Coverage for test/unit/tasks/common/test_load_ifc.py: 79%
72 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
1import shutil
2import tempfile
3import unittest
4from pathlib import Path
5from unittest import mock
7import bim2sim
8from bim2sim.kernel.decision.decisionhandler import DebugDecisionHandler
9from bim2sim.tasks.common import LoadIFC
11test_rsrc_path = Path(__file__).parent.parent.parent.parent / 'resources'
14class TestLoadIFC(unittest.TestCase):
15 load_task = None
16 export_path = None
17 playground = None
19 @classmethod
20 def setUpClass(cls) -> None:
21 # Set up playground, project and paths via mocks
22 cls.playground = mock.Mock()
23 project = mock.Mock()
24 paths = mock.Mock()
25 cls.playground.project = project
27 # Instantiate export task and set required values via mocks
28 cls.load_ifc_task = LoadIFC(cls.playground)
29 cls.load_ifc_task.prj_name = 'TestLoadIFC'
30 cls.load_ifc_task.paths = paths
31 cls.load_ifc_task.paths.finder = (
32 Path(bim2sim.__file__).parent /
33 'assets/finder/template_ArchiCAD.json')
35 def test_load_ifc(self):
36 ifc_temp_dir = tempfile.TemporaryDirectory(
37 prefix='bim2sim_test_load_ifc')
38 temp_path = Path(ifc_temp_dir.name)
39 subdir_path = temp_path / 'ifc/arch'
40 subdir_path.mkdir(parents=True, exist_ok=True)
41 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifc'
42 destination_file = subdir_path / source_file.name
43 shutil.copy2(source_file, destination_file)
45 self.load_ifc_task.paths.ifc_base = temp_path / 'ifc'
46 touches = DebugDecisionHandler(answers=()).handle(self.load_ifc_task.run())
48 ifc_file_name = touches[0][0].ifc_file_name
49 ifc_schema = touches[0][0].schema
50 n_windows = len(touches[0][0].file.by_type('IfcWindow'))
51 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifc")
52 self.assertEqual(ifc_schema, "IFC4")
53 self.assertEqual(n_windows, 11)
55 def test_load_ifczip(self):
56 ifc_temp_dir = tempfile.TemporaryDirectory(
57 prefix='bim2sim_test_load_ifc')
58 temp_path = Path(ifc_temp_dir.name)
59 subdir_path = temp_path / 'ifc/arch'
60 subdir_path.mkdir(parents=True, exist_ok=True)
61 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifczip'
62 destination_file = subdir_path / source_file.name
63 shutil.copy2(source_file, destination_file)
65 self.load_ifc_task.paths.ifc_base = temp_path / 'ifc'
66 touches = DebugDecisionHandler(
67 answers=()).handle(self.load_ifc_task.run())
69 ifc_file_name = touches[0][0].ifc_file_name
70 ifc_schema = touches[0][0].schema
71 n_windows = len(touches[0][0].file.by_type('IfcWindow'))
72 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifczip")
73 self.assertEqual(ifc_schema, "IFC4")
74 self.assertEqual(n_windows, 11)
76 @unittest.skip("IFCXML created with IfcOpenShell seems faulty, this might "
77 "not be due to bim2sim but IfcOpenShell itself")
78 def test_load_ifcxml(self):
79 ifc_temp_dir = tempfile.TemporaryDirectory(
80 prefix='bim2sim_test_load_ifc')
81 temp_path = Path(ifc_temp_dir.name)
82 subdir_path = temp_path / 'ifc/arch'
83 subdir_path.mkdir(parents=True, exist_ok=True)
84 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifcxml'
85 destination_file = subdir_path / source_file.name
86 shutil.copy2(source_file, destination_file)
88 self.load_ifc_task.paths.ifc_base = temp_path / 'ifc'
89 touches = DebugDecisionHandler(
90 answers=()).handle(self.load_ifc_task.run())
92 ifc_file_name = touches[0][0].ifc_file_name
93 ifc_schema = touches[0][0].schema
94 n_windows = len(touches[0][0].file.by_type('IfcWindow'))
95 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifcxml")
96 self.assertEqual(ifc_schema, "IFC4")
97 self.assertEqual(n_windows, 11)