"""Reject the missing-root-ID condition that caused RKS #2's replication kick.""" from pathlib import Path import sys import tempfile sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools')) from prefab_identity import check_prefabs, root_id def rejects(text): try: root_id(text) except ValueError: return raise AssertionError('Accepted invalid root identity') assert root_id('GenericEntity { ID "1234567890ABCDEF" }') == '1234567890ABCDEF' assert root_id('GenericEntity : "{ABCDEF1234567890}Prefab.et" {\n' '/* } */ components {} // {\n ID "1234567890ABCDEF" }') == '1234567890ABCDEF' rejects('GenericEntity { components { RplComponent "{1234567890ABCDEF}" {} } }') rejects('GenericEntity { { GenericEntity { ID "1234567890ABCDEF" } } }') rejects('GenericEntity { ID "0000000000000000" }') rejects('GenericEntity { ID "123" }') rejects('GenericEntity { ID "1234567890ABCDEF" ID "1234567890ABCDE0" }') with tempfile.TemporaryDirectory() as directory: paths = [Path(directory) / name for name in ('one.et', 'two.et')] for path in paths: path.write_text('GenericEntity { ID "1234567890ABCDEF" }') try: check_prefabs(paths) except ValueError as error: assert 'Duplicate prefab root ID' in str(error) else: raise AssertionError('Accepted duplicate root identities') print('PASS: missing, child-only, malformed, zero and duplicate prefab root IDs rejected')