def test_validate_with_yield_corrections(): params = settings.validate( {"yield_corrections": { "Mg": 3, "Aluminium": 4 }}) assert (params["yield_corrections"]) == {"Mg": 3}
def test_model_is_configured_properly(mocker, deactivate_os_actions, mock_config_file): argparse.ArgumentParser.parse_args.return_value = argparse.Namespace( generate_config=False, config='ejectas.dat') cli.main() expected_context = settings.validate(mock_config_file) model.Model.assert_called_once_with(expected_context) model.Model(expected_context).run.assert_called()
def test_validate_mass_limits_for_starburst_imf(): for imf in settings.valid_values["imf"]: params = settings.validate({ "imf": imf, "imf_m_low": 7, "imf_m_up": 40 }) if imf == "starburst": assert params["imf_m_low"] == 1 assert params["imf_m_up"] == 120 else: assert params["imf_m_low"] == 7 assert params["imf_m_up"] == 40
def test_explosive_nucleosynthesis_with_two_steps_t(mocker, deactivate_open_files): mocker.spy(Model, "explosive_nucleosynthesis_step_t") mocker.spy(Model, "explosive_nucleosynthesis_step_logt") mocker.spy(Model, "explosive_nucleosynthesis_two_steps_t") mocker.spy(Model, "explosive_nucleosynthesis_fixed_n_steps") model = Model(settings.validate({"integration_step": "two_steps_t"})) model.explosive_nucleosynthesis() Model.explosive_nucleosynthesis_two_steps_t.assert_called_once() Model.explosive_nucleosynthesis_step_t.assert_not_called() Model.explosive_nucleosynthesis_step_logt.assert_not_called() Model.explosive_nucleosynthesis_fixed_n_steps.assert_not_called()
def test_validate_with_invalid_values(): invalid_values = { "imf": "wrong name", "dtd_sn": "whatever", "sol_ab": "invalid", "sn_yields": "incorrect", "m_max": 3.3 } params = settings.validate(invalid_values) for param in ["imf", "dtd_sn", "sol_ab", "sn_yields"]: assert params[param] != invalid_values[param] assert params[param] == settings.default[param]
def test_explosive_nucleosynthesis_with_fixed_n_steps(mocker, deactivate_open_files): mocker.spy(Model, "explosive_nucleosynthesis_step_t") mocker.spy(Model, "explosive_nucleosynthesis_step_logt") mocker.spy(Model, "explosive_nucleosynthesis_two_steps_t") mocker.spy(Model, "explosive_nucleosynthesis_fixed_n_steps") model = Model(settings.validate({"integration_step": "fixed_n_steps", "integration_steps_stars_smaller_than_4Msun": 100, "integration_steps_stars_bigger_than_4Msun": 200})) model.explosive_nucleosynthesis() Model.explosive_nucleosynthesis_fixed_n_steps.assert_called_once_with(model, 200, 100) Model.explosive_nucleosynthesis_two_steps_t.assert_not_called() Model.explosive_nucleosynthesis_step_t.assert_not_called() Model.explosive_nucleosynthesis_step_logt.assert_not_called()
def test_validate_with_valid_values(): valid_values = { "z": 0.033, "imf": "miller_scalo", "imf_m_low": 0.3, "dtd_sn": "castrillo", "sol_ab": "ag89", "sn_yields": "iwa1998", "m_max": 40.0, "output_dir": "testing" } params = settings.validate(valid_values) for param in [ "z", "imf", "imf_m_low", "dtd_sn", "sol_ab", "m_max", "output_dir" ]: assert params[param] == valid_values[param]
def main(): parser = argparse.ArgumentParser( prog="starmatrix", description="Command line tools for the Starmatrix Python library.", epilog="Another dimension, new Galaxy!", ) parser.add_argument("-v", "--version", action="version", version=starmatrix.__version__) parser.add_argument( "--config", metavar="FILENAME", help="configuration file to use containing model initial params") parser.add_argument("--generate-config", action="store_true", help="create a config.yml example file") args = parser.parse_args() if args.generate_config: return create_template_config_file() input_params = {} if args.config is not None: input_params = read_config_file(args.config) context = settings.validate(input_params) print("Running model with settings:") print("") for param in context: print(" " + str(param) + " = " + str(context[param])) print("") create_output_directory(context['output_dir']) model.Model(context).run() print(f"Done. Output files ready in '{context['output_dir']}' directory.")
def test_model_initialization(): params = { "z": 0.033, "sol_ab": "ag89", "imf": "chabrier", "m_min": 1.1, "m_max": 42.0, "total_time_steps": 250, "dtd_sn": "greggio" } validated_params = settings.validate(params) model = Model(validated_params) assert isinstance(model.initial_mass_function, imfs.Chabrier) assert isinstance(model.context["abundances"], abundances.AndersGrevesse1989) assert model.context["abundances"].z == params["z"] assert model.mass_intervals == [] assert model.energies == [] assert model.sn_Ia_rates == [] assert model.z == params["z"] assert model.dtd == dtds.dtd_greggio assert model.m_min == params["m_min"] assert model.m_max == params["m_max"] assert model.total_time_steps == params["total_time_steps"]
def test_validate_max_mass_with_invalid_values(): for z in [0.001, 0.008, 0.2, 0.33, 0.5]: params = settings.validate({"m_max": 300, "z": z}) assert params["m_max"] == max_mass_allowed(z)
def test_validate_max_mass_with_valid_values(): params = settings.validate({"m_max": 33}) assert params["m_max"] == 33
def test_validate_with_invalid_settings(): params = settings.validate({"imf_m_low": 7, "invalid_setting": 47}) assert (params["imf_m_low"]) == 7 assert ("invalid_setting" in params) is False