def test_twostep_ordering(): strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts3/3"), 2, 'backwards', order_by="time_asc") all = strategy.all() assert tangos.get_item("sim/ts1/4") == all[0] assert tangos.get_item("sim/ts2/4") == all[1] strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts3/3"), 2, 'backwards', order_by="time_desc") all = strategy.all() assert tangos.get_item("sim/ts2/4") == all[0] assert tangos.get_item("sim/ts1/4") == all[1] strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts3/1"), 2, 'backwards', order_by=["time_asc", "weight"]) all, weights = strategy.all_and_weights() I = tangos.get_item testing.assert_halolists_equal( all, [ ("sim/ts1/1"), ("sim/ts1/2"), # ("sim/ts1/1"), weaker route should NOT be returned by default ("sim/ts2/1"), ("sim/ts2/2") ])
def test_self_inclusion(): # default: include_startpoint = False results = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts1/1"), 5, 'forwards').all() assert tangos.get_item("sim/ts1/1") not in results results = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts1/1"), 5, 'forwards', include_startpoint=True).all() assert tangos.get_item("sim/ts1/1") in results
def test_results_as_temptable(): standard_results = halo_finding.MultiHopStrategy( tangos.get_item("sim/ts2/1"), 2, 'backwards').all() with halo_finding.MultiHopStrategy(tangos.get_item("sim/ts2/1"), 2, 'backwards').temp_table() as table: thl_results = thl.halo_query(table).all() assert standard_results == thl_results
def test_twostep_direction(): strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts2/1"), 2, 'backwards') timesteps = set([x.timestep for x in strategy.all()]) assert tangos.get_item("sim/ts1") in timesteps assert tangos.get_item("sim/ts2") not in timesteps assert tangos.get_item("sim/ts3") not in timesteps
def test_simple_twostep_hop(): strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts3/3"), 2, 'backwards') assert strategy.count()==2 all, weights = strategy.all_and_weights() assert tangos.get_item("sim/ts1/4") in all assert tangos.get_item("sim/ts2/4") in all assert weights[0]==1.0 assert weights[1]==1.0
def test_twostep_multiroute(): strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts3/1"), 2, 'backwards', order_by=["time_asc", "weight"], combine_routes=False) all, weights = strategy.all_and_weights() I = tangos.get_item assert all==[I("sim/ts1/1"), I("sim/ts1/2"), I("sim/ts1/1"), # route 2 I("sim/ts2/1"), I("sim/ts2/2")]
def test_temptable_exceptions(): strategy = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts2/1"), 2, 'backwards') class TestException(Exception): pass def raise_exception(): raise TestException strategy._generate_multihop_results = raise_exception with assert_raises(TestException): with strategy.temp_table() as table: assert False, "This point should not be reached"
def test_across(): results = halo_finding.MultiHopStrategy(tangos.get_item("sim/ts2/2"), directed='across').all() testing.assert_halolists_equal(results, ["sim2/ts2/1"])