jpayne@4: import pytest jpayne@4: jpayne@4: from bio2srr import * jpayne@4: jpayne@4: jpayne@4: def test_element_tree_xpath(): jpayne@4: from xml.etree import ElementTree as xml jpayne@4: root = xml.fromstring(biosample_example) jpayne@4: assert root.find(".//Id[@db='BioSample']") is not None jpayne@4: jpayne@4: def test_flatten_biosample_xml(): jpayne@4: d = flatten_biosample_xml(biosample_example) jpayne@4: assert d['biosample_accession'] == 'SAMN17131268' jpayne@4: assert d['organism'] == 'Campylobacter jejuni' jpayne@4: assert d['isolate'] == 'CFSAN091032' jpayne@4: jpayne@4: def test_flatten_runs(): jpayne@4: d = list(flatten_runs(runs_example)) jpayne@4: assert len(d) == 2 jpayne@4: jpayne@4: def test_header_sort_override_consistency(): jpayne@4: import random jpayne@4: L = ["C", "B", "A", "taxid", "bioproject"] jpayne@4: L.sort(key=hso) jpayne@4: # assert L[0] == "bioproject" jpayne@4: A = L.copy() jpayne@4: assert A == L jpayne@4: R = [] jpayne@4: for _ in range(100): jpayne@4: random.shuffle(A) jpayne@4: A.sort(key=hso) jpayne@4: R.append(A == L) jpayne@4: assert all(R) jpayne@4: jpayne@4: def test_hso_override(): jpayne@4: assert header_sort_override("bioproject", "taxid") < 0 jpayne@4: assert header_sort_override("taxid", "bioproject") > 0 jpayne@4: assert header_sort_override("taxid", "taxid") == 0 jpayne@4: jpayne@4: def test_hso_regular(): jpayne@4: assert header_sort_override("A", "B") < 0 jpayne@4: assert header_sort_override("B", "A") > 0