Exemplo n.º 1
0
def test_ET_config_duplicate_ET_labels():
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Tm(1G4) + Tm(3H6) -> Yb(3H4) + Tm(3H5)
        multipolarity: 6
        strength: 8.87920884e+08
    CR50:
        process: Yb(ES) + Tm(3H6) -> Yb(GS) + Tm(3H5)
        multipolarity: 8
        strength: 1e3
'''
    with pytest.raises(SettingsValueError) as excinfo: # duplicate labels
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Duplicate label")
    assert excinfo.type == SettingsValueError
Exemplo n.º 2
0
def test_lattice_radius():
    data = data_lattice_full + '''states:
    asd: dsa
excitations:
        asd: dsa
sensitizer_decay:
        asd: dsa
activator_decay:
        asd: dsa'''
    data = data.replace('N_uc: 8', 'radius: 100.0')
    with pytest.raises(SettingsValueError) as excinfo: # ok, error later
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'Error validating section "states"')
    assert excinfo.match(r'"sensitizer_ion_label" not in dictionary')
    assert excinfo.type == SettingsValueError
Exemplo n.º 3
0
def test_branch_config_value_above_1():
    data = data_decay_ok + '''
activator_branching_ratios:
    3H5->3F4: 1.4
    3H4->3F4: 0.3
    3F3->3H4: 0.999
    1G4->3F4: 0.15
    1G4->3H5: 0.16
    1G4->3H4: 0.04
    1G4->3F3: 0.00
    1D2->3F4: 0.43
'''
    with pytest.raises(SettingsValueError) as excinfo: # value above 1.0
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'cannot be larger than 1')
    assert excinfo.type == SettingsValueError
Exemplo n.º 4
0
def test_branch_config_wrong_label():
    data = data_decay_ok + '''
activator_branching_ratios:
    3H->3F4: 0.4
    3H4->3F4: 0.3
    3F3->3H4: 0.999
    1G4->3F4: 0.15
    1G4->3H5: 0.16
    1G4->3H4: 0.04
    1G4->3F3: 0.00
    1D2->3F4: 0.43
'''
    with pytest.raises(settings.LabelError) as excinfo: # wrong state label
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"is not a valid state label")
    assert excinfo.type == settings.LabelError
Exemplo n.º 5
0
def test_decay_missing_A_state():
    data = data_abs_ok + '''sensitizer_decay:
# lifetimes in s
    ES: 1e-3

activator_decay:
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
'''
    with pytest.raises(SettingsValueError) as excinfo: # 1D2 state missing
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"All activator states must have a decay rate")
    assert excinfo.type == SettingsValueError
Exemplo n.º 6
0
def test_decay_ok():
    data = data_abs_ok + '''sensitizer_decay:
# lifetimes in s
    ES: dsa

activator_decay:
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
'''
    with pytest.raises(SettingsValueError) as excinfo: # decay rate is string
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Exemplo n.º 7
0
def test_decay_config5():
    data = data_abs_ok + '''sensitizer_decay:
# lifetimes in s
    ES: 1e-3

activator_decay:
# lifetimes in s
    34: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
'''
    with pytest.raises(settings.LabelError) as excinfo: # wrong state label
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"is not a valid state label")
    assert excinfo.type == settings.LabelError
Exemplo n.º 8
0
def test_decay_missing_S_state():
    data = data_abs_ok + '''sensitizer_decay:
    1ES: 2e-3

activator_decay:
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
'''
    data = data.replace('sensitizer_states_labels: [GS, ES]',
                        'sensitizer_states_labels: [GS, 1ES, 2ES]')
    with pytest.raises(SettingsValueError) as excinfo: # 2ES state missing
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"All sensitizer states must have a decay rate")
    assert excinfo.type == SettingsValueError
Exemplo n.º 9
0
def test_sim_steady1(setup_cte_sim):
    '''Test that the steady state solution is saved a loaded correctly'''
    setup_cte_sim['excitations']['Vis_473'][0].t_pulse = 1e-08
    with temp_bin_filename() as temp_filename:
        sim = simulations.Simulations(setup_cte_sim, full_path=temp_filename)
        assert sim.cte == setup_cte_sim
        solution = sim.simulate_steady_state()
        assert solution

    solution.log_populations()
    solution.plot()
    solution.log_populations()  # redo

    with temp_config_filename('') as filename:
        solution.save(filename)
        sol_hdf5 = simulations.SteadyStateSolution.load(filename)

    assert sol_hdf5
    assert sol_hdf5 == solution
    sol_hdf5.plot()
    plotter.plt.close('all')
Exemplo n.º 10
0
def test_lattice_config(lattice_values):
    data_format = data_lattice.format(*lattice_values)
    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data_format) as filename:
            settings.load(filename)
    assert excinfo.type == SettingsValueError
Exemplo n.º 11
0
def test_not_dict_config():
    with pytest.raises(SettingsFileError) as excinfo:
        with temp_config_filename('vers') as filename:
            settings.load(filename)
    assert excinfo.match(r"The settings file is empty or otherwise invalid")
    assert excinfo.type == SettingsFileError
Exemplo n.º 12
0
def test_yaml_error_config(bad_yaml_data):
    with pytest.raises(SettingsFileError) as excinfo:
        with temp_config_filename(bad_yaml_data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Error while parsing the config file")
    assert excinfo.type == SettingsFileError
Exemplo n.º 13
0
def test_conc_dep_config2(): # not present
    data = data_ET_ok + ''''''

    with temp_config_filename(data) as filename:
        cte = settings.load(filename)
        assert 'concentration_dependence' not in cte
Exemplo n.º 14
0
def load_from_text(text_data: str) -> Settings:
    '''Creates a new Settings instance and loads the configuration file.
        Returns the Settings instance (dict-like).'''
    with temp_config_filename(text_data) as filename:
        settings = load_file(filename)
    return settings