From 4faaa4062b76069a03956137927b45b1073f9d1e Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Thu, 11 Aug 2022 14:03:21 -0500 Subject: [PATCH] moved test out of python API into C++ API. modeled after test that adds a new tally. TODO add a test that tries to delete an invalid ID --- tests/unit_tests/test_lib.py | 14 ++++++++++++++ tests/unit_tests/test_tallies.py | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_lib.py b/tests/unit_tests/test_lib.py index b572429835..225415e56a 100644 --- a/tests/unit_tests/test_lib.py +++ b/tests/unit_tests/test_lib.py @@ -339,6 +339,20 @@ def test_new_tally(lib_init): new_tally_with_id.scores = ['flux'] assert len(openmc.lib.tallies) == 5 +def test_add_and_delete_tally(lib_init): + with pytest.raises(exc.AllocationError): + openmc.lib.Material(1) + new_tally = openmc.lib.Tally() + new_tally.scores = ['flux'] + new_tally_with_id = openmc.lib.Tally(10) + new_tally_with_id.scores = ['flux'] + assert len(openmc.lib.tallies) == 5 + # delete tally and check length is one less than before + openmc_remove_tally(10) + assert len(openmc.lib.tallies) == 4 + +# def test_delete_wrong_id(): + def test_tally_activate(lib_simulation_init): t = openmc.lib.tallies[1] diff --git a/tests/unit_tests/test_tallies.py b/tests/unit_tests/test_tallies.py index 77aef78b41..14319a0a29 100644 --- a/tests/unit_tests/test_tallies.py +++ b/tests/unit_tests/test_tallies.py @@ -38,7 +38,4 @@ def test_xml_roundtrip(run_in_tmpdir): assert len(new_tally.triggers) == 1 assert new_tally.triggers[0].trigger_type == tally.triggers[0].trigger_type assert new_tally.triggers[0].threshold == tally.triggers[0].threshold - assert new_tally.triggers[0].scores == tally.triggers[0].scores - # delete tally and check that new_tallies now has length zero - new_tally.openmc_remove_tally_from_tallies(tally.id) - assert len(new_tallies) == 0 \ No newline at end of file + assert new_tally.triggers[0].scores == tally.triggers[0].scores \ No newline at end of file