mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 06:38:40 +00:00
sql, stream: raise for accessing derived attributes
Raising `AttributeError` is definitely wasn't correct here, since it might push the code to assume it's a wrong entity type. Returning some stub value like `None` also could suggest incorrect derived attribute value, leading to unexpected behaviour. So adding an error, so it would propagate and code would need to be adjusted not to rely on derived attributes, if it actually interacts with sql/stream. `test_unit` was asserting that derived attr will return `None`, though it was actually raising `AttributeError`.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from ifcpatch.recipes import Ifc2Sql
|
||||
|
||||
import ifcopenshell
|
||||
@@ -63,6 +64,12 @@ class TestEntity:
|
||||
assert (element := ifc_sqlite.by_id(1))
|
||||
assert element.Name == "My Project"
|
||||
|
||||
def test_getattr_derive(self):
|
||||
ifc_sqlite = get_ifc_sqlite()
|
||||
assert (units := ifc_sqlite.by_type("IfcSIUnit"))
|
||||
with pytest.raises(RuntimeError):
|
||||
units[0].Dimensions
|
||||
|
||||
def test_setattr(self):
|
||||
ifc_sqlite = get_ifc_sqlite()
|
||||
assert (element := ifc_sqlite.by_id(1))
|
||||
|
||||
Reference in New Issue
Block a user