Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ pub struct TaxonomyIterator {

#[pymethods]
impl TaxonomyIterator {
fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
slf
}

fn __next__(mut slf: PyRefMut<Self>, py: Python<'_>) -> PyResult<Option<String>> {
let traverse_preorder = true;
loop {
Expand Down
16 changes: 13 additions & 3 deletions test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,16 @@ def test_json_internal_index(json_tax: Taxonomy):
] == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


def test_taxonomy_iterator_is_iterable(newick_tax):
it = iter(newick_tax)
assert iter(it) is it


def test_json_find_all_by_name(json_tax: Taxonomy):
assert sorted([n.id for n in json_tax.find_all_by_name("species 1.1")]) == ["10", "12"]
assert sorted([n.id for n in json_tax.find_all_by_name("species 1.1")]) == [
"10",
"12",
]


def test_json_edit_node_parent_updates_children(json_tax: Taxonomy):
Expand Down Expand Up @@ -475,7 +483,8 @@ def test_ncbi_edit_node_parent():
def test_ncbi_repr():
tax = Taxonomy.from_ncbi("tests/data/")
assert (
tax["562"].__repr__() == '<TaxonomyNode (id="562" rank="species" name="Escherichia coli")>'
tax["562"].__repr__()
== '<TaxonomyNode (id="562" rank="species" name="Escherichia coli")>'
)


Expand Down Expand Up @@ -511,7 +520,8 @@ def test_gtdb_invalid_format():


@pytest.mark.skipif(
not os.getenv("TAXONOMY_TEST_NCBI"), reason="Define TAXONOMY_TEST_NCBI to run NCBI test"
not os.getenv("TAXONOMY_TEST_NCBI"),
reason="Define TAXONOMY_TEST_NCBI to run NCBI test",
)
def test_latestncbi_load_latest_ncbi_taxonomy():
download("https://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz")
Expand Down
Loading