Download tests/test_hf_export_dashboard.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 2.89 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_hf_export_dashboard.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/tests/test_hf_export_dashboard.py
-
curl -L -o test_hf_export_dashboard.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_hf_export_dashboard.py
2.89 kB
| import importlib.util | |
| from collections import deque | |
| import json | |
| from pathlib import Path | |
| spec = importlib.util.spec_from_file_location('dashboard', Path(__file__).resolve().parents[1] / 'scripts/data/hf_export_dashboard.py') | |
| m = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(m) | |
| def test_rate_needs_elapsed_time_and_no_negative_speed(): | |
| values = deque() | |
| assert m.rate(values, 0, 10) is None | |
| assert m.rate(values, 10, 20) is None | |
| assert m.rate(values, 20, 50) == 2 | |
| assert m.rate(values, 30, 0) == 0 | |
| def test_waiting_period_not_counted_as_packing_time(): | |
| values = deque([(0, 0), (100, 0)]) | |
| assert m.rate(values, 115, 150) is None | |
| assert m.rate(values, 130, 300) == 10 | |
| def test_metadata_only_scan_cursor(tmp_path, monkeypatch): | |
| metadata = tmp_path / 'metadata.csv' | |
| metadata.write_text('move_g1_path\ng1/csv/240101/a.csv\ng1/csv/240101/b.csv\ng1/csv/240101/b.csv\n') | |
| obj = m.Observer(tmp_path / 'export', tmp_path / 'state', metadata) | |
| obj.keys_set = set(obj.keys) | |
| monkeypatch.setattr(m, 'processes', lambda _: [{'kind': 'pack', 'source_cursor': '240101/a'}]) | |
| obj.sample() | |
| assert obj.latest['scan']['estimated_completed_motions'] == 1 | |
| assert obj.latest['scan']['total_motions'] == 2 | |
| assert obj.latest['phase'] == '扫描动作文件' | |
| assert not (tmp_path / 'export').exists() # Observer never creates/modifies export tree. | |
| def test_partial_not_counted_as_complete(tmp_path, monkeypatch): | |
| metadata = tmp_path / 'metadata.csv' | |
| metadata.write_text('move_g1_path\ng1/csv/day/clip.csv\n') | |
| export = tmp_path / 'export' | |
| shard = export / 'hfd_data/shards/seed_motion/00000.tar.partial' | |
| shard.parent.mkdir(parents=True) | |
| shard.write_bytes(b'hello') | |
| obj = m.Observer(export, tmp_path / 'state', metadata) | |
| obj.keys_set = set(obj.keys) | |
| monkeypatch.setattr(m, 'processes', lambda _: []) | |
| obj.sample() | |
| row = obj.latest['packages'][0] | |
| assert row['written_bytes'] == 5 and row['done'] == 0 | |
| assert row['eta_seconds'] is None and row['bytes_per_second'] is None | |
| assert obj.latest['local_ready'] is False | |
| def test_completed_markers_and_safe_relative_api(tmp_path, monkeypatch): | |
| metadata = tmp_path / 'metadata.csv' | |
| metadata.write_text('move_g1_path\n') | |
| export = tmp_path / 'export' | |
| marker = export / 'hfd_data/.build/hfd_control_commands_v1/00000.done.json' | |
| marker.parent.mkdir(parents=True) | |
| marker.write_text(json.dumps({'archive_bytes': 100, 'files': 4})) | |
| obj = m.Observer(export, tmp_path / 'state', metadata) | |
| obj.keys_set = set() | |
| monkeypatch.setattr(m, 'processes', lambda _: []) | |
| obj.sample() | |
| row = next(r for r in obj.latest['packages'] if r['name'] == 'hfd_control_commands_v1') | |
| assert row['done'] == 1 and row['files_done'] == 4 | |
| assert "fetch('api/status'" in m.HTML | |
| assert 'textContent' in m.HTML | |