示例#1
0
def test_reader_hnmr(hnmr_ethanol_file):
    with open(hnmr_ethanol_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert 'Ethanol' in jcamp_dict.get('title')
    assert jcamp_dict.get('data type') == "LINK"

    children = jcamp_dict.get('children')
    assert len(children) == jcamp_dict.get('blocks')

    atoms = children[0]
    assert 'atomlist' in atoms
    assert atoms.get('block_id') == 1

    assignments = children[1]
    assert assignments.get('block_id') == 2
    assert assignments.get('data type') == "NMR PEAK ASSIGNMENTS"
    assert assignments.get('data class') == "ASSIGNMENTS"

    peaks = children[2]
    assert peaks.get('block_id') == 3
    assert peaks.get('data type') == "NMR SPECTRUM"
    assert peaks.get('data class') == "PEAK TABLE"
    assert peaks.get(jcamp._DATA_XY_TYPE_KEY) == '(XY..XY)'

    xydata = children[3]
    assert xydata.get('block_id') == 4
    assert xydata.get('data type') == "NMR SPECTRUM"
    assert xydata.get('data class') == "XYDATA"
    assert xydata.get(jcamp._DATA_XY_TYPE_KEY) == '(X++(Y..Y))'
示例#2
0
def test_reader_raman(raman_tannic_acid_file):
    with open(raman_tannic_acid_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "tannic acid"
    assert jcamp_dict.get('data type') == "RAMAN SPECTRUM"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(XY..XY)'
示例#3
0
def test_reader_neutron(neutron_emodine_file):
    with open(neutron_emodine_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "Emodine, C15H10O4"
    assert jcamp_dict.get('data type') == "INELASTIC NEUTRON SCATTERING"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(X++(Y..Y))'
示例#4
0
def test_reader_infrared_multiline(infrared_multiline_file):
    with open(infrared_multiline_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "multiline datasets test"
    assert jcamp_dict.get('data type') == "INFRARED SPECTRUM"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(X++(Y..Y))'
示例#5
0
def test_reader_infrared_compressed(infrared_ethanol_compressed_file):
    with open(infrared_ethanol_compressed_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "$$ Begin of the data block"
    assert jcamp_dict.get('data type') == "INFRARED SPECTRUM"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(X++(Y..Y))'
示例#6
0
def test_reader_uvvis(uvvis_toluene_file):
    with open(uvvis_toluene_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "Toluene"
    assert jcamp_dict.get('data type') == "UV/VIS SPECTRUM"
    assert jcamp_dict.get('molform') == "C7H8"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(XY..XY)'
示例#7
0
def test_reader_mass(mass_ethanol_file):
    with open(mass_ethanol_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "ethanol"
    assert jcamp_dict.get('data type') == "MASS SPECTRUM"
    assert jcamp_dict.get('data class') == "PEAK TABLE"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(XY..XY)'
示例#8
0
def test_reader_infrared(infrared_ethanol_file):
    with open(infrared_ethanol_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == "ETHANOL"
    assert jcamp_dict.get('data type') == "INFRARED SPECTRUM"
    assert jcamp_dict.get('molform') == "C2 H6 O"
    assert jcamp_dict.get(jcamp._DATA_XY_TYPE_KEY) == '(X++(Y..Y))'
示例#9
0
def test_reader_exception_bad_datatype(tmp_path, infrared_ethanol_file):
    # Create a "bad type" tmp file
    jcamp_dir = tmp_path / "jcamp"
    jcamp_dir.mkdir()
    bad_file = jcamp_dir / "bad_data_type.jdx"

    # Read input file lines and modify XYDATA file to "bad type"
    with open(infrared_ethanol_file.resolve(), 'r') as fileobj:
        lines = fileobj.readlines()
        for i, line in enumerate(lines):
            if line.startswith("##XYDATA"):
                lines[i] = "##XYDATA=BAD_DATA_TYPE\n"

    # Read modified lines to the "bad type" tmp file
    with open(bad_file.resolve(), 'w') as fileobj:
        fileobj.writelines(lines)

    # Read in "bad file" for test
    with open(bad_file.resolve(), 'r') as fileobj:
        with pytest.raises(jcamp.UnsupportedDataTypeConfigException):
            jcamp._reader(fileobj)
示例#10
0
def test_reader_infrared_compound(infrared_compound_file):
    with open(infrared_compound_file.resolve(), 'r') as fileobj:
        jcamp_dict = jcamp._reader(fileobj)
    xy_minmax_checker(jcamp_dict)

    assert jcamp_dict.get('title') == ""
    assert jcamp_dict.get('data type') == "LINK"

    children = jcamp_dict.get('children')
    assert len(children) == jcamp_dict.get('blocks')

    for child in children:
        assert child.get('data type') == "INFRARED SPECTRUM"
        assert child.get(jcamp._DATA_XY_TYPE_KEY) == '(XY..XY)'