Skip to content

Unit test that Shar reader is working when shard tar files are named randomly #937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/shar/test_read_lazy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
from functools import partial
from pathlib import Path

Expand Down Expand Up @@ -276,3 +277,28 @@ def cut_map_fn_1(cut):
assert c_test.dataset == "dataset_corresponding_to_shard_1"
else:
raise RuntimeError(f"Unexpected shard_origin: {c_test.shard_origin}")


def test_shar_lazy_reader_from_fields_with_random_tar_name(
cuts: CutSet, shar_dir: Path
):
path0 = shar_dir / "random_name_y.tar"
path1 = shar_dir / "random_another_name_x.tar"
shutil.copy(shar_dir / "recording.000000.tar", path0)
shutil.copy(shar_dir / "recording.000001.tar", path1)

# Prepare system under test
cuts_shar = CutSet.from_shar(
fields={
"cuts": [
shar_dir / "cuts.000000.jsonl.gz",
shar_dir / "cuts.000001.jsonl.gz",
],
"recording": [path0, path1],
}
)

# Actual test
for c_test, c_ref in zip(cuts_shar, cuts):
assert c_test.id == c_ref.id
np.testing.assert_allclose(c_ref.load_audio(), c_test.load_audio(), rtol=1e-3)