Datasets:
cocogni4d / code /evaluation-code /ent400-a06a1576 /apps /console /tests /test_segment_conversion.py
Download code/evaluation-code/ent400-a06a1576/apps/console/tests/test_segment_conversion.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 23.8 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/tests/test_segment_conversion.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/ent400-a06a1576/apps/console/tests/test_segment_conversion.py
-
curl -L -o test_segment_conversion.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/tests/test_segment_conversion.py
23.8 kB
| """Current generator plan import, including refusal of undeclared body yaw.""" | |
| from collections import Counter | |
| import json | |
| from pathlib import Path | |
| import tempfile | |
| import unittest | |
| from unittest.mock import patch | |
| import numpy as np | |
| from apps.console.server.errors import ViewError | |
| from apps.console.server.segment_import import read_import, sha | |
| from apps.console.server.registry import Registry | |
| from apps.console.server.schema import validate | |
| from apps.console.server import segment_conversion as g3, batch_summary as summary | |
| class GeneratorImportTests(unittest.TestCase): | |
| def plan(self, **updates): | |
| p = dict(kind='go', status='done', t_plan=0., t_depart=0., t_arrive=2., | |
| t_leave=4., t_end=4., dwell_s=2., cruise=1., from_stop=0, to_stop=1, to_region='room') | |
| p.update(updates) | |
| return p | |
| def intents(self, *plans): | |
| ints, rows, arrangements, counts = [], [], [], Counter() | |
| t = np.arange(201) / 20 | |
| g3.plan_intents({'plan': list(plans)}, np.column_stack((t, t)), t, | |
| ints, rows, counts, arrangements, 'a') | |
| for item in ints: | |
| self.assertLessEqual(0, item['start_s']) | |
| self.assertLessEqual(item['start_s'], item['end_s']) | |
| self.assertLessEqual(item['end_s'], 10) | |
| return ints, rows, arrangements, counts | |
| def test_g3_stay_planned_to_segment_end(self): | |
| # 最后一段停留没有离开时刻:读回在停点待满计划停留(计划停到段末,或计划短、人一直没走)就算停完;人走开了仍算没停够 | |
| t = np.arange(201) / 20 | |
| still, moving = np.column_stack((np.minimum(t, 2.), np.minimum(t, 2.))), np.column_stack((t, t)) | |
| for dwell, xy, status in ((8., still, 'effective'), (3., still, 'effective'), (8., moving, 'ineffective'), (3., moving, 'ineffective')): | |
| with self.subTest(dwell=dwell, status=status): | |
| ints, rows, arrangements, counts = [], [], [], Counter() | |
| g3.plan_intents({'plan': [self.plan(dwell_s=dwell, t_leave=None, t_end=None)]}, xy, t, ints, rows, counts, arrangements, 'a') | |
| (stay,) = [x for x in arrangements if x['kind'] == '停留'] | |
| self.assertEqual(stay['status'], status) | |
| self.assertEqual(ints[-1]['status'], 'completed' if status == 'effective' else 'truncated') | |
| def test_idle_remainder_and_selfcheck(self): | |
| # 段列表的两栏:最后一条计划做完后原地待到段末的秒数;自检按安排状态判,不再写死 NOT_CHECKED | |
| t = np.arange(201) / 20 | |
| xy = np.column_stack((np.minimum(t, 2.), np.minimum(t, 2.))) | |
| for plan, idle in ((self.plan(), 6.), (self.plan(dwell_s=3., t_leave=None, t_end=None), 5.), (self.plan(status='stayed'), 10.)): | |
| with self.subTest(plan=plan['status'], leave=plan['t_leave']): | |
| self.assertAlmostEqual(g3.plan_intents({'plan': [plan]}, xy, t, [], [], Counter(), [], 'a'), idle) | |
| arr = lambda *s: [dict(status=x) for x in s] | |
| self.assertEqual(g3.selfcheck(arr('effective', 'effective')), 'pass') | |
| self.assertEqual(g3.selfcheck(arr('effective', 'ineffective')), 'activity_defect') | |
| self.assertEqual(g3.selfcheck(arr('effective', 'NOT_CHECKED')), 'not_checked') | |
| self.assertEqual(g3.selfcheck([]), 'not_checked') | |
| def test_g2_all_plan_kinds(self): | |
| for kind in ('go', 'move', 'back', 'pause', 'detour'): | |
| with self.subTest(kind=kind): | |
| ints, rows, arrangements, _ = self.intents(self.plan(kind=kind)) | |
| self.assertEqual(ints[0]['kind'], 'back' if kind == 'back' else 'go_to') | |
| self.assertEqual(rows[0]['state'], 'moving') | |
| self.assertEqual(arrangements[0]['status'], 'effective') | |
| with self.assertRaises(KeyError): | |
| self.intents(self.plan(kind='unknown')) | |
| def test_g3_none_and_beyond_end(self): | |
| ints, _, _, _ = self.intents(self.plan(t_leave=None, t_end=None)) | |
| self.assertEqual((ints[-1]['end_s'], ints[-1]['status']), (10., 'truncated')) | |
| ints, _, arrangements, _ = self.intents(self.plan(t_arrive=12., t_leave=None, t_end=None)) | |
| self.assertEqual(len(ints), 1) | |
| self.assertEqual(ints[0]['end_s'], 10.) | |
| self.assertEqual(ints[0]['status'], 'truncated') | |
| self.assertIn('段末仍在途中', ints[0]['reason']) | |
| self.assertNotIn('到站', arrangements[0]['basis']) | |
| ints, _, _, _ = self.intents(self.plan(status='cut', t_arrive=None, t_end=None)) | |
| self.assertEqual(ints[0]['end_s'], 10.) | |
| def test_g4_stayed_after_end(self): | |
| for status, label in (('stayed', '原地不动'), ('after_end', '本段未执行')): | |
| with self.subTest(status=status): | |
| ints, rows, arr, counts = self.intents(self.plan(status=status, t_depart=None, | |
| t_arrive=None, t_leave=None, t_end=None, t_plan=12. if status == 'after_end' else 0.)) | |
| self.assertIn(label, ints[0]['reason']) | |
| self.assertIsNone(ints[0]['target']) | |
| self.assertNotIn('出发 ', arr[0]['basis']) | |
| self.assertNotIn('到站 ', arr[0]['basis']) | |
| self.assertFalse(any(r['state'] == 'moving' for r in rows)) | |
| if status == 'after_end': | |
| self.assertEqual(arr[0]['status'], 'NOT_CHECKED') | |
| self.assertIsNone(arr[0]['span_s']) | |
| self.assertEqual(counts['discarded'], 1) | |
| def convert(self, root, questions=(), arrangements=(), planned=(), **actor_updates): | |
| seg, cap, out = [root / name for name in ('seg', 'cap', 'out')] | |
| seg.mkdir(); cap.mkdir() | |
| (cap / 'capability.json').write_text('{}') | |
| actor = dict(id='a', kind='humanoid', entity='h0', yaw_source='planned', | |
| plan=[self.plan(waits=[[0., .25], [1., .5]])]) | |
| actor.update(actor_updates) | |
| script = dict(script_id='synthetic', span_s=[0., 10.], control_hz=20., actors=[actor], | |
| generator=dict(house='house', version='test', tier=None, branches=[999], | |
| entities=[dict(id='h0', actual=dict(waits=2, wait_max_s=.5))], arrangements=list(arrangements), | |
| config=dict(arrangements=list(planned)))) | |
| (seg / 'script.json').write_text(json.dumps(script)) | |
| t = np.arange(201) / 20 | |
| np.savez(seg / 'curves.npz', t=t, a__u=t, a__v=t, a__yaw=t) | |
| base = dict(bounds_uv=[[0., 0.], [10., 10.]], rooms=[], doorways=[], stop_points=[], | |
| occluder_contours_uv=[], occluder_height_m=1.5, | |
| raster=dict(url='', width_px=1, height_px=1, pixel_to_uv=[1., 0., 0., -1., 0., 1.], | |
| navigation_profile='test')) | |
| frame = dict(units='m', uv_axes=['X', 'Z'], yaw_zero='+u', yaw_positive='counterclockwise') | |
| verify = root / 'no-questions' | |
| if questions: # check-chain questions are looked up by script id | |
| (verify / script['script_id']).mkdir(parents=True) | |
| (verify / script['script_id'] / 'questions.jsonl').write_text(''.join(json.dumps(q) + '\n' for q in questions)) | |
| with patch.object(g3, 'basemap', return_value=(base, b'png', dict(frame=frame))): | |
| g3.convert(seg, cap, out, verify) | |
| return out | |
| def test_complete_review_import_identity(self): | |
| question = dict(candidate_id='candidate/#0', decision=dict(result='PASS'), | |
| public=dict(version_id='version', text=dict(zh=[dict(text='题面')])), | |
| binding=dict(local_span_s=[1., 2.]), proof=dict(source='original'), | |
| replay=dict(answer='A'), facts=dict(source='original')) | |
| cases = [({}, 'generator_plan', {'PLAN_TRAJECTORY_ONLY', 'GEN_PLAN', 'GEN_WAITS'}), | |
| ({'yaw_source': None}, 'generator_plan', | |
| {'SOURCE_BODY_YAW_MISSING', 'PLAN_TRAJECTORY_ONLY', 'GEN_PLAN', 'GEN_WAITS'}), | |
| ({'plan': [], 'yaw_source': None}, 'source_without_intent_records', | |
| {'SOURCE_BODY_YAW_MISSING', 'PLAN_TRAJECTORY_ONLY', 'INTENT_DERIVED', 'GEN_WAITS'})] | |
| for updates, method, warnings in cases: | |
| with self.subTest(updates=updates), tempfile.TemporaryDirectory() as tmp: | |
| root = Path(tmp) | |
| out = self.convert(root, questions=[question], **updates) | |
| self.assertEqual({p.name for p in out.iterdir()}, | |
| {'review-import.json', 'view.json', 'questions.json', 'basemap.png'}) | |
| manifest = json.loads((out / 'review-import.json').read_text()) | |
| self.assertEqual(manifest['schema'], 'console-review-import/2') | |
| self.assertEqual(set(manifest['files']), {'view.json', 'questions.json', 'basemap.png'}) | |
| for name, digest in manifest['files'].items(): | |
| self.assertEqual(digest, sha(out / name)) | |
| expected_inputs = {'case.json': root / 'seg/script.json', | |
| 'private20hz.npz': root / 'seg/curves.npz', | |
| 'capability.json': root / 'cap/capability.json'} | |
| self.assertEqual(manifest['inputs'], | |
| {name: dict(path=str(path), sha256=sha(path)) | |
| for name, path in expected_inputs.items()}) | |
| view, raster = read_import(out) | |
| self.assertEqual((view['schema'], view['builder_version'], view['visibility_builder_version']), | |
| ('segment-view/6', 'review-import/2', 'review-evidence/2')) | |
| self.assertEqual(view['generation']['method'], method) | |
| self.assertEqual({w['code'] for w in view['warnings']}, warnings) | |
| self.assertEqual(view['segment']['id'], 'synthetic') | |
| self.assertEqual(view['segment']['script_id'], sha(root / 'seg/curves.npz')) | |
| self.assertEqual(manifest['summary']['script_id'], view['segment']['script_id']) | |
| self.assertEqual(view['provenance']['artifact_sha256'], sha(root / 'seg/script.json')) | |
| for name, ref in view['provenance']['inputs'].items(): | |
| self.assertEqual(ref, dict(manifest['inputs'][name], artifact=False)) | |
| self.assertEqual(raster, b'png') | |
| self.assertEqual(view['review']['questions'][0]['id'], question['candidate_id']) | |
| detail = json.loads((out / 'questions.json').read_text())[question['candidate_id']] | |
| for key in ('candidate_id', 'public', 'decision', 'binding', 'proof', 'replay', 'facts'): | |
| self.assertEqual(detail[key], question[key]) | |
| def test_g1_null_tier_numeric_and_required(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| out = self.convert(Path(tmp)) | |
| view, _ = read_import(out) | |
| self.assertEqual(view['segment']['duration_tier'], 10.) | |
| for invalid in (None, True, []): | |
| view['segment']['duration_tier'] = invalid | |
| with self.assertRaises(ValueError): validate(view) | |
| del view['segment']['duration_tier'] | |
| with self.assertRaises(ValueError): validate(view) | |
| def test_g6_arrangement_note_shows_anchors_and_detail_by_actor_id(self): | |
| a = dict(index=0, type='target_visible', who=['A', 'h0'], strength='hard', happened=True, t=[3., 9.], | |
| anchors=[dict(who='h0', stop=4, xy=[1., 2.5], t0=3., t1=9., role='event'), dict(who=['A', 'B'], stop=None, xy=[0., 1.], t0=None, t1=None, role='view')], | |
| detail=dict(door='d3', views={'A': [3., 9.], 'B': None})) | |
| (row,) = g3.generator_arrangements(dict(arrangements=[a]), {'h0': 'actor-000', 'A': 'actor-002', 'B': 'actor-003'}) | |
| self.assertTrue(row['basis'].startswith('生成器 arrangements[0]:hard,成立')) | |
| self.assertIn('锚点:事发处 actor-000 (1.00, 2.50) 3.0–9.0 s、观察者站位 actor-002、actor-003 (0.00, 1.00);', row['basis']) | |
| self.assertIn('明细:门洞 d3:actor-002 看见 3.0–9.0 s,actor-003 没看见', row['basis']) | |
| for gen_id in ("'A'", '"A"', 'h0'): | |
| self.assertNotIn(gen_id, row['basis']) | |
| (bare,) = g3.generator_arrangements(dict(arrangements=[dict(a, anchors=[], detail={})]), {}) | |
| self.assertTrue(bare['basis'].endswith(';锚点:无;明细:无')) | |
| def test_g6_detail_reads_as_chinese_sentences(self): | |
| # gen/detect.py 各类安排的 detail 都成中文短句,键名不露;认不得的键原样留着 | |
| d = g3.detail_text | |
| self.assertEqual(d('stop_at', {'seconds': 10.4, 'need_s': 4.0}), '站住最长 10.4 秒(要 4.0 秒)') | |
| self.assertEqual(d('covisible_event', {'seconds': 1.0, 'need_s': 2.0, 'why': {'actor-002': {'out_of_frame': 2.5, 'too_small': 0, 'occluded': 1.0}}}), | |
| '都看见最长 1.0 秒(要 2.0 秒),没看见的原因:actor-002 出画 2.5 秒、被挡 1.0 秒') | |
| self.assertEqual(d('observer_body', {'looks': [[3.0, 9.0]], 'times': 2, 'why': {'out_of_frame': 4.0, 'too_small': 0, 'occluded': 0}}), | |
| '看见 1 次(要 2 次):3.0–9.0 s,没看见的原因:出画 4.0 秒') | |
| self.assertEqual(d('target_visible', {'reason': 'not placed'}), '没排进时间表') | |
| self.assertEqual(d('meet', {'seconds': 0, 'need_s': 2.5, 'new_key': 1}), '碰面最长 0 秒(要 2.5 秒),{"new_key": 1}') | |
| self.assertEqual(d('stop_at', {}), '无') | |
| for text in (d('covisible_region', {'door': 'd1', 'views': {'actor-002': [1.0, 2.0]}}), d('stop_at', {'seconds': 1, 'need_s': 1})): | |
| for key in ('seconds', 'need_s', 'looks', 'views', 'times', 'door'): | |
| self.assertNotIn(key, text) | |
| def test_g6_every_generator_anchor_role_has_a_chinese_name(self): | |
| # 生成器添了新的锚点角色(gen/arrange.py 里 Anchor(..., i, '角色', ...)),这里提醒补中文名,免得说明里冒英文 | |
| import re | |
| src = (Path(__file__).resolve().parents[3] / 'embodied_pipeline/gen/arrange.py').read_text() | |
| roles = set(re.findall(r"i, '(\w+)'", src)) | |
| self.assertTrue(roles) | |
| self.assertEqual(roles - set(g3.ANCHOR_ROLES), set()) | |
| def test_g6_generator_arrangements_join_the_one_list(self): | |
| # 段卡和段页数同一份清单:生成器判的安排并进 actual_arrangements,诱饵不进,主体按 entity 对到 actor id | |
| rows = [dict(index=0, type='observer_body', who=['h0'], strength='hard', happened=False, t=None), | |
| dict(index=1, type='covisible_event', who=['h0'], strength='soft', happened=True, t=[1., 2.]), | |
| dict(index=2, type='meet', who=['h0'], strength='hard', happened=True, decoy=True)] | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp), arrangements=rows)) | |
| gen = [e for e in view['review']['actual_arrangements'] if e['source'] == '生成器安排判定'] | |
| self.assertEqual([(e['id'], e['status'], e['entity_ids']) for e in gen], | |
| [('gen-arr-0', 'ineffective', ['a']), ('gen-arr-1', 'effective', ['a'])]) | |
| self.assertEqual(gen[1]['span_s'], [1., 2.]) | |
| self.assertEqual(gen[0]['regions_uv'], []) # 没有 anchors 就没有阴影,不编 | |
| rows = [dict(index=0, type='stop_at', who=['h0'], strength='hard', happened=True, t=[1., 2.])] | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp), arrangements=rows)) | |
| (e,) = [e for e in view['review']['actual_arrangements'] if e['source'] == '生成器安排判定'] | |
| self.assertEqual(e['label'], '硬安排:在某处站住') # 生成器自有的类型也是中文名,不显示 stop_at | |
| def test_observer_split_layer_reaches_the_view(self): | |
| """生成器记的错开两层要进段视图,下标换成段里的 id;契约收这一项。""" | |
| gen = dict(config=dict(cast=[dict(id='h0'), dict(id='h1')]), observers=[dict(id='A'), dict(id='B')]) | |
| actor_of = {'h1': 'mover-1', 'B': 'obs-B'} | |
| self.assertEqual(g3.observer_split(dict(layer='time', mover=1, first=3.5, second=40.25, early_view=1), gen, actor_of), | |
| dict(layer='time', mover='mover-1', first_s=3.5, second_s=40.25, early_view='obs-B')) | |
| self.assertEqual(g3.observer_split(dict(layer='none', drawn=True), gen, actor_of), dict(layer='none', drawn=True)) | |
| contract = json.loads((Path(g3.__file__).with_name('contract.schema.json')).read_text())['$defs'] | |
| self.assertEqual(contract['Observer']['properties']['split'], {'$ref': '#/$defs/ObserverSplit'}) | |
| self.assertEqual(contract['ObserverSplit']['properties']['layer']['enum'], ['time', 'none']) | |
| def test_every_generator_arrangement_type_has_a_label(self): | |
| from embodied_pipeline.gen.config import ARRANGEMENTS | |
| from np.planning import GENERATOR_TYPE_LABELS | |
| self.assertEqual(set(GENERATOR_TYPE_LABELS), set(ARRANGEMENTS)) | |
| # 阴影:被看的一方(body/event)各一个圆;只有站位(view)时画站位 | |
| rows = [dict(index=0, type='observer_body', who=['h0'], strength='hard', happened=True, t=[10.4, 17.6], | |
| anchors=[dict(who='h0', role='body', xy=[-12.34, 3.71], t0=8.9, t1=16.9), | |
| dict(who='o1', role='view', xy=[-8.09, 2.64], t0=8.9, t1=16.9)]), | |
| dict(index=1, type='covisible_event', who=['h0'], strength='soft', happened=True, t=[1., 2.], | |
| anchors=[dict(who='h0', role='view', xy=[1., 2.], t0=1., t1=2.)])] | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp), arrangements=rows)) | |
| gen = {e['id']: e for e in view['review']['actual_arrangements'] if e['source'] == '生成器安排判定'} | |
| for eid, centre in (('gen-arr-0', [-12.34, 3.71]), ('gen-arr-1', [1., 2.])): | |
| (region,) = gen[eid]['regions_uv'] | |
| self.assertEqual(len(region), 16) | |
| mid = [sum(p[i] for p in region) / 16 for i in (0, 1)] | |
| self.assertAlmostEqual(mid[0], centre[0], 2); self.assertAlmostEqual(mid[1], centre[1], 2) | |
| self.assertTrue(all(abs(((p[0]-centre[0])**2 + (p[1]-centre[1])**2) ** .5 - .6) < .01 for p in region)) | |
| # 共视安排的阴影画在它看的那件事上(配置 event 指向的 stop_at),不画两名观察者的站位 | |
| rows = [dict(index=0, type='stop_at', who=['h0'], strength='hard', happened=True, t=[30.4, 36.6], | |
| anchors=[dict(who='h0', role='event', xy=[-0.66, -2.16], t0=31.1, t1=36.1)]), | |
| dict(index=1, type='covisible_event', who=['B', 'A'], strength='hard', happened=True, t=[30.4, 36.8], | |
| anchors=[dict(who='B', role='view', xy=[-3.96, -2.16], t0=29.1, t1=38.1), | |
| dict(who='A', role='view', xy=[-1.24, 2.29], t0=29.1, t1=38.1)])] | |
| planned = [dict(type='stop_at', who=['h0']), dict(type='covisible_event', who=['B', 'A'], event=0)] | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp), arrangements=rows, planned=planned)) | |
| gen = {e['id']: e for e in view['review']['actual_arrangements'] if e['source'] == '生成器安排判定'} | |
| (region,) = gen['gen-arr-1']['regions_uv'] | |
| self.assertAlmostEqual(sum(p[0] for p in region) / 16, -0.66, 2) | |
| self.assertAlmostEqual(sum(p[1] for p in region) / 16, -2.16, 2) | |
| self.assertEqual(gen['gen-arr-1']['regions_uv'], gen['gen-arr-0']['regions_uv']) | |
| with tempfile.TemporaryDirectory() as tmp: # 负对照:没有生成器安排时清单里也没有这一类 | |
| view, _ = read_import(self.convert(Path(tmp))) | |
| self.assertFalse([e for e in view['review']['actual_arrangements'] if e['source'] == '生成器安排判定']) | |
| def test_g5_planned_yaw_registry_and_refusal(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| root = Path(tmp); out = self.convert(root) | |
| view, _ = read_import(out) | |
| self.assertIsNotNone(view['tracks']['a']['yaw_rad']) | |
| self.assertEqual(len(Registry([('test', root)]).entries), 1) | |
| # Change declaration and update the manifest hash: test yaw authorization itself. | |
| source = root / 'seg/script.json' | |
| script = json.loads(source.read_text()); script['actors'][0]['yaw_source'] = 'unknown' | |
| source.write_text(json.dumps(script)) | |
| manifest = json.loads((out / 'review-import.json').read_text()) | |
| manifest['inputs']['case.json']['sha256'] = sha(source) | |
| (out / 'review-import.json').write_text(json.dumps(manifest)) | |
| with self.assertRaises(ViewError): read_import(out) | |
| def test_g6_waits_replace_branches(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp))) | |
| self.assertIn('等待 2 次,最长 0.500 s', view['actors'][0]['profile']) | |
| # 路径里的临时目录随作业号变,先去掉再查哨兵值 | |
| self.assertNotIn('999', json.dumps(view).replace(tmp, '')) | |
| self.assertIsNone(view['construction']['retries']) | |
| def test_g7_obsolete_keep_clear_ignored(self): | |
| self.assertNotIn('keep_clear', Path(g3.__file__).read_text()) | |
| with tempfile.TemporaryDirectory() as tmp: | |
| view, _ = read_import(self.convert(Path(tmp), keep_clear={'obsolete': True})) | |
| self.assertFalse(any(w['code'] == 'GEN_KEEP_CLEAR' for w in view['warnings'])) | |
| def test_g10_length_uses_generator_tier_then_name_then_duration(self): | |
| with tempfile.TemporaryDirectory() as tmp: | |
| root = Path(tmp) | |
| cases = [('a-long-metadata-short', 90, {'tier': 'short'}, 'short'), | |
| ('b-short-metadata-long', 90, {'tier': 'long'}, 'long'), | |
| ('c-short-config-long', 90, {'config': {'tier': 'long'}}, 'long'), | |
| ('d-short-name', 90, {}, 'short'), | |
| ('e-long-name', 90, {}, 'long'), | |
| ('f-no-tier', 90, {}, 'short'), | |
| ('g-no-tier', 359, {}, 'short'), | |
| ('h-no-tier', 360, {}, 'long'), | |
| ('i-short-conflict', 360, {'tier': 'short', 'config': {'tier': 'long'}}, 'short')] | |
| for name, duration, generator, expected in cases: | |
| src = root / 'src' / name; verify = root / 'verify' / name | |
| src.mkdir(parents=True); verify.mkdir(parents=True) | |
| (src / 'script.json').write_text(json.dumps(dict(script_id=name, span_s=[5., 5. + duration], | |
| generator=dict(house='house', **generator)))) | |
| (verify / 'summary.json').write_text(json.dumps(dict(script_id=name, candidates=0))) | |
| (verify / 'questions.jsonl').write_text('') | |
| result = summary.summarize(root / 'src', root / 'verify') | |
| self.assertEqual(len(result['per_case']), len(cases)) | |
| for row, (name, duration, _, expected) in zip(result['per_case'], cases): | |
| with self.subTest(name=name): | |
| self.assertEqual((row['name'], row['duration_s'], row['length']), (name, duration, expected)) | |
| if __name__ == '__main__': | |
| unittest.main() | |