From e18597a107b7df0e3c900540b3741b8a2370b687 Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 23 Jul 2026 21:31:50 +0200 Subject: [PATCH 1/2] Fix Measurement.to_xml() writing invalid LuminousIntensity on FilterMeasurement Measurement.to_xml() wrote LuminousIntensity unconditionally whenever self.luminous_intensity was not None (default 0.0 on read). This is correct for EmitterMeasurement, which requires the attribute, but the same Measurement class also serializes FilterMeasurement, where gdtf.xsd does not declare LuminousIntensity as a permitted attribute at all - so a round-tripped Filter/Measurement became XSD-invalid even though the source file was valid. Transmission already guards against this one line below via _attr_keys (the set of attribute names actually present on the source element): only re-emit it if it was in the source, or its value is non-zero. This applies the identical condition to LuminousIntensity, so an EmitterMeasurement (which always has LuminousIntensity in valid GDTF) keeps writing it unchanged, while a FilterMeasurement (which never does) stops inventing one. Reproduction: round-trip any GDTF file with PhysicalDescriptions/ Filters/Filter/Measurement elements (e.g. the Robe Robin Esprite / iSpiider / MegaPointe files on gdtf-share.com) and validate against gdtf.xsd - each Filter/Measurement gains an invalid LuminousIntensity="0.000000". --- pygdtf/__init__.py | 4 +- tests/test_filter_measurement.py | 114 +++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/test_filter_measurement.py 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" From 2a455aeae3b6746af8541f3905c4710961780302 Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 23 Jul 2026 21:55:21 +0200 Subject: [PATCH 2/2] Fix pre-existing CHANGELOG.md formatting Unrelated to the LuminousIntensity fix: the "Check if code is formatted" workflow runs ruff format --check with ruff "latest" (not the 0.11.5 pinned in .pre-commit-config.yaml). A newer ruff now reformats markdown-embedded Python code fences too, and CHANGELOG.md had drifted out of compliance on master itself (missing space after # and a stray blank line) - this was failing CI on every push/PR, including this one, independent of the actual change. --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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) ```