def test_msp_empty(empty_msp, ignore_unknown, read_msp_f): """An empty msp file should not throw an error but yield an empty list """ data = list(read_msp_f(str(empty_msp), ignore_unknown=ignore_unknown)) assert isinstance(data, list) assert len(data) == 0
def test_msp_pepmass(valid_msp, ignore_unknown, read_msp_f): """`read` should return the same *m/z* values than the ones written in msp. """ mzs, _, p = valid_msp gen = read_msp_f(str(p), ignore_unknown=ignore_unknown) for i, (params, _) in enumerate(gen): assert pytest.approx(params['precursormz']) == mzs[i]
def test_msp_data(valid_msp, ignore_unknown, read_msp_f): """`read` should return the same data arrays than the ones written in msp. """ _, spectra, p = valid_msp gen = read_msp_f(str(p), ignore_unknown=ignore_unknown) for i, (_, data) in enumerate(gen): assert pytest.approx(data) == spectra[i]
def test_msp_invalid(invalid_msp, ignore_unknown, read_msp_f): """Invalid precursormz declaration should be ignored. """ _, _, p = invalid_msp gen = read_msp_f(str(p), ignore_unknown=ignore_unknown) for i, (params, data) in enumerate(gen): if i == 2: assert 'precursormz' not in params
def test_msp_wrongfloat(invalid_msp, read_msp_f): """Characters after a float value should be ignored and not raise any error. """ mzs, _, p = invalid_msp data = list(read_msp_f(str(p), ignore_unknown=True)) assert len(data) == len(mzs) for i, (params, d) in enumerate(data): assert pytest.approx(params['precursormz']) == mzs[i]
def test_msp_noions(noions_msp, ignore_unknown, read_msp_f): """A msp file with only one entry where there is no ions should not throw an error. """ data = list(read_msp_f(str(noions_msp), ignore_unknown=ignore_unknown)) assert isinstance(data, list) assert len(data) == 1 assert data[0][1].size == 0 assert data[0][1].shape == (0, 2)
def test_msp_nonumpeaks(invalid_msp, ignore_unknown, read_msp_f): """Entries where num peaks field is missing should be ignored. """ mzs, _, p = invalid_msp data = list(read_msp_f(str(p), ignore_unknown=ignore_unknown)) assert len(data) == len(mzs) - 1 for i, (params, d) in enumerate(data): if i < 2: assert pytest.approx(params['precursormz']) == mzs[i] else: assert pytest.approx(params['precursormz']) == mzs[i+1]
def test_msp_twonames(invalid_msp, read_msp_f): """If two names sections, the spectrum will be ignored """ mzs, _, p = invalid_msp data = list(read_msp_f(str(p), ignore_unknown=True)) assert len(data) == len(mzs) - 1 for i, (params, d) in enumerate(data): if i < 2: assert pytest.approx(params['precursormz']) == mzs[i] else: assert pytest.approx(params['precursormz']) == mzs[i+1]
def test_msp_mz_zero(invalid_msp, read_msp_f): """A peak with an mz equal to zero should be ignored.""" mzs, spectra, p = invalid_msp data = list(read_msp_f(str(p), ignore_unknown=True)) assert len(data) == len(mzs) for i, (params, d) in enumerate(data): if i == 2: assert len(d) == len(spectra[i]) - 1 assert pytest.approx(d) == spectra[i][1:] else: assert len(d) == len(spectra[i]) assert pytest.approx(d) == spectra[i]
def test_msp_numpeakszero(invalid_msp, ignore_unknown, read_msp_f): """Entries where num peaks field is zero should be not have peaks """ mzs, spectra, p = invalid_msp data = list(read_msp_f(str(p), ignore_unknown=ignore_unknown)) assert len(data) == len(mzs) for i, (params, d) in enumerate(data): assert pytest.approx(params['precursormz']) == mzs[i] if i == 2: assert len(d) == 0 else: assert len(d) == len(spectra[i])
def test_msp_non_existing(filename, ignore_unknown, read_msp_f): """A filename that does not exists should throw a FileNotFoundError """ with pytest.raises(FileNotFoundError): data = list(read_msp_f(filename, ignore_unknown=ignore_unknown))