Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ MontePy Changelog

**Bugs Fixed**

* Fixed a bug where surface type mnemonics (e.g. ``SO``, ``PZ``) were always written in uppercase, discarding the original case supplied by the user (e.g. ``sO``, ``Pz``) (:issue:`522`).

* Fixed a bug where ``append_renumber`` raised a ``TypeError`` when called with an object whose ``number`` is ``None`` (e.g. an object created with no arguments) (:issue:`880`).

**Feature Added**
Expand Down
11 changes: 11 additions & 0 deletions montepy/input_parser/syntax_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,17 @@ def _value_changed(self):
return not math.isclose(
self._print_value, self._og_value, rel_tol=rel_tol, abs_tol=abs_tol
)
if isinstance(self._type, type) and issubclass(self._type, enum.Enum):
# Compare case-insensitively: the original token may differ in case
# from the normalised enum value (e.g. "sO" → SurfaceType.SO).
# If the canonical value matches the original token modulo case,
# the user has not changed the field and the original token is kept.
og = (
self._og_value
if isinstance(self._og_value, str)
else str(self._og_value)
)
Comment on lines +1267 to +1269
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What cases are you guarding against for _og_value not being a string? None was previously checked.

return self.value.value.upper() != og.upper()
return self.value != self._og_value

def _avoid_rounding_truncation(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,21 @@ def test_surface_is_white_bound_setter(cp_simple_problem, in_str, expected):
verify_prob_export(cp_simple_problem, surf)
with pytest.raises(TypeError):
surf.is_white_boundary = 1


@pytest.mark.parametrize(
"in_str,expected",
[
("1 so 0.0", "1 so 0.0"),
("1 sO 0.0", "1 sO 0.0"),
("1 So 0.0", "1 So 0.0"),
("1 SO 0.0", "1 SO 0.0"),
("1 pz 0.0", "1 pz 0.0"),
("1 PZ 0.0", "1 PZ 0.0"),
("1 Pz 0.0", "1 Pz 0.0"),
],
)
def test_surface_preserves_mnemonic_case(in_str, expected):
"""Surface mnemonics should be written with the original case (issue #522)."""
surf = Surface(in_str)
assert surf.mcnp_str() == expected
Loading