1313
1414import pytest
1515import dataclasses
16+ import difflib
17+ import logging
18+ from pathlib import Path
1619
1720# define standard LIBRA input parameters to be used in multiple tests
1821geom = ColumnGeometry (
3942)
4043
4144
42- def test_from_parameters_success ():
45+ def test_from_parameters_success (tmp_path ):
4346 """
4447 Test that SimulationInput.from_parameters successfully creates a SimulationInput object from minimal input objects
48+ and that the generated SimulationInput is consistent with the standard input it should yield
4549 """
4650 sim_input = SimulationInput .from_parameters (
4751 geom , flibe , operating_params , sparging_params
@@ -57,16 +61,31 @@ def test_from_parameters_success():
5761 f"Expected field '{ field .name } ' to be a pint.Quantity, got { type (value )} "
5862 )
5963
64+ reference_path = Path (__file__ ).with_name ("standard_input.json" )
65+ generated_path = Path (tmp_path ).joinpath ("generated_input.json" )
66+
67+ sim_input .to_json (generated_path )
68+
69+ generated_text = generated_path .read_text (encoding = "utf-8" )
70+ reference_text = reference_path .read_text (encoding = "utf-8" )
71+
72+ diff = "\n " .join (
73+ difflib .unified_diff (
74+ reference_text .splitlines (),
75+ generated_text .splitlines (),
76+ fromfile = str (reference_path .name ),
77+ tofile = str (generated_path .name ),
78+ lineterm = "" ,
79+ )
80+ )
81+ assert generated_text == reference_text , f"Log output mismatch:\n { diff } "
82+
6083
6184def test_find_in_graph_logging (tmp_path ):
6285 """
6386 Test that the `find_in_graph` function logs the expected output when searching for a parameter in the graph.
6487 """
6588 # BUILD
66- import difflib
67- import logging
68- from pathlib import Path
69-
7089 reference_log_path = Path (__file__ ).with_name ("test_find_in_graph.reference.log" )
7190 generated_log_path = Path (tmp_path ).joinpath ("test_find_in_graph.generated.log" )
7291
0 commit comments