def test_valdshortline(): """Test code paths and cases in vald.ValdShortLine(). """ for vslstr in vald_short_line_strings: vsl = ValdShortLine(vslstr) assert isinstance(vsl, ValdShortLine) assert vsl.__str__() == vslstr assert vsl.__repr__() == type(vsl).__name__ + f'({vslstr!r})'
def test_smeline(): """Test code paths and cases in vald.SmeLine(). """ line = SmeLine('H 1', '6564.61', '10.20', '0.71', '8.766', '2', '3') for vslstr in vald_short_line_strings: # Pass various VALD short line (vsl) strings to __init__(). vsl = ValdShortLine(vslstr) line = SmeLine(vsl.species, vsl.wlcent, vsl.excit, vsl.loggf, vsl.gamrad, vsl.gamqst, vsl.gamvw) assert isinstance(line, SmeLine) # __init__() argument order maps to properties as expected. assert line.species == vsl.species assert line.wlcent == vsl.wlcent assert line.excit == vsl.excit assert line.loggf == vsl.loggf assert line.gamrad == vsl.gamrad assert line.gamqst == vsl.gamqst assert line.gamvw == vsl.gamvw # eval(repr()) yields equal result according to __eq__(). line2 = eval(repr(line)) assert line == line2 # __eq__() yields False when value of a property differs. line2.excit += 0.1 assert not line == line2 # __eq__() yields False when type of other object is not SmeLine. assert not line == ''
def test_valdshortref(): """Test code paths and cases in vald.ValdShortRef(). """ for vslstr in vald_short_line_strings: vsr = ValdShortLine(vslstr).ref datastr, refstr = vslstr.strip().split(", '") refs = refstr.split()[1::2] assert isinstance(vsr, ValdShortRef) assert refs[0] in [vsr.wlcent, 'wl:' + vsr.wlcent] assert refs[1] == vsr.excit assert refs[2] in [vsr.loggf, 'gf:' + vsr.loggf] assert refs[3] == vsr.gamrad assert refs[4] == vsr.gamqst assert refs[5] == vsr.gamvw assert refs[6] == vsr.lande_mean with raises(ValdFileError, match='expected 15 words'): vsr = ValdShortLine(datastr + ", 'invalid reference string'")
def test_linelist(): """Test code paths and cases in vald.LineList(). """ # __init__() creates a LineList with 0 lines. linelist = LineList() assert isinstance(linelist, LineList) assert len(linelist) == 0 inputs = [] for iline, vslstr in enumerate(vald_short_line_strings): assert len(linelist) == iline vsl = ValdShortLine(vslstr) inputs.append(vsl) # Append SmeLine and ValdShortLine objects (add ValdLongLine). # __getitem__() returns the object just appended. if iline % 2 == 0: linelist.append(vsl) assert linelist[iline] == vsl else: smeline = SmeLine(vsl.species, vsl.wlcent, vsl.excit, vsl.loggf, vsl.gamrad, vsl.gamqst, vsl.gamvw) linelist.append(smeline) assert linelist[iline] == smeline # __len__() returns number of appended lines. assert len(linelist) == len(vald_short_line_strings) # Exercise __str__() to make sure it returns a value. assert type(str(linelist)) is str # Properties return lists of values equal to the input values. assert isinstance(linelist.species, list) assert len(linelist.species) == len(vald_short_line_strings) assert linelist.species == [line.species for line in inputs] assert linelist.wlcent == [line.wlcent for line in inputs] assert linelist.excit == [line.excit for line in inputs] assert linelist.loggf == [line.loggf for line in inputs] assert linelist.gamrad == [line.gamrad for line in inputs] assert linelist.gamqst == [line.gamqst for line in inputs] assert linelist.gamvw == [line.gamvw for line in inputs] # Exceptions with raises(TypeError, match='line in LineList has invalid type'): linelist[0] = 'invalid type' with raises(TypeError, match='line in LineList has invalid type'): linelist.append('invalid type')
def _make_linelist(index, delta_loggf=None): """Make a line list for use in tests. """ vald_short_line_strings = [ "'Ti 1', 6554.2230, 1.4432, 1.0, -1.150, 7.870,-6.070," " 284.261, 1.070, 0.606, ' 9 wl:LGWSC 9 LGWSC 9 gf:LGWSC" " 7 K10 7 K10 7 K10 10 BPM Ti '", "'MgH 1', 6556.8086, 0.9240, 1.0, -0.867, 7.060, 0.000," " 0.000, 99.000, 0.021, ' 12 KMGH 12 KMGH 12 KMGH" " 12 KMGH 12 KMGH 12 KMGH 12 KMGH (24)MgH '" ] linelist = LineList() for i in index: vsl = ValdShortLine(vald_short_line_strings[i]) if delta_loggf: vsl.loggf += delta_loggf linelist.append(vsl) return (linelist)
def test_basic(): libsme = LibSme() print(libsme.SMELibraryVersion()) libsme.InputWaveRange(5000, 6000) libsme.SetVWscale(2.5) libsme.SetH2broad() vald_short_line_strings = [ "'Ti 1', 6554.2230, 1.4432, 1.0, -1.150, 7.870,-6.070," " 284.261, 1.070, 0.606, ' 9 wl:LGWSC 9 LGWSC 9 gf:LGWSC" " 7 K10 7 K10 7 K10 10 BPM Ti '", "'MgH 1', 6556.8086, 0.9240, 1.0, -0.867, 7.060, 0.000," " 0.000, 99.000, 0.021, ' 12 KMGH 12 KMGH 12 KMGH" " 12 KMGH 12 KMGH 12 KMGH 12 KMGH (24)MgH '" ] linelist = LineList() for vsl in vald_short_line_strings: linelist.append(ValdShortLine(vsl)) libsme.InputLineList(linelist) outlist = libsme.OutputLineList() print( libsme.file, libsme.wfirst, libsme.wlast, libsme.vw_scale, libsme.H2broad ) print(libsme.linelist) fmt = " Out: {0:10.4f},{2:7.4f},{1:7.3f},{3:5.2f},{4:6.2f},{5:8.3f}" for i in range(len(linelist)): outline = [x for x in outlist[i]] outline[1] = log10(outline[1]) print(fmt.format(*outline))