forked from mergeos-bounties/Loru
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wlasl_adapter.py
More file actions
61 lines (45 loc) · 2.06 KB
/
Copy pathtest_wlasl_adapter.py
File metadata and controls
61 lines (45 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import annotations
import json
from pathlib import Path
from typer.testing import CliRunner
from loru.cli import app
from loru.data.wlasl import load_wlasl_manifest, write_wlasl_manifest
FIXTURES = Path(__file__).parent / "fixtures"
def test_load_wlasl_manifest_normalizes_entries() -> None:
manifest = load_wlasl_manifest(FIXTURES / "wlasl_index.json", samples_dir=Path("data/samples"))
assert [entry["gloss"] for entry in manifest] == ["thank_you", "hello"]
assert manifest[0]["video_id"] == "wlasl-thank-you-001"
assert manifest[0]["split"] == "train"
assert manifest[0]["source_url"] == "https://example.invalid/wlasl/thank-you.mp4"
# Path may be absolute (Windows) or relative — only require trailing sample path.
assert Path(manifest[0]["sequence_path"]).as_posix().endswith("data/samples/thank_you.json")
assert manifest[0]["sequence_exists"] is True
assert manifest[0]["frame_start"] == 1
assert manifest[0]["frame_end"] == 48
assert manifest[1]["gloss"] == "hello"
assert Path(manifest[1]["sequence_path"]).as_posix().endswith("data/samples/hello.json")
assert manifest[1]["sequence_exists"] is True
def test_write_wlasl_manifest_outputs_loru_manifest(tmp_path: Path) -> None:
out = tmp_path / "manifest.json"
write_wlasl_manifest(FIXTURES / "wlasl_index.json", out, samples_dir=Path("data/samples"))
payload = json.loads(out.read_text(encoding="utf-8"))
assert payload[0]["dataset"] == "wlasl"
assert payload[0]["gloss"] == "thank_you"
def test_wlasl_manifest_cli_writes_manifest(tmp_path: Path) -> None:
out = tmp_path / "manifest.json"
result = CliRunner().invoke(
app,
[
"data",
"wlasl-manifest",
"--index",
str(FIXTURES / "wlasl_index.json"),
"--samples-dir",
"data/samples",
"--out",
str(out),
],
)
assert result.exit_code == 0
assert "WLASL manifest" in result.output
assert json.loads(out.read_text(encoding="utf-8"))[1]["gloss"] == "hello"