Coverage for test / unit / tasks / common / test_load_ifc.py: 80%

74 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-12 10:59 +0000

1import shutil 

2import tempfile 

3import unittest 

4from pathlib import Path 

5 

6import bim2sim 

7from bim2sim.kernel.decision.decisionhandler import DebugDecisionHandler 

8from bim2sim.tasks.common import LoadIFC 

9 

10from test.unit.tasks import TestTask 

11from test.unit.elements.helper import SetupHelper 

12from bim2sim.sim_settings import BaseSimSettings 

13 

14test_rsrc_path = Path(__file__).parent.parent.parent.parent / 'resources' 

15 

16 

17class TestLoadIFC(TestTask): 

18 @classmethod 

19 def simSettingsClass(cls): 

20 return BaseSimSettings() 

21 

22 @classmethod 

23 def testTask(cls): 

24 return LoadIFC(cls.playground) 

25 

26 @classmethod 

27 def helper(cls): 

28 return SetupHelper() 

29 

30 # define setUpClass 

31 @classmethod 

32 def setUpClass(cls) -> None: 

33 super().setUpClass() 

34 cls.test_task.paths.finder = ( 

35 Path(bim2sim.__file__).parent / 

36 'assets/finder/template_ArchiCAD.json') 

37 

38 def test_load_ifc(self): 

39 ifc_temp_dir = tempfile.TemporaryDirectory( 

40 prefix='bim2sim_test_load_ifc') 

41 temp_path = Path(ifc_temp_dir.name) 

42 subdir_path = temp_path / 'ifc/arch' 

43 subdir_path.mkdir(parents=True, exist_ok=True) 

44 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifc' 

45 destination_file = subdir_path / source_file.name 

46 shutil.copy2(source_file, destination_file) 

47 

48 self.test_task.paths.ifc_base = temp_path / 'ifc' 

49 touches = DebugDecisionHandler(answers=()).handle(self.test_task.run()) 

50 

51 ifc_file_name = touches[0][0].ifc_file_name 

52 ifc_schema = touches[0][0].schema 

53 n_windows = len(touches[0][0].file.by_type('IfcWindow')) 

54 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifc") 

55 self.assertEqual(ifc_schema, "IFC4") 

56 self.assertEqual(n_windows, 11) 

57 

58 def test_load_ifczip(self): 

59 ifc_temp_dir = tempfile.TemporaryDirectory( 

60 prefix='bim2sim_test_load_ifc') 

61 temp_path = Path(ifc_temp_dir.name) 

62 subdir_path = temp_path / 'ifc/arch' 

63 subdir_path.mkdir(parents=True, exist_ok=True) 

64 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifczip' 

65 destination_file = subdir_path / source_file.name 

66 shutil.copy2(source_file, destination_file) 

67 

68 self.test_task.paths.ifc_base = temp_path / 'ifc' 

69 touches = DebugDecisionHandler( 

70 answers=()).handle(self.test_task.run()) 

71 

72 ifc_file_name = touches[0][0].ifc_file_name 

73 ifc_schema = touches[0][0].schema 

74 n_windows = len(touches[0][0].file.by_type('IfcWindow')) 

75 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifczip") 

76 self.assertEqual(ifc_schema, "IFC4") 

77 self.assertEqual(n_windows, 11) 

78 

79 @unittest.skip("IFCXML created with IfcOpenShell seems faulty, this might " 

80 "not be due to bim2sim but IfcOpenShell itself") 

81 def test_load_ifcxml(self): 

82 ifc_temp_dir = tempfile.TemporaryDirectory( 

83 prefix='bim2sim_test_load_ifc') 

84 temp_path = Path(ifc_temp_dir.name) 

85 subdir_path = temp_path / 'ifc/arch' 

86 subdir_path.mkdir(parents=True, exist_ok=True) 

87 source_file = test_rsrc_path / 'arch/ifc/AC20-FZK-Haus.ifcxml' 

88 destination_file = subdir_path / source_file.name 

89 shutil.copy2(source_file, destination_file) 

90 

91 self.test_task.paths.ifc_base = temp_path / 'ifc' 

92 touches = DebugDecisionHandler( 

93 answers=()).handle(self.test_task.run()) 

94 

95 ifc_file_name = touches[0][0].ifc_file_name 

96 ifc_schema = touches[0][0].schema 

97 n_windows = len(touches[0][0].file.by_type('IfcWindow')) 

98 self.assertEqual(ifc_file_name, "AC20-FZK-Haus.ifcxml") 

99 self.assertEqual(ifc_schema, "IFC4") 

100 self.assertEqual(n_windows, 11)