22
22
"""
23
23
Test cases for prior functionality used in tsdate
24
24
"""
25
+ import logging
26
+
27
+ import pytest
28
+ import utility_functions
29
+
25
30
from tsdate .prior import ConditionalCoalescentTimes
31
+ from tsdate .prior import create_timepoints
26
32
from tsdate .prior import PriorParams
33
+ from tsdate .prior import SpansBySamples
27
34
28
35
29
36
class TestConditionalCoalescentTimes :
@@ -43,3 +50,41 @@ def test_str(self):
43
50
for i , line in enumerate (lines [2 :]):
44
51
assert line .startswith (f" { i } descendants" )
45
52
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