|
| 1 | +import io |
| 2 | +import tarfile |
| 3 | + |
| 4 | +from gasbench.dataset.config import BenchmarkDatasetConfig |
| 5 | +from gasbench.dataset.download.extract import yield_media_from_source |
| 6 | + |
| 7 | + |
| 8 | +def _write_tar(path, members): |
| 9 | + with tarfile.open(path, "w") as archive: |
| 10 | + for name, payload in members.items(): |
| 11 | + info = tarfile.TarInfo(name) |
| 12 | + info.size = len(payload) |
| 13 | + archive.addfile(info, io.BytesIO(payload)) |
| 14 | + |
| 15 | + |
| 16 | +def test_archive_member_filtering_keeps_only_matching_media(tmp_path): |
| 17 | + archive_path = tmp_path / "mixed.tar" |
| 18 | + _write_tar( |
| 19 | + archive_path, |
| 20 | + { |
| 21 | + "raw/fake/tts/audio/fake.wav": b"synthetic audio", |
| 22 | + "raw/real/speech/audio/real.wav": b"captured audio", |
| 23 | + "raw/fake/tts/metadata/fake.json": b"{}", |
| 24 | + }, |
| 25 | + ) |
| 26 | + dataset = BenchmarkDatasetConfig( |
| 27 | + name="mixed-audio", |
| 28 | + path="example/mixed-audio", |
| 29 | + modality="audio", |
| 30 | + media_type="synthetic", |
| 31 | + source_format="tar", |
| 32 | + archive_include_paths=["/fake/"], |
| 33 | + ) |
| 34 | + |
| 35 | + samples = list(yield_media_from_source(archive_path, dataset, num_items=-1)) |
| 36 | + |
| 37 | + assert [sample["member_path"] for sample in samples] == [ |
| 38 | + "raw/fake/tts/audio/fake.wav" |
| 39 | + ] |
| 40 | + assert samples[0]["audio_bytes"] == b"synthetic audio" |
0 commit comments