Skip to content

Commit 18c84ae

Browse files
committed
Add test for temperature unit conversion in SBML
Introduces a test to verify that temperature values in Celsius are correctly converted to Kelvin when reading and writing SBML files. Ensures the temperature unit is set to 'Kelvin' after conversion.
1 parent b772194 commit 18c84ae

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/integration/test_sbml.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,27 @@ def test_end_to_end(self):
140140
"Parsed document does not match expected document"
141141
)
142142

143+
def test_temperature_conversion(self):
144+
enzmldoc = pe.read_enzymeml("tests/fixtures/modeling/enzmldoc_reaction.json")
145+
enzmldoc.measurements = [enzmldoc.measurements[0]]
146+
enzmldoc.measurements[0].temperature = 0.0
147+
enzmldoc.measurements[0].temperature_unit = "°C" # type: ignore
148+
149+
with tempfile.TemporaryDirectory() as dirname:
150+
# Write to OMEX and read again
151+
path = Path(dirname) / "test.omex"
152+
pe.to_sbml(enzmldoc, path)
153+
enzmldoc = pe.from_sbml(path)
154+
155+
assert enzmldoc.measurements[0].temperature == 273.15
156+
157+
if enzmldoc.measurements[0].temperature_unit is not None:
158+
assert enzmldoc.measurements[0].temperature_unit.name == "Kelvin"
159+
else:
160+
raise ValueError("Temperature unit is None")
161+
143162
def set_unit_name_as_id(self, obj):
144163
for key, value in obj:
145-
print(key, value)
146164
if isinstance(value, pe.UnitDefinition):
147165
value.id = value.name
148166
elif isinstance(value, BaseModel):

0 commit comments

Comments
 (0)