File: test_validate_export.py

package info (click to toggle)
augur 24.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,312 kB
  • sloc: python: 14,253; sh: 227; makefile: 35
file content (30 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Bio.Phylo
from io import StringIO
from pathlib import Path
import pytest
import sys

# we assume (and assert) that this script is running from the tests/ directory
sys.path.append(str(Path(__file__).parent.parent.parent))

from augur.export_v2 import convert_tree_to_json_structure
from augur.validate import ValidateError
from augur.validate_export import ensure_no_duplicate_names


class TestValidateExport():
    def test_export_without_duplicate_names(self):
        # Create a tree with unique tip names.
        tree = Bio.Phylo.read(StringIO("root(A, internal(B, C))"), "newick")
        metadata = {"A": {}, "B": {}, "C": {}, "root": {}, "internal": {}}
        root = convert_tree_to_json_structure(tree.root, metadata, None)
        ensure_no_duplicate_names(root, ValidateError)

    def test_export_with_duplicate_names(self):
        # Create a tree with duplicate tip names.
        tree = Bio.Phylo.read(StringIO("root(A, internal(B, B))"), "newick")
        metadata = {"A": {}, "B": {}, "root": {}, "internal": {}}
        root = convert_tree_to_json_structure(tree.root, metadata, None)

        with pytest.raises(ValidateError):
            ensure_no_duplicate_names(root, ValidateError)