<s> import os <EOL> import stat <EOL> import sys <EOL> import pytest <EOL> import qisys . error <EOL> import qisys . sh <EOL> from qisrc . test . conftest import TestGit <EOL> def test_install_ro ( tmpdir ) : <EOL> tmp = tmpdir . strpath <EOL> src = os . path . join ( tmp , "<STR_LIT:src>" ) <EOL> os . mkdir ( src ) <EOL> ro = os . path . join ( src , "<STR_LIT>" ) <EOL> with open ( ro , "<STR_LIT:w>" ) as fp : <EOL> fp . write ( "<STR_LIT>" ) <EOL> os . chmod ( ro , stat . S_IRUSR ) <EOL> dest = os . path . join ( tmp , "<STR_LIT>" ) <EOL> qisys . sh . install ( src , dest ) <EOL> def test_install_on_self ( tmpdir ) : <EOL> a_file = tmpdir . join ( "<STR_LIT:a>" ) <EOL> a_file . write ( "<STR_LIT>" ) <EOL> with pytest . raises ( qisys . error . Error ) as e : <EOL> qisys . sh . install ( a_file . strpath , tmpdir . strpath ) <EOL> assert "<STR_LIT>" in e . value . message <EOL> with pytest . raises ( qisys . error . Error ) as e : <EOL> qisys . sh . install ( tmpdir . strpath , tmpdir . strpath ) <EOL> assert "<STR_LIT>" in e . value . message <EOL> def test_install_symlink ( tmpdir ) : <EOL> src = tmpdir . mkdir ( "<STR_LIT:src>" ) <EOL> a = src . ensure ( "<STR_LIT:a>" , file = True ) <EOL> b = src . join ( "<STR_LIT:b>" ) <EOL> b . mksymlinkto ( "<STR_LIT:a>" ) <EOL> dest = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> a_dest = dest . join ( "<STR_LIT:a>" ) <EOL> b_dest = dest . join ( "<STR_LIT:b>" ) <EOL> qisys . sh . install ( b . strpath , b_dest . strpath ) <EOL> qisys . sh . install ( a . strpath , a_dest . strpath ) <EOL> assert b_dest . check ( file = True ) <EOL> assert b_dest . islink ( ) <EOL> assert b_dest . readlink ( ) == "<STR_LIT:a>" <EOL> def test_filter_hidden ( tmpdir ) : <EOL> src = tmpdir . ensure ( "<STR_LIT:src>" , dir = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> dest = tmpdir . join ( "<STR_LIT>" ) <EOL> def non_hidden ( src ) : <EOL> return not src . startswith ( "<STR_LIT:.>" ) <EOL> installed = qisys . sh . install ( src . strpath , dest . strpath , filter_fun = non_hidden ) <EOL> a_file = dest . join ( "<STR_LIT>" ) <EOL> assert a_file . check ( file = True ) <EOL> assert not dest . join ( "<STR_LIT>" ) . check ( file = True ) <EOL> assert installed == [ "<STR_LIT>" ] <EOL> def test_ls_r_default ( tmpdir ) : <EOL> src = tmpdir . ensure ( "<STR_LIT:src>" , dir = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> res = qisys . sh . ls_r ( src . strpath ) <EOL> assert res == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_ls_r_all ( tmpdir ) : <EOL> src = tmpdir . join ( "<STR_LIT:src>" ) <EOL> src . ensure ( "<STR_LIT>" , file = True ) <EOL> src . ensure ( "<STR_LIT>" , file = True ) <EOL> src . ensure ( "<STR_LIT>" , file = True ) <EOL> src . ensure ( "<STR_LIT>" , file = True ) <EOL> src . ensure ( "<STR_LIT>" , file = True ) <EOL> res = qisys . sh . ls_r ( src . strpath ) <EOL> assert res == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> res = qisys . sh . ls_r ( src . strpath , all = True ) <EOL> assert res == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def test_iter_directory ( tmpdir ) : <EOL> src = tmpdir . ensure ( "<STR_LIT:src>" , dir = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> src . join ( "<STR_LIT>" ) . ensure ( file = True ) <EOL> res = sorted ( qisys . sh . iter_directory ( src . strpath , all = True ) ) <EOL> assert res == [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> res = sorted ( qisys . sh . iter_directory ( src . strpath ) ) <EOL> assert res == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_is_path_inside ( ) : <EOL> assert qisys . sh . is_path_inside ( os . path . join ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) , "<STR_LIT:foo>" ) <EOL> assert qisys . sh . is_path_inside ( os . path . join ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) , <EOL> os . path . join ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> assert qisys . sh . is_path_inside ( "<STR_LIT:foo>" , os . path . join ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) is False <EOL> assert qisys . sh . is_path_inside ( os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) ) is False <EOL> assert qisys . sh . is_path_inside ( os . path . join ( "<STR_LIT>" , "<STR_LIT:bar>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) is False <EOL> def test_copy_git_src ( tmpdir ) : <EOL> src = tmpdir . mkdir ( "<STR_LIT:src>" ) <EOL> dest = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> foo_src = src . mkdir ( "<STR_LIT:foo>" ) <EOL> foo_git = TestGit ( foo_src . strpath ) <EOL> foo_git . initialize ( ) <EOL> foo_git . commit_file ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_git . commit_file ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_src . ensure ( "<STR_LIT>" , file = True ) <EOL> qisys . sh . copy_git_src ( foo_src . strpath , dest . strpath ) <EOL> assert dest . join ( "<STR_LIT>" ) . check ( file = True ) <EOL> assert not dest . join ( "<STR_LIT>" ) . check ( file = True ) <EOL> def test_is_runtime ( ) : <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is False <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is False <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is True <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is True <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is True <EOL> if sys . platform == "<STR_LIT>" : <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is True <EOL> assert qisys . sh . is_runtime ( "<STR_LIT>" ) is True <EOL> def test_install_return_value ( tmpdir ) : <EOL> src = tmpdir . mkdir ( "<STR_LIT:src>" ) <EOL> b = src . ensure ( "<STR_LIT:a>" , "<STR_LIT:b>" , file = True ) <EOL> d = src . ensure ( "<STR_LIT:a>" , "<STR_LIT:c>" , "<STR_LIT:d>" , file = True ) <EOL> dest = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> ret = qisys . sh . install ( src . strpath , dest . strpath ) <EOL> assert ret == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ret = qisys . sh . install ( d . strpath , dest . strpath ) <EOL> assert ret == [ "<STR_LIT:d>" ] <EOL> def test_install_qt_symlinks ( tmpdir ) : <EOL> tc_path = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> qt_src = tc_path . mkdir ( "<STR_LIT>" ) <EOL> qt_src . ensure ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , file = True ) <EOL> qt_src . join ( "<STR_LIT>" ) . mksymlinkto ( "<STR_LIT>" ) <EOL> dest = tmpdir . join ( "<STR_LIT>" ) <EOL> qisys . sh . install ( qt_src . strpath , dest . strpath , filter_fun = qisys . sh . is_runtime ) <EOL> assert dest . join ( "<STR_LIT>" ) . islink ( ) <EOL> def test_to_posix_path ( ) : <EOL> assert qisys . sh . to_posix_path ( r"<STR_LIT>" ) == "<STR_LIT>" <EOL> assert qisys . sh . to_posix_path ( r"<STR_LIT>" ) == "<STR_LIT>" <EOL> assert qisys . sh . to_posix_path ( r"<STR_LIT>" , fix_drive = True ) == "<STR_LIT>" </s>
