Skip to content

Commit

Permalink
Fix issues with out-of-order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apontzen committed Feb 26, 2024
1 parent 490d24e commit 208b0df
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tests/test_halo_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/test_histogram_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_simulation_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -158,13 +159,15 @@ 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,
11550437, 11740437, 12270437, 12590437, 12600437, 12920437,
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])

Expand Down

0 comments on commit 208b0df

Please sign in to comment.