11import pytest
2- import zstandard as zstd
32
43from datasets .utils .extract import Extractor , ZstdExtractor
54
5+ from .utils import require_zstandard
66
7- FILE_CONTENT = """\
8- Text data.
9- Second line of data."""
107
11-
12- @pytest .fixture (scope = "session" )
13- def zstd_path (tmp_path_factory ):
14- path = tmp_path_factory .mktemp ("data" ) / "file.zstd"
15- data = bytes (FILE_CONTENT , "utf-8" )
16- with zstd .open (path , "wb" ) as f :
17- f .write (data )
18- return path
19-
20-
21- def test_zstd_extractor (zstd_path , tmp_path , text_file ):
22- input_path = zstd_path
8+ @require_zstandard
9+ def test_zstd_extractor (zstd_file , tmp_path , text_file ):
10+ input_path = zstd_file
2311 assert ZstdExtractor .is_extractable (input_path )
2412 output_path = str (tmp_path / "extracted.txt" )
2513 ZstdExtractor .extract (input_path , output_path )
@@ -30,21 +18,16 @@ def test_zstd_extractor(zstd_path, tmp_path, text_file):
3018 assert extracted_file_content == expected_file_content
3119
3220
33- @pytest .mark .parametrize (
34- "compression_format, expected_text_path_name" , [("gzip" , "text_path" ), ("xz" , "text_file" ), ("zstd" , "text_file" )]
35- )
36- def test_extractor (
37- compression_format , expected_text_path_name , text_gz_path , xz_file , zstd_path , tmp_path , text_file , text_path
38- ):
39- input_paths = {"gzip" : text_gz_path , "xz" : xz_file , "zstd" : zstd_path }
21+ @require_zstandard
22+ @pytest .mark .parametrize ("compression_format" , ["gzip" , "xz" , "zstd" ])
23+ def test_extractor (compression_format , gz_file , xz_file , zstd_file , tmp_path , text_file ):
24+ input_paths = {"gzip" : gz_file , "xz" : xz_file , "zstd" : zstd_file }
4025 input_path = str (input_paths [compression_format ])
4126 output_path = str (tmp_path / "extracted.txt" )
4227 assert Extractor .is_extractable (input_path )
4328 Extractor .extract (input_path , output_path )
4429 with open (output_path ) as f :
4530 extracted_file_content = f .read ()
46- expected_text_paths = {"text_file" : text_file , "text_path" : text_path }
47- expected_text_path = str (expected_text_paths [expected_text_path_name ])
48- with open (expected_text_path ) as f :
31+ with open (text_file ) as f :
4932 expected_file_content = f .read ()
5033 assert extracted_file_content == expected_file_content
0 commit comments