def test_readd_simulation(): manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1")) with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants() assert db.core.get_default_session().query(db.core.Simulation).count()==1 assert len(db.get_simulation("dummy_sim_1").timesteps)==2 assert db.get_simulation("dummy_sim_1").properties.count()==3
def test_timestep_linking(): 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
def setup_func(): parallel_tasks.use('null') testing.init_blank_db_for_testing() db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations") manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1")) with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants()
def _perform_simulation_update(): try: old_base = db.config.base db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations_mock_update") manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1")) with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants() finally: db.config.base = old_base
def _setup_dummy_histogram_data(ts1, ts2): global test_histogram test_histogram = np.arange(0.0, 1000.0, 1.0) stored_log = log.LogCapturer() writer = property_writer.PropertyWriter() writer.parse_command_line(["dummy_histogram"]) with stored_log: writer.run_calculation_loop()
def test_renumbering(fresh_database_no_contents): manager = add_simulation.SimulationAdderUpdater( output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2")) assert not manager.simulation_exists() with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants() assert db.get_halo("dummy_sim_2/step.1/halo_2").halo_number == 2 assert db.get_halo("dummy_sim_2/step.1/halo_2").finder_id == 7 assert db.get_halo("dummy_sim_2/step.1/halo_2").NDM == 2006
def test_blocking_avoids_exception(): if testing_db_backend != "sqlite": skip("This test is only relevant for sqlite databases") assert tangos.get_halo("sim/ts1/6") is None db.core.get_default_session().commit() with log.LogCapturer(): pt.launch(_perform_test,3, (True,)) assert tangos.get_halo("sim/ts1/6") is not None
def test_non_blocking_exception(): if testing_db_backend != "sqlite": skip("This test is only relevant for sqlite databases") with _suppress_exception_report(): with assert_raises(sqlalchemy.exc.OperationalError): with log.LogCapturer(): pt.launch(_perform_test,3, (False,)) db.core.get_default_session().rollback()
def test_renumbering_disabled(): testing.init_blank_db_for_testing() manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"), renumber=False) assert not manager.simulation_exists() with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants() assert db.get_halo("dummy_sim_2/step.1/halo_2").halo_number==2 assert db.get_halo("dummy_sim_2/step.1/halo_2").finder_id == 2 assert db.get_halo("dummy_sim_2/step.1/halo_2").NDM==2001
def test_crosslinking(): cl = crosslink.CrossLinker() cl.parse_command_line(["dummy_sim_2","dummy_sim_1"]) with log.LogCapturer(): assert cl.need_crosslink_ts(db.get_timestep("dummy_sim_1/step.1"), db.get_timestep("dummy_sim_2/step.1")) cl.run_calculation_loop() assert not cl.need_crosslink_ts(db.get_timestep("dummy_sim_1/step.1"), db.get_timestep("dummy_sim_2/step.1")) assert db.get_halo('dummy_sim_1/step.1/1').calculate('match("dummy_sim_2").dbid()')==db.get_halo('dummy_sim_2/step.1/1').id assert db.get_halo('dummy_sim_2/step.2/3').calculate('match("dummy_sim_1").dbid()') == db.get_halo( 'dummy_sim_1/step.2/3').id with assert_raises(live_calculation.NoResultsError): result = db.get_halo('dummy_sim_2/step.3/1').calculate('match("dummy_sim_1").dbid()')
def setup_func(): parallel_tasks.use('null') testing.init_blank_db_for_testing() db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations") manager = add_simulation.SimulationAdderUpdater( output_testing.TestInputHandler("dummy_sim_1")) manager2 = add_simulation.SimulationAdderUpdater( output_testing.TestInputHandler("dummy_sim_2")) with log.LogCapturer(): manager.scan_simulation_and_add_all_descendants() manager2.scan_simulation_and_add_all_descendants() writer = property_writer.PropertyWriter() writer.parse_command_line(['dummy_property']) writer.run_calculation_loop()
def setup(): global output_manager, iord_expected_s960, iord_expected_s832 testing.init_blank_db_for_testing() db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations") output_manager = pynbody_outputs.ChangaInputHandler("test_tipsy") with log.LogCapturer(): add.SimulationAdderUpdater( output_manager).scan_simulation_and_add_all_descendants() h1 = db.get_halo("test_tipsy/%640/1").load() h1_sub = h1[::5] tracking.new("test_tipsy", h1_sub) iord_expected_s960 = copy.deepcopy(h1_sub['iord']) # because the tiny test files are downsampled, only a small number of particles are actually # in common between the two steps iord_expected_s832 = np.intersect1d( iord_expected_s960, db.get_timestep("test_tipsy/%832").load()['iord'])