Skip to content

Commit 07dd054

Browse files
committed
More testing of prior classes and functions
1 parent b7ec883 commit 07dd054

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_priors.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@
2222
"""
2323
Test cases for prior functionality used in tsdate
2424
"""
25+
import logging
26+
27+
import pytest
28+
import utility_functions
29+
2530
from tsdate.prior import ConditionalCoalescentTimes
31+
from tsdate.prior import create_timepoints
2632
from tsdate.prior import PriorParams
33+
from tsdate.prior import SpansBySamples
2734

2835

2936
class TestConditionalCoalescentTimes:
@@ -43,3 +50,41 @@ def test_str(self):
4350
for i, line in enumerate(lines[2:]):
4451
assert line.startswith(f" {i} descendants")
4552
assert line.endswith("]")
53+
54+
def test_add_error(self):
55+
priors = ConditionalCoalescentTimes(None, "gamma")
56+
with pytest.raises(RuntimeError, match="cannot add"):
57+
priors.add(2, approximate=True)
58+
59+
def test_clear_precalc_debug(self, caplog):
60+
priors = ConditionalCoalescentTimes(None, "gamma")
61+
caplog.set_level(logging.DEBUG)
62+
priors.clear_precalculated_priors()
63+
assert "not yet created" in caplog.text
64+
65+
66+
class TestSpansBySamples:
67+
def test_repr(self):
68+
ts = utility_functions.single_tree_ts_n2()
69+
span_data = SpansBySamples(ts)
70+
rep = repr(span_data)
71+
assert rep.count("Node") == ts.num_nodes
72+
for t in ts.trees():
73+
for u in t.leaves():
74+
assert rep.count(f"{u}: {{}}") == 1
75+
76+
77+
class TestTimepoints:
78+
def test_create_timepoints(self):
79+
priors = ConditionalCoalescentTimes(None, "gamma")
80+
priors.add(3)
81+
tp = create_timepoints(priors, n_points=3)
82+
assert len(tp) == 4
83+
assert tp[0] == 0
84+
85+
def test_create_timepoints_error(self):
86+
priors = ConditionalCoalescentTimes(None, "gamma")
87+
priors.add(2)
88+
priors.prior_distr = "bad_distr"
89+
with pytest.raises(ValueError, match="must be lognorm or gamma"):
90+
create_timepoints(priors, n_points=3)

0 commit comments

Comments
 (0)