From c1b0739bf428cae4180e03230ad05b4a8a08732e Mon Sep 17 00:00:00 2001 From: Jonathan Langlois Date: Sun, 13 Aug 2023 21:46:00 +0900 Subject: [PATCH] fix: skip bash tests if bash or globstar is not available --- fsspec/tests/test_spec.py | 50 +++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/fsspec/tests/test_spec.py b/fsspec/tests/test_spec.py index 9dc0d4d89..37cf7b7d8 100644 --- a/fsspec/tests/test_spec.py +++ b/fsspec/tests/test_spec.py @@ -1081,30 +1081,50 @@ def glob_fs(): return DummyTestFS(fs_content=PATHS_FOR_GLOB_TESTS) +@pytest.fixture(scope="function") +def glob_files_folder(tmp_path): + local_fs = LocalFileSystem(auto_mkdir=True) + local_fake_dir = str(tmp_path) + for path_info in PATHS_FOR_GLOB_TESTS: + if path_info["type"] == "file": + local_fs.touch(path=f"{str(tmp_path)}/{path_info['name']}") + return local_fake_dir + + +@pytest.mark.parametrize( + GLOB_POSIX_TESTS["argnames"], + GLOB_POSIX_TESTS["argvalues"], +) +def test_posix_tests_python_glob(path, expected, glob_files_folder): + """ + Tests against python glob to check if our posix tests are accurate. + """ + abs_path = f"{glob_files_folder}/{path}" + + python_output = glob.glob(pathname=abs_path, recursive=True) + assert _clean_paths(python_output, glob_files_folder) == _clean_paths(expected) + + @pytest.mark.skipif( - sys.platform.startswith("win"), reason="can't run bash tests on windows" + sys.platform.startswith("win"), reason="no need to run bash posix tests on windows" ) @pytest.mark.parametrize( GLOB_POSIX_TESTS["argnames"], GLOB_POSIX_TESTS["argvalues"], ) -def test_posix_tests(path, expected, tmp_path): +def test_posix_tests_bash_stat(path, expected, glob_files_folder): """ - Tests against python glob and bash stat to check if our posix tests are accurate. + Tests against bash stat to check if our posix tests are accurate. """ - local_fs = LocalFileSystem(auto_mkdir=True) - local_fake_dir = str(tmp_path) - for path_info in PATHS_FOR_GLOB_TESTS: - if path_info["type"] == "file": - local_fs.touch(path=f"{str(tmp_path)}/{path_info['name']}") - - abs_path = f"{local_fake_dir}/{path}" + try: + subprocess.check_output(["bash", "-c", "shopt -s globstar"]) + except FileNotFoundError: + pytest.skip("bash is not available") + except subprocess.CalledProcessError: + pytest.skip("globstar option is not available") - # Test python glob - python_output = glob.glob(pathname=abs_path, recursive=True) - assert _clean_paths(python_output, local_fake_dir) == _clean_paths(expected) + abs_path = f"{glob_files_folder}/{path}" - # Test bash glob bash_abs_path = ( abs_path.replace("\\", "\\\\") .replace("$", "\\$") @@ -1117,7 +1137,7 @@ def test_posix_tests(path, expected, tmp_path): capture_output=True, ) bash_output = bash_output.stdout.decode("utf-8").replace("'", "").split("\n") - assert _clean_paths(bash_output, local_fake_dir) == _clean_paths(expected) + assert _clean_paths(bash_output, glob_files_folder) == _clean_paths(expected) @pytest.mark.parametrize(