Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the addition of a numbered object from another problem #467

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
MontePy Changelog
=================

#Next Version#
--------------

**Bug fixes**

* Fixed bug with appending and renumbeing numbered objects from other MCNP problems (:issue:`466`).


0.3.2
--------------

Expand Down
4 changes: 2 additions & 2 deletions montepy/numbered_object_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ def append_renumber(self, obj, step=1):
if not isinstance(step, int):
raise TypeError("The step number must be an int")
number = obj.number
if self._problem:
obj.link_to_problem(self._problem)
try:
self.append(obj)
except NumberConflictError:
number = self.request_number(number, step)
obj.number = number
self.append(obj)

if self._problem:
obj.link_to_problem(self._problem)
return number

def request_number(self, start_num=1, step=1):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_numbered_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ def test_append_renumber(self):
self.assertEqual(cell.number, 4)
self.assertEqual(len(cells), size + 2)

def test_append_renumber_problems(self):
prob1 = copy.deepcopy(self.simple_problem)
prob2 = copy.deepcopy(self.simple_problem)
# Delete Material 2, making its number available.
prob2.materials.remove(prob2.materials[2])
len_mats = len(prob2.materials)
mat1 = prob1.materials[1]
new_num = prob2.materials.append_renumber(mat1)
self.assertEqual(new_num, 2)
self.assertEqual(len(prob2.materials), len_mats + 1)
self.assertIs(prob2.materials[2], mat1)
tjlaboss marked this conversation as resolved.
Show resolved Hide resolved

def test_request_number(self):
cells = self.simple_problem.cells
self.assertEqual(cells.request_number(6), 6)
Expand Down