From 208b0df94be3d832a9950d6e8e3556bbc433e01b Mon Sep 17 00:00:00 2001 From: Andrew Pontzen Date: Mon, 26 Feb 2024 09:18:40 +0000 Subject: [PATCH] Fix issues with out-of-order tests --- tests/test_halo_setitem.py | 8 +++++--- tests/test_histogram_property.py | 1 + tests/test_linking.py | 3 ++- tests/test_simulation_outputs.py | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_halo_setitem.py b/tests/test_halo_setitem.py index e30ddcc6..ce7409d2 100644 --- a/tests/test_halo_setitem.py +++ b/tests/test_halo_setitem.py @@ -15,6 +15,8 @@ def setup_module(): generator.add_timestep() generator.add_objects_to_timestep(3) + tangos.get_halo("sim/ts1/1")['item_for_update'] = 24 + def teardown_module(): tangos.core.close_db() @@ -29,10 +31,10 @@ def test_set_another_item(): assert tangos.get_halo("sim/ts1/2")['bla'] == 42 def test_update_item(): - assert tangos.get_halo("sim/ts1/1")['bla'] == 23 - tangos.get_halo("sim/ts1/1")['bla'] = 96 + assert tangos.get_halo("sim/ts1/1")['item_for_update'] == 24 + tangos.get_halo("sim/ts1/1")['item_for_update'] = 96 db.core.get_default_session().commit() - assert tangos.get_halo("sim/ts1/1")['bla'] == 96 + assert tangos.get_halo("sim/ts1/1")['item_for_update'] == 96 def test_set_large_item(): "Test inserting arrays with size up to a few MiB" diff --git a/tests/test_histogram_property.py b/tests/test_histogram_property.py index 3366d35b..7d98da5e 100644 --- a/tests/test_histogram_property.py +++ b/tests/test_histogram_property.py @@ -147,6 +147,7 @@ def test_summed_reconstruction_across_simulations(): finally: ts2.simulation = db.query.get_simulation("sim") + session.commit() def test_custom_delta_t(): diff --git a/tests/test_linking.py b/tests/test_linking.py index 996bf0cf..e3d207cd 100644 --- a/tests/test_linking.py +++ b/tests/test_linking.py @@ -31,13 +31,14 @@ def test_issue_77(): assert(ih1.load_timestep("step.1") is not ih2.load_timestep("step.1")) def test_timestep_linking(): + orig_count = db.get_halo("dummy_sim_1/step.1/1").links.count() # may not be zero if tests run out of order tl = crosslink.TimeLinker() tl.parse_command_line([]) with log.LogCapturer(): tl.run_calculation_loop() assert db.get_halo("dummy_sim_1/step.1/1").next==db.get_halo("dummy_sim_1/step.2/1") assert db.get_halo("dummy_sim_1/step.2/2").previous == db.get_halo("dummy_sim_1/step.1/2") - assert db.get_halo("dummy_sim_1/step.1/1").links.count()==2 + assert db.get_halo("dummy_sim_1/step.1/1").links.count() - orig_count==2 def test_crosslinking(): cl = crosslink.CrossLinker() diff --git a/tests/test_simulation_outputs.py b/tests/test_simulation_outputs.py index 69683cfb..9bf2dd0d 100644 --- a/tests/test_simulation_outputs.py +++ b/tests/test_simulation_outputs.py @@ -108,6 +108,7 @@ def test_partial_load_tracker_halo(): assert pynbody_h.ancestor is pynbody_h def test_load_persistence(): + add_test_simulation_to_db() f = db.get_timestep("test_tipsy/tiny.000640").load() f2 = db.get_timestep("test_tipsy/tiny.000640").load() h = db.get_halo("test_tipsy/tiny.000640/1").load() @@ -158,6 +159,7 @@ def assert_is_subview_of_full_file(pynbody_h): assert len(pynbody_h.ancestor) == len(db.get_timestep("test_tipsy/tiny.000640").load()) def test_load_region(): + add_test_simulation_to_db() region = db.get_timestep("test_tipsy/tiny.000640").load_region(pynbody.filt.Sphere(2000,[1000,1000,1000])) assert (region['iord']==[ 9980437, 10570437, 10630437, 10640437, 10770437, 10890437, 10900437, 10960437, 11030437, 11090437, 11480437, 11490437, @@ -165,6 +167,7 @@ def test_load_region(): 13380437, 13710437]).all() def test_load_region_uses_cache(): + add_test_simulation_to_db() filt1 = pynbody.filt.Sphere(2000,[1000,1000,1000]) filt2 = pynbody.filt.Sphere(2000,[1001,1000,1000])