tools/data/test_door_statels.py (2211B)
1 import json 2 import pathlib 3 import unittest 4 5 import extract_backyards 6 7 8 class DoorStatelTests(unittest.TestCase): 9 def setUp(self): 10 source = json.loads((pathlib.Path(__file__).parent / 'testdata/door_statels_1491.json').read_text()) 11 self.records = {record['identity']: record for record in source['records']} 12 13 def test_four_integer_door_teleport(self): 14 descriptor = bytes.fromhex(self.records[3221356668]['raw_hex'])[64:] 15 16 attributes = extract_backyards.parse_descriptor(descriptor) 17 18 self.assertEqual(len(attributes), 1) 19 function = attributes[0]['functions'][0] 20 self.assertEqual(function['id'], 53016) 21 self.assertEqual(function['argument_header'], 9) 22 self.assertEqual(function['arguments'], [ 23 {'integer': 604}, {'integer': 0}, {'integer': 402}, {'integer': 640}]) 24 25 def test_instance_door_preserves_its_destination_and_following_stats(self): 26 descriptor = bytes.fromhex(self.records[3221488221]['raw_hex'])[64:] 27 28 attributes = extract_backyards.parse_descriptor(descriptor) 29 30 self.assertEqual(attributes[0]['functions'][0]['id'], 53083) 31 self.assertEqual(attributes[0]['functions'][0]['arguments'], [ 32 {'integer': 51102}, {'integer': 1004}, {'integer': 0}, {'integer': 0}, 33 {'bytes_hex': '000186a1000703ec000001f4'}]) 34 self.assertEqual(attributes[1], {'stats': [[12, 41611]]}) 35 36 def test_zero_argument_door_function_preserves_following_stats(self): 37 descriptor = bytes.fromhex(self.records[3222078006]['raw_hex'])[64:] 38 39 attributes = extract_backyards.parse_descriptor(descriptor) 40 41 self.assertEqual(attributes[0]['functions'][0]['id'], 53109) 42 self.assertEqual(attributes[0]['functions'][0]['arguments'], []) 43 self.assertEqual(attributes[1], {'stats': [[12, 42037]]}) 44 45 def test_truncated_door_descriptors_are_rejected(self): 46 for identity, record in self.records.items(): 47 with self.subTest(identity=identity): 48 descriptor = bytes.fromhex(record['raw_hex'])[64:-1] 49 50 with self.assertRaises(ValueError): 51 extract_backyards.parse_descriptor(descriptor)