Skip to content

Commit ddd8d19

Browse files
committed
Fixes for old unit tests that broke,and a bug in the making with parseToLines not being wholey tuples, and in index_preserved because the filter function was broken
1 parent b1b9adc commit ddd8d19

4 files changed

Lines changed: 203 additions & 178 deletions

File tree

io_xplane2blender/tests/__init__.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
from io_xplane2blender.tests import animation_file_mappings, test_creation_helpers
1515
from io_xplane2blender.xplane_config import getDebug, setDebug
1616
from io_xplane2blender.xplane_helpers import XPlaneLogger, logger
17-
from io_xplane2blender.xplane_types import xplane_bone, xplane_file, xplane_primitive
17+
from io_xplane2blender.xplane_types import (
18+
xplane_attribute,
19+
xplane_bone,
20+
xplane_file,
21+
xplane_primitive,
22+
)
1823

1924
FLOAT_TOLERANCE = 0.0001
2025

@@ -188,10 +193,10 @@ def assertFloatVectorsEqual(
188193
for a_comp, b_comp in zip(a, b):
189194
self.assertFloatsEqual(a_comp, b_comp, tolerance)
190195

191-
def parseFileToLines(self, data: str) -> List[Union[float, str]]:
196+
def parseFileToLines(self, data: str) -> List[Tuple[Union[float, str]]]:
192197
"""
193-
Turns a string of \n seperated lines into a List[Union[float,str]]
194-
without comments or 0 length strings. All numeric parts are converted
198+
Turns a string of \n seperated lines into a list of lines
199+
without comments or 0 length strings with all numeric parts are converted
195200
"""
196201
lines = [] # type: List[Union[float,str]]
197202

@@ -207,7 +212,7 @@ def tryToFloat(part: str) -> Union[float, str]:
207212
line = line.strip()
208213
if line:
209214
if line.startswith("800"):
210-
lines.append(line.split())
215+
lines.append(tuple(line.split()))
211216
else:
212217
lines.append(tuple(map(tryToFloat, line.split())))
213218

@@ -445,34 +450,35 @@ def assertExportableRootExportEqualsFixture(
445450
# asserts that an attributes object equals a dict
446451
def assertAttributesEqualDict(
447452
self,
448-
attrs: List[str],
453+
attrs: List[Union[str, xplane_attribute.XPlaneAttribute]],
449454
d: Dict[str, Any],
450455
floatTolerance: float = FLOAT_TOLERANCE,
451456
):
452-
self.assertEquals(len(d), len(attrs), "Attribute lists have different length")
457+
self.assertEquals(
458+
len(d),
459+
len(attrs),
460+
f"Attribute lists {list(d.keys())}, {list(attrs.keys())} have different length",
461+
)
453462

454463
for name in attrs:
455464
attr = attrs[name]
456465
value = attr.getValue()
457466
expectedValue = d[name]
458467

459-
if isinstance(expectedValue, list) or isinstance(expectedValue, tuple):
460-
self.assertTrue(
461-
isinstance(value, list) or isinstance(value, tuple),
462-
'Attribute value for "%s" is no list or tuple but: %s'
463-
% (name, str(value)),
468+
if isinstance(expectedValue, (list, tuple)):
469+
self.assertIsInstance(
470+
value,
471+
(list, tuple),
472+
msg='Attribute value for "%s" is no list or tuple but: %s',
464473
)
465474
self.assertEquals(
466475
len(expectedValue),
467476
len(value),
468477
'Attribute values for "%s" have different length' % name,
469478
)
470479

471-
for i in range(0, len(expectedValue)):
472-
v = value[i]
473-
expectedV = expectedValue[i]
474-
475-
if isinstance(expectedV, float) or isinstance(expectedV, int):
480+
for i, (v, expectedV) in enumerate(zip(value, expectedValue)):
481+
if isinstance(expectedV, (float, int)):
476482
self.assertFloatsEqual(expectedV, v, floatTolerance)
477483
else:
478484
self.assertEquals(

tests/features/materials.test.py

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,58 @@
1-
import bpy
21
import os
32
import sys
3+
4+
import bpy
5+
46
from io_xplane2blender.tests import *
57
from io_xplane2blender.xplane_config import getDebug
68
from io_xplane2blender.xplane_types import xplane_file
79

810
__dirname__ = os.path.dirname(__file__)
911

12+
1013
class TestMaterials(XPlaneTestCase):
1114
def test_material_attributes(self):
12-
xplaneFile = self.createXPlaneFileFromPotentialRoot(bpy.data.collections["Layer 1"])
13-
14-
green = xplaneFile._bl_obj_name_to_bone['green'].xplaneObject.material
15-
red = xplaneFile._bl_obj_name_to_bone['red'].xplaneObject.material
16-
blue = xplaneFile._bl_obj_name_to_bone['blue'].xplaneObject.material
17-
emissive = xplaneFile._bl_obj_name_to_bone['emissive'].xplaneObject.material
18-
cockpit = xplaneFile._bl_obj_name_to_bone['cockpit'].xplaneObject.material
19-
cockpitPanel = xplaneFile._bl_obj_name_to_bone['cockpit_panel'].xplaneObject.material
20-
invisible = xplaneFile._bl_obj_name_to_bone['invisible'].xplaneObject.material
21-
surface = xplaneFile._bl_obj_name_to_bone['surface'].xplaneObject.material
22-
conditions = xplaneFile._bl_obj_name_to_bone['conditions'].xplaneObject.material
23-
specular = xplaneFile._bl_obj_name_to_bone['specular'].xplaneObject.material
15+
xplaneFile = self.createXPlaneFileFromPotentialRoot(
16+
bpy.data.collections["Layer 1"]
17+
)
18+
19+
green = xplaneFile._bl_obj_name_to_bone["green"].xplaneObject.material
20+
red = xplaneFile._bl_obj_name_to_bone["red"].xplaneObject.material
21+
blue = xplaneFile._bl_obj_name_to_bone["blue"].xplaneObject.material
22+
emissive = xplaneFile._bl_obj_name_to_bone["emissive"].xplaneObject.material
23+
cockpit = xplaneFile._bl_obj_name_to_bone["cockpit"].xplaneObject.material
24+
cockpitPanel = xplaneFile._bl_obj_name_to_bone[
25+
"cockpit_panel"
26+
].xplaneObject.material
27+
invisible = xplaneFile._bl_obj_name_to_bone["invisible"].xplaneObject.material
28+
surface = xplaneFile._bl_obj_name_to_bone["surface"].xplaneObject.material
29+
conditions = xplaneFile._bl_obj_name_to_bone["conditions"].xplaneObject.material
30+
specular = xplaneFile._bl_obj_name_to_bone["specular"].xplaneObject.material
2431

2532
defaultAttrs = {
26-
'ATTR_shiny_rat': 1,
27-
'ATTR_hard': None,
28-
'ATTR_hard_deck': None,
29-
'ATTR_no_hard': True,
30-
'ATTR_blend': True,
31-
'ATTR_shadow_blend': None,
32-
'ATTR_no_blend': None,
33-
'ATTR_draw_enable': True,
34-
'ATTR_shadow': True,
35-
'ATTR_no_shadow': False,
36-
'ATTR_draw_disable': None,
37-
'ATTR_solid_camera': None,
38-
'ATTR_no_solid_camera': True,
39-
'ATTR_light_level': None,
40-
'ATTR_poly_os': None,
41-
'ATTR_draped': None,
42-
'ATTR_no_draped': True
33+
"ATTR_shiny_rat": 1,
34+
"ATTR_hard": None,
35+
"ATTR_hard_deck": None,
36+
"ATTR_no_hard": True,
37+
"ATTR_blend": True,
38+
"ATTR_shadow_blend": None,
39+
"ATTR_no_blend": None,
40+
"ATTR_draw_enable": True,
41+
"ATTR_shadow": True,
42+
"ATTR_no_shadow": False,
43+
"ATTR_draw_disable": None,
44+
"ATTR_solid_camera": None,
45+
"ATTR_no_solid_camera": True,
46+
"ATTR_light_level": None,
47+
"ATTR_poly_os": None,
48+
"ATTR_draped": None,
49+
"ATTR_no_draped": True,
4350
}
4451
defaultCockpitAttrs = {
45-
'ATTR_cockpit': None,
46-
'ATTR_no_cockpit': True,
47-
'ATTR_cockpit_region': None
52+
"ATTR_cockpit": None,
53+
"ATTR_cockpit_lit_only": None,
54+
"ATTR_cockpit_region": None,
55+
"ATTR_no_cockpit": True,
4856
}
4957

5058
redAttrs = defaultAttrs.copy()
@@ -56,48 +64,49 @@ def test_material_attributes(self):
5664
emissiveAttrs = defaultAttrs.copy()
5765

5866
cockpitAttrs = defaultAttrs.copy()
59-
cockpitAttrs['ATTR_shiny_rat'] = 1.0
60-
cockpitAttrs['ATTR_blend'] = True
61-
cockpitAttrs['ATTR_draw_enable'] = True
62-
cockpitAttrs['ATTR_solid_camera'] = True
63-
cockpitAttrs['ATTR_no_solid_camera'] = False
64-
cockpitAttrs['ATTR_light_level'] = [1.0, 2.0, 'light-level-test']
67+
cockpitAttrs["ATTR_shiny_rat"] = 1.0
68+
cockpitAttrs["ATTR_blend"] = True
69+
cockpitAttrs["ATTR_draw_enable"] = True
70+
cockpitAttrs["ATTR_solid_camera"] = True
71+
cockpitAttrs["ATTR_no_solid_camera"] = False
72+
cockpitAttrs["ATTR_light_level"] = [1.0, 2.0, "light-level-test"]
6573
cockpitCockpitAttrs = defaultCockpitAttrs.copy()
66-
cockpitCockpitAttrs['ATTR_cockpit'] = None
67-
cockpitCockpitAttrs['ATTR_no_cockpit'] = True
68-
cockpitCockpitAttrs['ATTR_cockpit_region'] = None
74+
cockpitCockpitAttrs["ATTR_cockpit"] = None
75+
cockpitCockpitAttrs["ATTR_no_cockpit"] = True
76+
cockpitCockpitAttrs["ATTR_cockpit_region"] = None
6977

7078
cockpitPanelAttrs = defaultAttrs.copy()
71-
cockpitPanelAttrs['ATTR_shiny_rat'] = None
72-
cockpitPanelAttrs['ATTR_blend'] = None
73-
cockpitPanelAttrs['ATTR_draw_enable'] = True
79+
cockpitPanelAttrs["ATTR_shiny_rat"] = None
80+
cockpitPanelAttrs["ATTR_blend"] = None
81+
cockpitPanelAttrs["ATTR_draw_enable"] = True
7482
cockpitPanelAttrs["ATTR_shadow"] = None
7583
cockpitPanelAttrs["ATTR_no_shadow"] = None
76-
cockpitPanelAttrs['ATTR_solid_camera'] = True
77-
cockpitPanelAttrs['ATTR_no_solid_camera'] = False
84+
cockpitPanelAttrs["ATTR_solid_camera"] = True
85+
cockpitPanelAttrs["ATTR_no_solid_camera"] = False
7886
cockpitPanelCockpitAttrs = defaultCockpitAttrs.copy()
79-
cockpitPanelCockpitAttrs['ATTR_cockpit'] = True
80-
cockpitPanelCockpitAttrs['ATTR_no_cockpit'] = None
81-
cockpitPanelCockpitAttrs['ATTR_cockpit_region'] = 0
87+
cockpitPanelCockpitAttrs["ATTR_cockpit"] = True
88+
cockpitPanelCockpitAttrs["ATTR_cockpit_lit_only"] = None
89+
cockpitPanelCockpitAttrs["ATTR_cockpit_region"] = 0
90+
cockpitPanelCockpitAttrs["ATTR_no_cockpit"] = None
8291

8392
invisibleAttrs = defaultAttrs.copy()
84-
invisibleAttrs['ATTR_shiny_rat'] = None
85-
invisibleAttrs['ATTR_blend'] = None
86-
invisibleAttrs['ATTR_draw_enable'] = None
87-
invisibleAttrs['ATTR_draw_disable'] = True
93+
invisibleAttrs["ATTR_shiny_rat"] = None
94+
invisibleAttrs["ATTR_blend"] = None
95+
invisibleAttrs["ATTR_draw_enable"] = None
96+
invisibleAttrs["ATTR_draw_disable"] = True
8897
invisibleAttrs["ATTR_shadow"] = None
8998
invisibleAttrs["ATTR_no_shadow"] = None
9099

91100
surfaceAttrs = defaultAttrs.copy()
92-
surfaceAttrs['ATTR_no_hard'] = None
93-
surfaceAttrs['ATTR_hard_deck'] = 'asphalt'
94-
surfaceAttrs['ATTR_poly_os'] = 2
101+
surfaceAttrs["ATTR_no_hard"] = None
102+
surfaceAttrs["ATTR_hard_deck"] = "asphalt"
103+
surfaceAttrs["ATTR_poly_os"] = 2
95104

96105
conditionsAttrs = defaultAttrs.copy()
97-
conditionsAttrs['custom_prop'] = '10'
106+
conditionsAttrs["custom_prop"] = "10"
98107

99108
specularAttrs = defaultAttrs.copy()
100-
specularAttrs['ATTR_shiny_rat'] = 0.25
109+
specularAttrs["ATTR_shiny_rat"] = 0.25
101110

102111
self.assertAttributesEqualDict(red.attributes, redAttrs)
103112
self.assertAttributesEqualDict(red.cockpitAttributes, defaultCockpitAttrs)
@@ -115,7 +124,9 @@ def test_material_attributes(self):
115124
self.assertAttributesEqualDict(cockpit.cockpitAttributes, cockpitCockpitAttrs)
116125

117126
self.assertAttributesEqualDict(cockpitPanel.attributes, cockpitPanelAttrs)
118-
self.assertAttributesEqualDict(cockpitPanel.cockpitAttributes, cockpitPanelCockpitAttrs)
127+
self.assertAttributesEqualDict(
128+
cockpitPanel.cockpitAttributes, cockpitPanelCockpitAttrs
129+
)
119130

120131
self.assertAttributesEqualDict(invisible.attributes, invisibleAttrs)
121132
self.assertAttributesEqualDict(invisible.cockpitAttributes, defaultCockpitAttrs)
@@ -124,20 +135,24 @@ def test_material_attributes(self):
124135
self.assertAttributesEqualDict(surface.cockpitAttributes, defaultCockpitAttrs)
125136

126137
self.assertAttributesEqualDict(conditions.attributes, conditionsAttrs)
127-
self.assertAttributesEqualDict(conditions.cockpitAttributes, defaultCockpitAttrs)
138+
self.assertAttributesEqualDict(
139+
conditions.cockpitAttributes, defaultCockpitAttrs
140+
)
128141

129142
self.assertAttributesEqualDict(specular.attributes, specularAttrs)
130143
self.assertAttributesEqualDict(specular.cockpitAttributes, defaultCockpitAttrs)
131144

132145
def test_export_materials(self):
133146
def filterLines(line):
134-
return isinstance(line[0], str) and line[0].find('ATTR_') == 0
147+
return isinstance(line[0], str) and line[0].find("ATTR_") == 0
135148

136-
filename = 'test_materials'
149+
filename = "test_materials"
137150
self.assertLayerExportEqualsFixture(
138-
0, os.path.join(__dirname__, 'fixtures', filename + '.obj'),
151+
0,
152+
os.path.join(__dirname__, "fixtures", filename + ".obj"),
139153
filterLines,
140154
filename,
141155
)
142156

157+
143158
runTestCases([TestMaterials])

0 commit comments

Comments
 (0)