2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai - OpenBIM Blender Add-on
|
2022-01-10 10:45:46 +11:00
|
|
|
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# This file is part of Bonsai.
|
2022-01-10 10:45:46 +11:00
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai is free software: you can redistribute it and/or modify
|
2022-01-10 10:45:46 +11:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai is distributed in the hope that it will be useful,
|
2022-01-10 10:45:46 +11:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2024-08-13 15:47:27 +10:00
|
|
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
2022-01-10 10:45:46 +11:00
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import bpy
|
|
|
|
|
import ifcopenshell
|
2024-08-14 13:56:39 +05:00
|
|
|
import bonsai.core.tool
|
|
|
|
|
import bonsai.tool as tool
|
2022-01-10 10:45:46 +11:00
|
|
|
from test.bim.bootstrap import NewFile
|
2024-08-14 13:56:39 +05:00
|
|
|
from bonsai.tool.debug import Debug as subject
|
|
|
|
|
from bonsai.bim.ifc import IfcStore
|
2024-08-23 17:25:00 +05:00
|
|
|
from pathlib import Path
|
2022-01-10 10:45:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestImplementsTool(NewFile):
|
|
|
|
|
def test_run(self):
|
2024-08-14 13:56:39 +05:00
|
|
|
assert isinstance(subject(), bonsai.core.tool.Debug)
|
2022-01-10 10:45:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddSchemaIdentifier(NewFile):
|
|
|
|
|
def test_run(self):
|
2023-01-30 11:27:38 +11:00
|
|
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
2023-03-01 18:14:52 +05:00
|
|
|
schema_path = os.path.join(cwd, "..", "files", "test.exp")
|
|
|
|
|
schema = subject.load_express(schema_path)
|
2023-01-30 11:27:38 +11:00
|
|
|
subject.add_schema_identifier(schema)
|
2022-01-10 10:45:46 +11:00
|
|
|
assert IfcStore.schema_identifiers[-1] == "IFCROGUE"
|
2023-03-01 18:14:52 +05:00
|
|
|
os.remove(schema_path + ".cache.dat")
|
2022-01-10 10:45:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLoadExpress(NewFile):
|
|
|
|
|
def test_run(self):
|
|
|
|
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
2023-03-01 18:14:52 +05:00
|
|
|
schema_path = os.path.join(cwd, "..", "files", "test.exp")
|
|
|
|
|
schema = subject.load_express(schema_path)
|
2022-01-10 10:45:46 +11:00
|
|
|
assert schema.schema_name == "IFCROGUE"
|
2023-03-01 18:14:52 +05:00
|
|
|
os.remove(schema_path + ".cache.dat")
|
2022-01-11 11:24:13 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestPurgeHdf5Cache(NewFile):
|
|
|
|
|
def test_run(self):
|
2024-08-23 17:25:00 +05:00
|
|
|
cache_dir = Path(bpy.context.scene.BIMProperties.data_dir) / "cache"
|
|
|
|
|
test_file = cache_dir / "test.h5"
|
|
|
|
|
test_file.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
test_file.touch()
|
2024-08-27 11:59:56 +05:00
|
|
|
|
|
|
|
|
# Ensure it can skip currently loaded cache.
|
|
|
|
|
loaded_file_path = test_file.with_stem("test_loaded")
|
|
|
|
|
loaded_file = open(loaded_file_path, "w")
|
|
|
|
|
|
2022-01-11 11:24:13 +11:00
|
|
|
subject.purge_hdf5_cache()
|
2024-08-28 11:29:36 +05:00
|
|
|
# On Unix loaded files are not locked.
|
|
|
|
|
paths = [loaded_file_path] if os.name == "nt" else []
|
|
|
|
|
assert [f for f in cache_dir.iterdir() if f.suffix == ".h5"] == paths
|