Coverage for test/unit/test_project.py: 96%
50 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 os
2import shutil
3import tempfile
4import unittest
5from pathlib import Path
7from bim2sim.plugins import Plugin
8from bim2sim.project import Project
9from bim2sim.sim_settings import PlantSimSettings
10from bim2sim.utilities.types import IFCDomain
12sample_root = Path(__file__).parent.parent.parent / \
13 'test/resources/hydraulic/ifc'
14ifc_paths = {
15 IFCDomain.hydraulic:
16 sample_root /
17 'KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc'}
20class PluginDummy(Plugin):
21 name = "Dummy"
22 sim_settings = PlantSimSettings
23 tasks = []
26class BaseTestProject(unittest.TestCase):
28 def setUp(self):
29 self.directory = tempfile.TemporaryDirectory(prefix='bim2sim_')
30 self.path = os.path.join(self.directory.name, 'proj')
32 def tearDown(self):
33 try:
34 self.directory.cleanup()
35 except PermissionError:
36 pass
39class TestProject(BaseTestProject):
41 def test_create_remove(self):
42 """Test creation and deletion of Project"""
44 project = Project.create(
45 self.path,
46 ifc_paths,
47 PluginDummy
48 )
50 self.assertTrue(os.path.samefile(self.path, project.paths.root))
51 self.assertTrue(os.path.exists(project.paths.config))
52 self.assertTrue(os.path.exists(project.paths.ifc_base))
54 project.delete()
56 self.assertFalse(os.path.exists(project.paths.root),
57 f"Project folder {project.paths} not deleted!")
59 def test_double_create(self):
60 """Test creating two projects in same dir"""
61 project = Project.create(
62 self.path,
63 ifc_paths,
64 PluginDummy
65 )
66 self.assertTrue(os.path.exists(project.paths.ifc_base))
67 project.finalize(True)
69 domain = list(ifc_paths.keys())[0].name
70 shutil.rmtree(project.paths.ifc_base / domain)
71 self.assertFalse(os.path.exists(project.paths.ifc_base / domain))
73 project2 = Project.create(
74 self.path,
75 ifc_paths,
76 PluginDummy
77 )
78 self.assertTrue(os.path.exists(project2.paths.ifc_base / domain))
79 project2.finalize(True)
81 def test_reuse_project_folder_change_plugin(self):
82 """Tests to create project, reuse folder with other Plugin"""
83 project = Project.create(
84 self.path,
85 ifc_paths,
86 PluginDummy
87 )
88 self.assertEqual(project.plugin_cls, PluginDummy)
89 project.finalize(True)
91 project2 = Project.create(
92 self.path,
93 ifc_paths,
94 'aixlib'
95 )
96 from bim2sim.plugins.PluginAixLib.bim2sim_aixlib import PluginAixLib
97 project2.finalize(True)
98 self.assertEqual(project2.plugin_cls.__name__, PluginAixLib.__name__)