def test_file_prune(): lines = fileinput.input("tests/treefiles/basic.trees") trees = NewickParser().consume(lines) pruned = Prune(filename="tests/argfiles/taxa_abc.txt").consume(trees) for t in pruned: leaves = t.get_leaf_names() assert not any((x in leaves for x in ("A", "B", "C")))
def test_inverse_annotation_prune(basictrees): annotated = Annotate(filename="tests/argfiles/annotation.csv", key="taxon").consume(basictrees) pruned = Prune(attribute="f1", values="0", inverse=True).consume(annotated) for t in pruned: leaves = t.get_leaf_names() assert all((x in leaves for x in ("A", "B", "C"))) assert not any ((x in leaves for x in ("D", "E", "F")))
def test_annotation_prune(): lines = fileinput.input("tests/treefiles/basic.trees") trees = NewickParser().consume(lines) annotated = Annotate(filename="tests/argfiles/annotation.csv", key="taxon").consume(trees) pruned = Prune(attribute="f1", value="0").consume(annotated) for t in pruned: leaves = t.get_leaf_names() assert not any((x in leaves for x in ("A", "B", "C")))
def test_inverse_prune(): lines = fileinput.input("tests/treefiles/basic.trees") trees = NewickParser().consume(lines) pruned = Prune(["A", "B"], inverse=True).consume(trees) for t in pruned: leaves = t.get_leaf_names() assert all((x in leaves for x in ("A", "B"))) assert not any((x in leaves for x in ("C", "D", "E", "F")))
def test_prune(): lines = fileinput.input("tests/treefiles/basic.trees") trees = NewickParser().consume(lines) pruned = Prune(["A"]).consume(trees) for t in pruned: leaves = t.get_leaf_names() assert "A" not in leaves assert all((x in leaves for x in ("B", "C", "D", "E", "F")))
def test_bad_init_no_args(): with pytest.raises(ValueError): Prune()
def test_bad_init_no_value_only(): with pytest.raises(ValueError): Prune(value="bar")
def test_bad_init_empty_file(): Prune(filename="tests/argfiles/empty.txt")
def test_bad_init_no_attribute_only(): Prune(attribute="foo")
def test_bad_init_no_value_only(): Prune(value="bar")
def test_bad_init_no_attribute_only(): with pytest.raises(ValueError): Prune(attribute="foo")
def test_bad_init_no_args(): Prune()
def test_annotation_prune(basictrees, argfilepath): annotated = Annotate(filename=argfilepath("annotation.csv"), key="taxon").consume(basictrees) pruned = Prune(attribute="f1", values="0").consume(annotated) for t in pruned: leaves = t.get_leaf_names() assert not any((x in leaves for x in ("A", "B", "C")))
def test_file_prune(basictrees): pruned = Prune(filename="tests/argfiles/taxa_abc.txt").consume(basictrees) for t in pruned: leaves = t.get_leaf_names() assert not any((x in leaves for x in ("A", "B", "C")))
def test_inverse_prune(basictrees): pruned = Prune(taxa=["A", "B"], inverse=True).consume(basictrees) for t in pruned: leaves = t.get_leaf_names() assert all((x in leaves for x in ("A", "B"))) assert not any((x in leaves for x in ("C", "D", "E", "F")))
def test_prune(basictrees): pruned = Prune(taxa=["A"]).consume(basictrees) for t in pruned: leaves = t.get_leaf_names() assert "A" not in leaves assert all((x in leaves for x in ("B", "C", "D", "E", "F")))
def test_bad_init_empty_file(emptyargs): with pytest.raises(ValueError): Prune(filename=emptyargs)