Ejemplo n.º 1
0
def test_extra_value(recwarn):
    extra_data = '''version: 1
lattice:
    name: bNaYF4
    N_uc: 8
    # concentration
    S_conc: 0.3
    A_conc: 0.3
    # unit cell
    # distances in Angstrom
    a: 5.9738
    b: 5.9738
    c: 3.5297
    # angles in degree
    alpha: 90
    beta: 90
    gamma: 120
    # the number is also ok for the spacegroup
    spacegroup: P-6
    # info about sites
    sites_pos: [[0, 0, 0], [2/3, 1/3, 1/2]]
    sites_occ: [1, 1/2]
    extra_value: 3
states:
    sensitizer_ion_label: Yb
    sensitizer_states_labels: [GS, ES]
    activator_ion_label: Tm
    activator_states_labels: [3H6, 3F4, 3H5, 3H4, 3F3, 1G4, 1D2]
excitations:
    Vis_473:
        active: True
        power_dens: 1e6 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: Tm(3H6) -> Tm(1G4) # both ion labels are required
        degeneracy: 13/9
        pump_rate: 9.3e-4 # cm2/J
sensitizer_decay:
# lifetimes in s
    ES: 2.5e-3
activator_decay:
# lifetimes in s
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
sensitizer_branching_ratios:
activator_branching_ratios:
'''
    with pytest.warns(
            settings.ConfigWarning):  # "extra_value" in lattice section
        with temp_filename(extra_data) as filename:
            settings.load(filename)
    assert len(recwarn) == 1  # one warning
    warning = recwarn.pop(settings.ConfigWarning)
    assert issubclass(warning.category, settings.ConfigWarning)
    assert 'Some values or sections should not be present in the file.' in str(
        warning.message)
Ejemplo n.º 2
0
def test_duplicate_key(settings_dict):
    data = '''key1: 5
key1: 10
'''
    with pytest.raises(SettingsValueError) as excinfo:
        with temp_filename(data) as filename:
            settings.Settings(settings_dict).validate(filename)
    assert excinfo.match(r"Duplicate label")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 3
0
def test_extra_value(settings_dict):
    extra_data = '''version: 1
extra: 3
'''
    with pytest.warns(SettingsExtraValueWarning
                      ) as record:  # "extra_value" in lattice section
        with temp_filename(extra_data) as filename:
            settings.Settings({
                'version': settings_dict['version']
            }).validate(filename)
    assert len(record) == 2  # one warning
    warning = record.pop(SettingsExtraValueWarning)
    assert warning.category == SettingsExtraValueWarning
    assert 'Some values or sections should not be present in the file' in str(
        warning.message)
Ejemplo n.º 4
0
def test_missing_value(settings_dict):
    ''''Test that missing values raise errors.'''
    orig_filename = os.path.join(test_folder_path, 'test_standard_config.txt')
    with open(orig_filename) as file:
        file_text = file.read()
    # remove the version section
    file_text = file_text.replace('version: 1', '')

    sett = settings.Settings(settings_dict)

    with temp_filename(file_text) as filename:
        with pytest.raises(SettingsFileError) as excinfo:
            sett.validate(filename)
    assert excinfo.match(
        r'Sections that are needed but not present in the file')
    assert excinfo.type == SettingsFileError
Ejemplo n.º 5
0
def test_not_dict_config(settings_dict):
    with pytest.raises(SettingsFileError) as excinfo:
        with temp_filename('vers') as filename:
            settings.Settings(settings_dict).validate(filename)
    assert excinfo.match(r"The settings file is empty or otherwise invalid")
    assert excinfo.type == SettingsFileError
Ejemplo n.º 6
0
def test_yaml_error_config(bad_yaml_data, settings_dict):
    with pytest.raises(SettingsFileError) as excinfo:
        with temp_filename(bad_yaml_data) as filename:
            settings.Settings(settings_dict).validate(filename)
    assert excinfo.match(r"Error while parsing the config file")
    assert excinfo.type == SettingsFileError
Ejemplo n.º 7
0
def test_not_dict_config():
    with pytest.raises(settings.ConfigError) as excinfo:
        with temp_filename('vers') as filename:
            settings.load(filename)
    assert excinfo.match(r"The settings file is empty or otherwise invalid")
    assert excinfo.type == settings.ConfigError
Ejemplo n.º 8
0
def test_yaml_error_config(bad_yaml_data):
    with pytest.raises(settings.ConfigError) as excinfo:
        with temp_filename(bad_yaml_data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Error while parsing the config file")
    assert excinfo.type == settings.ConfigError
Ejemplo n.º 9
0
def test_version_config():
    with pytest.raises(settings.ConfigError) as excinfo:
        with temp_filename('version: 2') as filename:
            settings.load(filename)
    assert excinfo.match(r"Version number must be 1!")
    assert excinfo.type == settings.ConfigError