Skip to content

Commit 169c439

Browse files
committed
test_model - simplify stair generation kwargs
1 parent e543785 commit 169c439

1 file changed

Lines changed: 46 additions & 85 deletions

File tree

src/bonsai/test/tool/test_model.py

Lines changed: 46 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import bonsai.tool as tool
3131
import numpy as np
3232
import json
33+
from typing import Any
3334
from test.bim.bootstrap import NewFile
3435
from bonsai.tool.model import Model as subject
3536
from ifcopenshell.util.shape_builder import V, ShapeBuilder
@@ -222,18 +223,20 @@ def compare_data(self, generated_profile, expected_profile):
222223
for vert, vert_gen in zip(verts, verts_gen, strict=True):
223224
assert np.allclose(vert, V(vert_gen), atol=0.01)
224225

226+
CONCRETE_STAIR_KWARGS: dict[str, Any] = {
227+
"base_slab_depth": 0.25,
228+
"has_top_nib": False,
229+
"height": 1.0,
230+
"number_of_treads": 3,
231+
"stair_type": "CONCRETE",
232+
"top_slab_depth": 0.25,
233+
"tread_depth": 0.25,
234+
"tread_run": 0.3,
235+
"width": 1.2,
236+
}
237+
225238
def test_create_concrete_stair(self):
226-
kwargs = {
227-
"base_slab_depth": 0.25,
228-
"has_top_nib": False,
229-
"height": 1.0,
230-
"number_of_treads": 3,
231-
"stair_type": "CONCRETE",
232-
"top_slab_depth": 0.25,
233-
"tread_depth": 0.25,
234-
"tread_run": 0.3,
235-
"width": 1.2,
236-
}
239+
kwargs = self.CONCRETE_STAIR_KWARGS.copy()
237240
verts_data = (
238241
V(0.0, 0, 0.0),
239242
V(0.0, 0, 0.25),
@@ -269,17 +272,8 @@ def test_create_concrete_stair(self):
269272
self.compare_data(generated_profile, expected_profile)
270273

271274
def test_create_concrete_stair_nib(self):
272-
kwargs = {
273-
"base_slab_depth": 0.25,
274-
"has_top_nib": True,
275-
"height": 1.0,
276-
"number_of_treads": 3,
277-
"stair_type": "CONCRETE",
278-
"top_slab_depth": 0.25,
279-
"tread_depth": 0.25,
280-
"tread_run": 0.3,
281-
"width": 1.2,
282-
}
275+
kwargs = self.CONCRETE_STAIR_KWARGS.copy()
276+
kwargs["has_top_nib"] = True
283277
verts_data = (
284278
V(0.0, 0, 0.0),
285279
V(0.0, 0, 0.25),
@@ -318,19 +312,8 @@ def test_create_concrete_stair_nib(self):
318312
self.compare_data(generated_profile, expected_profile)
319313

320314
def test_create_concrete_stair_zero_width_first_tread(self):
321-
"""Test concrete stair with zero-width first tread"""
322-
kwargs = {
323-
"base_slab_depth": 0.25,
324-
"has_top_nib": False,
325-
"height": 1.0,
326-
"number_of_treads": 3,
327-
"stair_type": "CONCRETE",
328-
"top_slab_depth": 0.25,
329-
"tread_depth": 0.25,
330-
"tread_run": 0.3,
331-
"width": 1.2,
332-
"custom_first_last_tread_run": (0.0, 0.0),
333-
}
315+
kwargs = self.CONCRETE_STAIR_KWARGS.copy()
316+
kwargs["custom_first_last_tread_run"] = (0.0, None)
334317
verts_data = (
335318
V(0.0, 0, 0.0),
336319
# First tread skipped - goes straight to second tread
@@ -361,19 +344,8 @@ def test_create_concrete_stair_zero_width_first_tread(self):
361344
self.compare_data(generated_profile, expected_profile)
362345

363346
def test_create_concrete_stair_zero_width_last_tread(self):
364-
"""Test concrete stair with zero-width last tread"""
365-
kwargs = {
366-
"base_slab_depth": 0.25,
367-
"has_top_nib": False,
368-
"height": 1.0,
369-
"number_of_treads": 3,
370-
"stair_type": "CONCRETE",
371-
"top_slab_depth": 0.25,
372-
"tread_depth": 0.25,
373-
"tread_run": 0.3,
374-
"width": 1.2,
375-
"custom_first_last_tread_run": (0.0, 0.0),
376-
}
347+
kwargs = self.CONCRETE_STAIR_KWARGS.copy()
348+
kwargs["custom_first_last_tread_run"] = (None, 0.0)
377349
verts_data = (
378350
V(0.0, 0, 0.0),
379351
V(0.0, 0, 0.25),
@@ -405,15 +377,17 @@ def test_create_concrete_stair_zero_width_last_tread(self):
405377
generated_profile = subject.generate_stair_2d_profile(**kwargs)
406378
self.compare_data(generated_profile, expected_profile)
407379

380+
WOOD_STEEL_STAIR_KWARGS: dict[str, Any] = {
381+
"height": 1.0,
382+
"number_of_treads": 3,
383+
"stair_type": "WOOD/STEEL",
384+
"tread_depth": 0.25,
385+
"tread_run": 0.3,
386+
"width": 1.2,
387+
}
388+
408389
def test_create_wood_steel_stair(self):
409-
kwargs = {
410-
"height": 1.0,
411-
"number_of_treads": 3,
412-
"stair_type": "WOOD/STEEL",
413-
"tread_depth": 0.25,
414-
"tread_run": 0.3,
415-
"width": 1.2,
416-
}
390+
kwargs = self.WOOD_STEEL_STAIR_KWARGS.copy()
417391
verts_data = (
418392
V(0.0, 0, 0.0),
419393
V(0.3, 0, 0.0),
@@ -458,16 +432,8 @@ def test_create_wood_steel_stair(self):
458432
self.compare_data(generated_profile, expected_profile)
459433

460434
def test_create_wood_steel_stair_zero_width_first_tread(self):
461-
"""Test wood/steel stair with zero-width first tread"""
462-
kwargs = {
463-
"height": 1.0,
464-
"number_of_treads": 3,
465-
"stair_type": "WOOD/STEEL",
466-
"tread_depth": 0.25,
467-
"tread_run": 0.3,
468-
"width": 1.2,
469-
"custom_first_last_tread_run": (0.0, 0.0),
470-
}
435+
kwargs = self.WOOD_STEEL_STAIR_KWARGS.copy()
436+
kwargs["custom_first_last_tread_run"] = (0.0, None)
471437
verts_data = (
472438
# First tread skipped - start at second tread
473439
V(0.0, 0, 0.25),
@@ -506,15 +472,9 @@ def test_create_wood_steel_stair_zero_width_first_tread(self):
506472

507473
def test_create_wood_steel_stair_zero_width_last_tread(self):
508474
"""Test wood/steel stair with zero-width last tread"""
509-
kwargs = {
510-
"height": 1.0,
511-
"number_of_treads": 3,
512-
"stair_type": "WOOD/STEEL",
513-
"tread_depth": 0.25,
514-
"tread_run": 0.3,
515-
"width": 1.2,
516-
"custom_first_last_tread_run": (0.0, 0.0),
517-
}
475+
kwargs = self.WOOD_STEEL_STAIR_KWARGS.copy()
476+
kwargs["custom_first_last_tread_run"] = (None, 0.0)
477+
518478
verts_data = (
519479
V(0.0, 0, 0.0),
520480
V(0.3, 0, 0.0),
@@ -551,8 +511,16 @@ def test_create_wood_steel_stair_zero_width_last_tread(self):
551511
generated_profile = subject.generate_stair_2d_profile(**kwargs)
552512
self.compare_data(generated_profile, expected_profile)
553513

514+
GENERIC_STAIR_KWARGS: dict[str, Any] = {
515+
"height": 1.0,
516+
"number_of_treads": 3,
517+
"stair_type": "GENERIC",
518+
"tread_run": 0.3,
519+
"width": 1.2,
520+
}
521+
554522
def test_create_generic_stair(self):
555-
kwargs = {"height": 1.0, "number_of_treads": 3, "stair_type": "GENERIC", "tread_run": 0.3, "width": 1.2}
523+
kwargs = self.GENERIC_STAIR_KWARGS.copy()
556524
verts_data = (
557525
V(0.0, 0, 0.0),
558526
V(0.0, 0, 0.25),
@@ -585,15 +553,8 @@ def test_create_generic_stair(self):
585553
self.compare_data(generated_profile, expected_profile)
586554

587555
def test_create_generic_stair_zero_width_treads(self):
588-
"""Test generic stair with zero-width first and last treads"""
589-
kwargs = {
590-
"height": 1.0,
591-
"number_of_treads": 3,
592-
"stair_type": "GENERIC",
593-
"tread_run": 0.3,
594-
"width": 1.2,
595-
"custom_first_last_tread_run": (0.0, 0.0),
596-
}
556+
kwargs = self.GENERIC_STAIR_KWARGS.copy()
557+
kwargs["custom_first_last_tread_run"] = (0.0, 0.0)
597558
verts_data = (
598559
V(0.0, 0, 0.0),
599560
# First tread skipped

0 commit comments

Comments
 (0)