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))"
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
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)'])
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'
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))'
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'
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)))"
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']
def test_recursive_add(self): t = Tree('root', ['A', 'B']) t.get("B").add("sub", ["b1", "b2"]) assert str(t) == "(A,(b1,b2))"
def test_simple(self): t = Tree('root', ['A', 'B', 'C']) assert str(t) == "(A,B,C)"
def test_add(self): t = Tree('root', ['A', 'B']) t.add("C") assert str(t) == "(A,B,C)"
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))'
def test_singleton_tree(self): assert str(Tree("root")) == "root"
def test_repr(self): assert repr(Tree('a')) == "<Tree: a>"
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"
def test_eq(self): assert Tree("a") == Tree("a")
def test_gt(self): assert Tree("a") < Tree("b")
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)))))))))"
def test_empty_tree(self): assert str(Tree()) == ""
def test_simple(self): t = Tree('root', ['A', 'B', 'C'], show_nodelabels=True) assert str(t) == "(A,B,C)root"
def test_lt(self): assert Tree("b") > Tree("a")
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"