File size: 2,142 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Generic lamp slots may bind to lamp-family source categories; shades and other categories stay rejected."""
import sys
import unittest
from pathlib import Path

BASE = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(BASE))

from room_program import _binding_transition_fields  # noqa: E402


def _slot(**over):
    row = dict(entity_id='lamp', room_id='living', role='lamp', procedural_kind='bedside_lamp',
               category='lamp', asset_id='procedural:lamp')
    row.update(over)
    return row


def _bound(category, **over):
    row = dict(entity_id='lamp', room_id='living', role='lamp', binding_semantic_key='lamp',
               category=category, asset_id='hssd:objects/a/aaaa', asset_sha256='a' * 64,
               runtime_sha256='b' * 64, canonical_path='/canon/x.glb', runtime_path='/run/x.glb',
               dimensions_m=[0.3, 0.3, 0.5], source_dimensions_m=[0.3, 0.3, 0.5], uniform_scale=1.0)
    row.update(over)
    return row


MANIFEST = {'fixed_layout_real_asset_binding': {'binding_phase': 'final', 'final_binding_passed': True,
            'uniform_scale_only': True, 'preserve_source_materials': True}}


class LampSourceFamilyTests(unittest.TestCase):
    def test_generic_lamp_accepts_lamp_family_source_category(self):
        fields = _binding_transition_fields(_slot(), _bound('malay_lamp_base_furniture_base_d5b3'), MANIFEST)
        self.assertIn('category', fields)

    def test_generic_lamp_accepts_plain_table_lamp(self):
        self.assertIn('category', _binding_transition_fields(_slot(), _bound('table_lamp'), MANIFEST))

    def test_lamp_shade_is_rejected(self):
        self.assertEqual(_binding_transition_fields(_slot(), _bound('lamp_shade'), MANIFEST), ())

    def test_non_lamp_category_is_rejected(self):
        self.assertEqual(_binding_transition_fields(_slot(), _bound('plate'), MANIFEST), ())

    def test_authored_lamp_subtype_stays_exact(self):
        self.assertEqual(_binding_transition_fields(_slot(category='floor_lamp'),
                                                    _bound('table_lamp'), MANIFEST), ())


if __name__ == '__main__':
    unittest.main()