| 32 | |
| 33 | @pytest.mark.parametrize("compression_fs_class", COMPRESSION_FILESYSTEMS) |
| 34 | def test_compression_filesystems(compression_fs_class, gz_file, bz2_file, lz4_file, zstd_file, xz_file, text_file): |
| 35 | input_paths = {"gzip": gz_file, "xz": xz_file, "zstd": zstd_file, "bz2": bz2_file, "lz4": lz4_file} |
| 36 | input_path = input_paths[compression_fs_class.protocol] |
| 37 | if input_path is None: |
| 38 | reason = f"for '{compression_fs_class.protocol}' compression protocol, " |
| 39 | if compression_fs_class.protocol == "lz4": |
| 40 | reason += require_lz4.kwargs["reason"] |
| 41 | elif compression_fs_class.protocol == "zstd": |
| 42 | reason += require_zstandard.kwargs["reason"] |
| 43 | pytest.skip(reason) |
| 44 | fs = fsspec.filesystem(compression_fs_class.protocol, fo=input_path) |
| 45 | expected_filename = os.path.basename(input_path) |
| 46 | expected_filename = expected_filename[: expected_filename.rindex(".")] |
| 47 | assert fs.glob("*") == [expected_filename] |
| 48 | with fs.open(expected_filename, "r", encoding="utf-8") as f, open(text_file, encoding="utf-8") as expected_file: |
| 49 | assert f.read() == expected_file.read() |
| 50 | |
| 51 | |
| 52 | @pytest.mark.parametrize("protocol", ["zip", "gzip"]) |