def test_cmd_tar_archive_is_ok(archive_file_path_dicts, file_type): archive_file_path = archive_file_path_dicts[file_type]['valid'] if not archive_file_path: raise ValueError('archive_file_path') with pytest.helpers.work_dir(): Cmd.tar_extract(archive_file_path) assert os.path.isdir('a')
def test_cmd_curl_is_failed(file_url): not_existed_file_url = file_url + '.dummy' with pytest.helpers.work_dir(): with pytest.raises(RemoteFileNotFoundError) as ei: Cmd.curl_remote_name(not_existed_file_url) assert re.match(r'^Download failed: .* HTTP Error 404: Not Found$', str(ei.value))
def test_cmd_tar_archive_is_failed(archive_file_path_dicts, file_type): archive_file_path = archive_file_path_dicts[file_type]['invalid'] if not archive_file_path: raise ValueError('archive_file_path') with pytest.helpers.work_dir(): with pytest.raises(InstallError) as ei: Cmd.tar_extract(archive_file_path) assert re.match(r'^Extract failed: .* could not be opened successfully$', str(ei.value))
def test_cmd_find_is_ok(): with pytest.helpers.work_dir(): os.makedirs('dir1/dir2') pytest.helpers.touch('dir1/dir2/a.txt') pytest.helpers.touch('dir1/b.txt') pytest.helpers.touch('dir1/a.rpm') pytest.helpers.run_cmd('ln -s dir1/b.txt dir1/c.txt') matched_files = Cmd.find('.', '*.txt') assert matched_files == [ './dir1/b.txt', './dir1/dir2/a.txt', ] matched_files = Cmd.find('.', 'a.txt') assert matched_files == [ './dir1/dir2/a.txt', ] matched_files = Cmd.find('.', 'a.*') assert matched_files == [ './dir1/a.rpm', './dir1/dir2/a.txt', ]
def test_cmd_pushd_is_ok(): with pytest.helpers.reset_dir(): tmp_dir = tempfile.gettempdir() before_dir = os.getcwd() with Cmd.pushd(tmp_dir): a_dir = os.getcwd() assert a_dir == tmp_dir after_dir = os.getcwd() assert after_dir == before_dir pass
def test_cmd_cd_is_ok(): with pytest.helpers.reset_dir(): tmp_dir = tempfile.gettempdir() Cmd.cd(tmp_dir) cwd = os.getcwd() assert cwd == tmp_dir
def test_cmd_sh_e_out_is_ok(): stdout = Cmd.sh_e_out('pwd') assert stdout assert re.match(r'^.*\n$', stdout)
def test_cmd_sh_e_is_failed(): with pytest.raises(InstallError): Cmd.sh_e('ls abcde') assert True
def test_cmd_sh_e_is_ok_with_stderr(): stdout, stderr = Cmd.sh_e('echo "abc" 1>&2') assert not stdout assert stderr assert stderr == 'abc\n'
def test_cmd_sh_e_is_ok(): stdout, stderr = Cmd.sh_e('pwd') assert not stdout assert stderr == ''
def test_cmd_mkdir_p_is_ok(): with pytest.helpers.work_dir(): Cmd.mkdir_p('./a/b') pytest.helpers.touch('./a/b/c.txt') assert True
def test_cmd_curl_is_ok(file_url): with pytest.helpers.work_dir(): assert Cmd.curl_remote_name(file_url)
def test_cmd_which_is_ok(cmd): abs_path = Cmd.which(cmd) assert re.match(r'^/.*{0}$'.format(cmd), abs_path)