Files
Neutron/tests/test_collision_material_identity.py
T

43 lines
1.9 KiB
Python

from pathlib import Path
from types import SimpleNamespace
import sys
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'tools/extractors'))
from omt import Entry, export_scene
class CollisionMaterialIdentityTests(unittest.TestCase):
def export(self, link, identity=61):
shape = dict(vertices=[(0, 0, 0), (1, 0, 0), (0, 1, 0)], normals=[],
polygons=[dict(corners=[dict(vertex=i, normal=0, uv=(0, 0)) for i in range(3)],
normal=(0, 0, 1), material=link)])
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
database = SimpleNamespace(path=root/'input'/'fixture.omt', data=b'fixture',
entries=[Entry('3DSh', 0, 0, 0, 'wall'), Entry('3DMa', identity, 0, 0, 'fence')],
payload=lambda entry: b'')
with patch('omt.read_shape', return_value=shape), patch('omt.read_material', return_value={}):
return export_scene(database, root/'output')['collisionPolygons'][0]
def test_archive_identity_is_preserved_independently_of_render_index(self):
polygon = self.export(dict(type='3DMa', id=61))
self.assertEqual((polygon['materialId'], polygon['materialName']), (61, 'fence'))
def test_null_missing_and_wrong_type_links_are_not_materials(self):
for link in (None, dict(type='3DMa', id=999), dict(type='3DSh', id=61)):
with self.subTest(link=link):
polygon = self.export(link)
self.assertIsNone(polygon['materialId'])
self.assertIsNone(polygon['materialName'])
def test_callback_identity_is_a_signed_long(self):
self.assertEqual(self.export(dict(type='3DMa', id=0xffffffff), 0xffffffff)['materialId'], -1)
if __name__ == '__main__':
unittest.main()