Exemplo n.º 1
0
 def test_get_or_create(self):
     t = Tree('root', ['A', 'B'])
     c = t.get_or_create("C")
     c.get_or_create("c1")
     c.get_or_create("c2")
     t.get("B").add('b1')
     assert str(t) == "(A,b1,(c1,c2))"
Exemplo n.º 2
0
 def test_is_tip(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert t.get("A").is_tip
     assert t.get("B").is_tip is False
     assert t.get("b1").is_tip
     assert t.get("b2").is_tip
Exemplo n.º 3
0
 def test_get_or_create(self):
     t = Tree('root', ['A', 'B'])
     c = t.get_or_create("C")
     c.get_or_create("c1")
     c.get_or_create("c2")
     t.get("B").add('b1')
     assert str(t) == "(A,b1,(c1,c2))"
Exemplo n.º 4
0
    def test_sanitise(self):
        with self.assertRaises(ValueError):
            Tree('a;', ['A', 'B'])

        with self.assertRaises(ValueError):
            Tree('a', ['A(', 'B'])

        with self.assertRaises(ValueError):
            Tree('a;', ['A', 'B)'])
Exemplo n.º 5
0
 def test_get(self):
     t = Tree('root', ['A', 'B', 'C'])
     c = t.get("C")
     c.add("c1")
     c.add("c2")
     t.get("B").add('b1')
     assert str(t) == "(A,b1,(c1,c2))"
     # try from different depths
     assert t.get('c1').node == 'c1'
     assert c.get('c1').node == 'c1'
Exemplo n.º 6
0
 def test_example(self):
     t = Tree('root')
     a = t.add("family a")
     a1 = a.add("subgroup 1")
     a1.add("A1")
     
     a2 = a.add("subgroup 2")
     a2.add("A2")
     
     b = t.add("family b")
     b1 = b.add("subgroup 1")
     b1.add("B1a")
     b1.add("B1b")
     
     b2 = b.add("subgroup 2")
     b2.add("B2")
     assert str(t) == '((A1,A2),((B1a,B1b),B2))'
Exemplo n.º 7
0
    def test_example(self):
        t = Tree('root')
        a = t.add("family a")
        a1 = a.add("subgroup 1")
        a1.add("A1")

        a2 = a.add("subgroup 2")
        a2.add("A2")

        b = t.add("family b")
        b1 = b.add("subgroup 1")
        b1.add("B1a")
        b1.add("B1b")

        b2 = b.add("subgroup 2")
        b2.add("B2")
        assert str(t) == '((A1,A2),((B1a,B1b),B2))'
Exemplo n.º 8
0
    def test_example(self):
        t = Tree('root', show_nodelabels=True)
        a = t.add("family a")
        a1 = a.add("subgroup 1")
        a1.add("A1")

        a2 = a.add("subgroup 2")
        a2.add("A2")

        b = t.add("family b")
        b1 = b.add("subgroup 1")
        b1.add("B1a")
        b1.add("B1b")

        b2 = b.add("subgroup 2")
        b2.add("B2")
        assert str(
            t) == '((A1,A2)family a,((B1a,B1b)subgroup 1,B2)family b)root'
Exemplo n.º 9
0
 def test_real(self):
     # yon  Trans-New Guinea, Ok-Awyu, Ok, Lowland
     # bhl  Trans-New Guinea, Ok-Awyu, Ok, Mountain
     # fai  Trans-New Guinea, Ok-Awyu, Ok, Mountain
     # yir  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Awyu
     # aax  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Dumut
     # bwp  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Dumut
     t = Tree("Ok-Awyu")
     
     Ok = t.add('Ok', ['Mountain', 'Lowland'])
     Ok.get('Lowland').add('yon')
     Ok.get('Mountain').add('bhl')
     Ok.get('Mountain').add('fai')
     
     AD = t.add('Awyu-Dumut', ['Awyu', 'Dumut'])
     AD.get('Awyu').add('yir')
     AD.get('Dumut').add('aax')
     AD.get('Dumut').add('bwp')
     assert str(t) == "((yir,(aax,bwp)),(yon,(bhl,fai)))"
Exemplo n.º 10
0
    def test_real(self):
        # yon  Trans-New Guinea, Ok-Awyu, Ok, Lowland
        # bhl  Trans-New Guinea, Ok-Awyu, Ok, Mountain
        # fai  Trans-New Guinea, Ok-Awyu, Ok, Mountain
        # yir  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Awyu
        # aax  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Dumut
        # bwp  Trans-New Guinea, Ok-Awyu, Awyu-Dumut, Dumut
        t = Tree("Ok-Awyu")

        Ok = t.add('Ok', ['Mountain', 'Lowland'])
        Ok.get('Lowland').add('yon')
        Ok.get('Mountain').add('bhl')
        Ok.get('Mountain').add('fai')

        AD = t.add('Awyu-Dumut', ['Awyu', 'Dumut'])
        AD.get('Awyu').add('yir')
        AD.get('Dumut').add('aax')
        AD.get('Dumut').add('bwp')
        assert str(t) == "((yir,(aax,bwp)),(yon,(bhl,fai)))"
Exemplo n.º 11
0
 def test_is_tip(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert t.get("A").is_tip
     assert t.get("B").is_tip is False
     assert t.get("b1").is_tip
     assert t.get("b2").is_tip
Exemplo n.º 12
0
 def test_get(self):
     t = Tree('root', ['A', 'B', 'C'])
     c = t.get("C")
     c.add("c1")
     c.add("c2")
     t.get("B").add('b1')
     assert str(t) == "(A,b1,(c1,c2))"
     # try from different depths
     assert t.get('c1').node == 'c1'
     assert c.get('c1').node == 'c1'
Exemplo n.º 13
0
 def test_tips(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert list([t.node for t in t.tips()]) == ['A', 'b1', 'b2']
Exemplo n.º 14
0
 def test_recursive_add(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert str(t) == "(A,(b1,b2))"
Exemplo n.º 15
0
 def test_simple(self):
     t = Tree('root', ['A', 'B', 'C'])
     assert str(t) == "(A,B,C)"
Exemplo n.º 16
0
 def test_add(self):
     t = Tree('root', ['A', 'B'])
     t.add("C")
     assert str(t) == "(A,B,C)"
Exemplo n.º 17
0
 def test_conflicts(self):
     t = Tree('root', ['A', 'B'])
     t.get("A").add("sub", ["b1", "b2"])
     t.get("B").add("sub", ["b1", "b2"])
     assert str(t) == '((b1,b2),(b1,b2))'
Exemplo n.º 18
0
 def test_singleton_tree(self):
     assert str(Tree("root")) == "root"
Exemplo n.º 19
0
 def test_repr(self):
     assert repr(Tree('a')) == "<Tree: a>"
Exemplo n.º 20
0
 def test_deep_tree(self):
     t = Tree('root', show_nodelabels=True)
     taxon = t
     for i in range(0, 10):
         taxon = taxon.add(i, [i])
     assert str(t) == "(0,(1,(2,(3,(4,(5,(6,(7,(8,9)8)7)6)5)4)3)2)1)0"
Exemplo n.º 21
0
 def test_eq(self):
     assert Tree("a") == Tree("a")
Exemplo n.º 22
0
 def test_conflicts(self):
     t = Tree('root', ['A', 'B'])
     t.get("A").add("sub", ["b1", "b2"])
     t.get("B").add("sub", ["b1", "b2"])
     assert str(t) == '((b1,b2),(b1,b2))'
Exemplo n.º 23
0
 def test_add(self):
     t = Tree('root', ['A', 'B'])
     t.add("C")
     assert str(t) == "(A,B,C)"
Exemplo n.º 24
0
 def test_gt(self):
     assert Tree("a") < Tree("b")
Exemplo n.º 25
0
 def test_deep_tree(self):
     t = Tree('root')
     taxon = t
     for i in range(0, 10):
         taxon = taxon.add(i, [i])
     assert str(t) == "(0,(1,(2,(3,(4,(5,(6,(7,(8,9)))))))))"
Exemplo n.º 26
0
 def test_recursive_add(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert str(t) == "(A,(b1,b2))"
Exemplo n.º 27
0
 def test_empty_tree(self):
     assert str(Tree()) == ""
Exemplo n.º 28
0
 def test_simple(self):
     t = Tree('root', ['A', 'B', 'C'], show_nodelabels=True)
     assert str(t) == "(A,B,C)root"
Exemplo n.º 29
0
 def test_lt(self):
     assert Tree("b") > Tree("a")
Exemplo n.º 30
0
 def test_tips(self):
     t = Tree('root', ['A', 'B'])
     t.get("B").add("sub", ["b1", "b2"])
     assert list([t.node for t in t.tips()]) == ['A', 'b1', 'b2']
Exemplo n.º 31
0
 def test_recursive_add(self):
     t = Tree('root', ['A', 'B'], show_nodelabels=True)
     t.get("B").add("sub", ["b1", "b2"])
     assert str(t) == "(A,(b1,b2)sub)root"