mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fix mandatory title and optional date and check invalid dates in IDS
This commit is contained in:
@@ -20,7 +20,6 @@ import os
|
||||
import re
|
||||
import logging
|
||||
import operator
|
||||
import os
|
||||
import numpy as np
|
||||
import datetime
|
||||
|
||||
@@ -36,8 +35,9 @@ from xmlschema.validators import identities
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
||||
# http://standards.buildingsmart.org/IDS/ids_05.xsd
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
ids_schema = XMLSchema(os.path.join(cwd, "ids.xsd")) # source: "http://standards.buildingsmart.org/IDS/ids_05.xsd"
|
||||
ids_schema = XMLSchema(os.path.join(cwd, "ids.xsd"))
|
||||
|
||||
|
||||
def error(msg):
|
||||
@@ -49,7 +49,7 @@ class ids:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title="Name",
|
||||
title="Title",
|
||||
copyright=None,
|
||||
version=None,
|
||||
description=None,
|
||||
@@ -79,22 +79,20 @@ class ids:
|
||||
"""
|
||||
self.specifications = []
|
||||
self.info = {}
|
||||
if title:
|
||||
self.info["title"] = title
|
||||
self.info["title"] = title or "Unnamed"
|
||||
if copyright:
|
||||
self.info["copyright"] = copyright
|
||||
if version:
|
||||
self.info["version"] = version
|
||||
if description:
|
||||
self.info["description"] = description
|
||||
if author:
|
||||
if "@" in author:
|
||||
self.info["author"] = author
|
||||
if author and "@" in author:
|
||||
self.info["author"] = author
|
||||
if date:
|
||||
if re.match(r"\d\d\d\d-\d\d-\d\d", date):
|
||||
self.info["date"] = date # date.fromisoformat(creation_date).isoformat()
|
||||
if "date" not in self.info:
|
||||
self.info["date"] = datetime.date.today().isoformat()
|
||||
try:
|
||||
self.info["date"] = datetime.date.fromisoformat(date).isoformat()
|
||||
except ValueError:
|
||||
pass
|
||||
if purpose:
|
||||
self.info["purpose"] = purpose
|
||||
if milestone:
|
||||
@@ -175,19 +173,6 @@ class ids:
|
||||
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# if "ifcversion" in self.info.keys():
|
||||
# if self.info["ifcversion"] in ["2.3.0.1", "4.0.2.1", "4.3.0.0"]:
|
||||
# if self.info["ifcversion"][0:3] == "2.3":
|
||||
# if not ifc_file.schema.startswith("IFC2x3"):
|
||||
# logger.error("IFC file is of %s not of %s schema." % (ifc_file.schema, self.info["ifcversion"]))
|
||||
# elif self.info["ifcversion"][0:3] == "4.0":
|
||||
# if not ifc_file.schema == "IFC4":
|
||||
# logger.error("IFC file is of %s not of %s schema." % (ifc_file.schema, self.info["ifcversion"]))
|
||||
# elif self.info["ifcversion"][0:3] == "4.3":
|
||||
# if not ifc_file.schema.startswith("IFC4x3"):
|
||||
# logger.error("IFC file is of %s not of %s schema." % (ifc_file.schema, self.info["ifcversion"]))
|
||||
# else:
|
||||
# logger.error("IFC version not recognized")
|
||||
|
||||
# Consider other way around: for elem, for spec so we can see if an element pass all IDSes?
|
||||
for spec in self.specifications:
|
||||
@@ -1362,8 +1347,6 @@ class BcfHandler(logging.StreamHandler):
|
||||
viewpoint.components.visibility.default_visibility = True
|
||||
viewpoint.snapshot = None
|
||||
self.bcf.add_viewpoint(topic, viewpoint)
|
||||
# except:
|
||||
# pass
|
||||
|
||||
def flush(self):
|
||||
"""Saves the BCF report to file. Triggered at the end of the validation process."""
|
||||
|
||||
@@ -149,9 +149,6 @@ class TestIdsParsing(unittest.TestCase):
|
||||
|
||||
|
||||
class TestIdsAuthoring(unittest.TestCase):
|
||||
|
||||
"""Creating basic IDS"""
|
||||
|
||||
def test_creating_a_minimal_ids_and_validating(self):
|
||||
specs = ids.ids(title="Title")
|
||||
spec = ids.specification(name="Name")
|
||||
@@ -165,6 +162,38 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
specs.validate(model)
|
||||
# TODO test this without resorting to hooking into logger output
|
||||
|
||||
def test_create_an_ids_with_minimal_information(self):
|
||||
specs = ids.ids(title="title")
|
||||
assert specs.info == {"title": "title"}
|
||||
|
||||
def test_create_an_ids_with_all_possible_information(self):
|
||||
specs = ids.ids(
|
||||
title="title",
|
||||
copyright="copyright",
|
||||
version="version",
|
||||
description="description",
|
||||
author="author@test.com",
|
||||
date="2020-01-01",
|
||||
purpose="purpose",
|
||||
milestone="milestone",
|
||||
)
|
||||
assert specs.info["title"] == "title"
|
||||
assert specs.info["copyright"] == "copyright"
|
||||
assert specs.info["version"] == "version"
|
||||
assert specs.info["description"] == "description"
|
||||
assert specs.info["author"] == "author@test.com"
|
||||
assert specs.info["date"] == "2020-01-01"
|
||||
assert specs.info["purpose"] == "purpose"
|
||||
assert specs.info["milestone"] == "milestone"
|
||||
|
||||
def test_check_invalid_ids_information(self):
|
||||
specs = ids.ids(title=None)
|
||||
assert specs.info["title"] == "Unnamed"
|
||||
specs = ids.ids(author="author")
|
||||
assert not specs.info.get("author")
|
||||
specs = ids.ids(date="9999-99-99")
|
||||
assert not specs.info.get("date")
|
||||
|
||||
def test_entity_create(self):
|
||||
e = ids.entity.create(name="Test_Name", predefinedType="Test_PredefinedType")
|
||||
self.assertEqual(e.name, "Test_Name")
|
||||
@@ -307,21 +336,6 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
os.remove(fn)
|
||||
self.assertTrue(result)
|
||||
|
||||
""" IDS information """
|
||||
|
||||
def test_create_full_information(self):
|
||||
i = ids.ids(
|
||||
title="Test IDS",
|
||||
description="test",
|
||||
author="test@test.com",
|
||||
copyright="test",
|
||||
version=1.23,
|
||||
date="2021-01-01",
|
||||
purpose="test",
|
||||
milestone="test",
|
||||
)
|
||||
self.assertEqual(i.info["version"], 1.23)
|
||||
|
||||
|
||||
class TestIfcValidation(unittest.TestCase):
|
||||
def test_validate_simple(self):
|
||||
|
||||
Reference in New Issue
Block a user