diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e366d..a03f71e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,7 +164,6 @@ having to use the .utils package. See more details below. ```python modes_info = gdtf_fixture.dmx_modes.as_dict() - ``` ##### .utils.get\_geometry\_by\_name @@ -176,7 +175,7 @@ gdtf_fixture.geometries.get_geometry_by_name("geometry name") ##### .utils.get\_geometry\_by\_type ```python -#this is a static method and requires a root_geometry +# this is a static method and requires a root_geometry gdtf_fixture.geometries.get_geometry_by_type(geometry_root, geometry_type) ``` diff --git a/pygdtf/__init__.py b/pygdtf/__init__.py index 5509f82..d2541f9 100644 --- a/pygdtf/__init__.py +++ b/pygdtf/__init__.py @@ -1003,7 +1003,9 @@ def to_xml(self): attrs = {} if self.physical is not None: attrs["Physical"] = f"{self.physical:.6f}" - if self.luminous_intensity is not None: + if self.luminous_intensity is not None and ( + "LuminousIntensity" in self._attr_keys or self.luminous_intensity != 0 + ): attrs["LuminousIntensity"] = f"{self.luminous_intensity:.6f}" if self.transmission is not None and ( "Transmission" in self._attr_keys or self.transmission != 0 diff --git a/tests/test_filter_measurement.py b/tests/test_filter_measurement.py new file mode 100644 index 0000000..c8e88d0 --- /dev/null +++ b/tests/test_filter_measurement.py @@ -0,0 +1,114 @@ +# MIT License +# +# Copyright (C) 2026 Marvin +# +# This file is part of pygdtf. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from pathlib import Path +from xml.etree import ElementTree + +import pygdtf + +# A FilterMeasurement never carries LuminousIntensity in valid GDTF (gdtf.xsd: +# FilterMeasurement declares Physical, Transmission and InterpolationTo only - +# LuminousIntensity is not a permitted attribute there, unlike on +# EmitterMeasurement where it is required). Round-tripping a fixture whose +# Filter/Measurement never had LuminousIntensity must not invent one. +_DSC_XML = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + + +def test_filter_measurement_roundtrip_omits_luminous_intensity(tmp_path: Path): + dsc_file = tmp_path / "description.xml" + dsc_file.write_text(_DSC_XML, encoding="utf-8") + + with pygdtf.FixtureType(dsc_file=str(dsc_file)) as fixture: + writer = pygdtf.FixtureTypeWriter(fixture) + output = tmp_path / "roundtrip.xml" + writer.write_gdtf(output) + + root = ElementTree.fromstring(output.read_bytes()) + + filter_measurement = root.find( + "./FixtureType/PhysicalDescriptions/Filters/Filter/Measurement" + ) + assert filter_measurement is not None + assert "LuminousIntensity" not in filter_measurement.attrib + + emitter_measurement = root.find( + "./FixtureType/PhysicalDescriptions/Emitters/Emitter/Measurement" + ) + assert emitter_measurement is not None + assert emitter_measurement.attrib.get("LuminousIntensity") == "50.000000"