Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Jul 27, 2022
1 parent 1fa75c9 commit bffe447
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions python/tests/test_genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,18 +2107,20 @@ def test_variant_str(self):
"""
Test using a simple dummy tree sequence for testing.
It has only one tree and one site, whose variant has the alleles
('A', 'T', 'G', None).
('A', 'T', 'G', '💩', '', 'TAG', None).
"""
tables = tskit.TableCollection(10)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
for _ in np.arange(6):
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.sites.add_row(position=5, ancestral_state="A")
tables.mutations.add_row(site=0, node=0, derived_state="T")
tables.mutations.add_row(site=0, node=1, derived_state="G")
tables.mutations.add_row(site=0, node=2, derived_state="💩")
tables.mutations.add_row(site=0, node=3, derived_state="")
tables.mutations.add_row(site=0, node=4, derived_state="TAG")
ts = tables.tree_sequence()
v = next(ts.variants())
assert v.alleles == ("A", "T", "G", None)
assert v.alleles == ("A", "T", "G", "💩", "", "TAG", None)
assert isinstance(str(v), str)
assert re.match(
textwrap.dedent(
Expand All @@ -2128,7 +2130,7 @@ def test_variant_str(self):
╠═+╤═+╣
║Site id\s*│\s*0║
╟─+┼─+╢
║Site position\s*│\s*[0-9]+\.0
║Site position\s*│\s*[0-9\.]+
╟─+┼─+╢
║Number of samples\s*│\s*[0-9]+║
╟─+┼─+╢
Expand All @@ -2140,6 +2142,12 @@ def test_variant_str(self):
╟─+┼─+╢
║Samples with allele \'G\'\s*│\s*[0-9]+\s*\([0-9\.]+\%\)║
╟─+┼─+╢
║Samples with allele \'💩\'\s*│\s*[0-9]+\s*\([0-9\.]+\%\)║
╟─+┼─+╢
║Samples with allele \'\'\s*│\s*[0-9]+\s*\([0-9\.]+\%\)║
╟─+┼─+╢
║Samples with allele \'TAG\'\s*│\s*[0-9]+\s*\([0-9\.]+\%\)║
╟─+┼─+╢
║Samples with allele missing\s*│\s*[0-9]+\s*\([0-9\.]+\%\)║
╟─+┼─+╢
║Has missing data\s*│\s*True║
Expand All @@ -2157,6 +2165,7 @@ def test_variant_str_no_samples(self):
tables = tskit.TableCollection(10)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.sites.add_row(position=5, ancestral_state="A")
tables.mutations.add_row(site=0, node=0, derived_state="T")
ts = tables.tree_sequence()
v = next(ts.variants(samples=[]))
for allele in v.alleles:
Expand All @@ -2168,12 +2177,12 @@ def test_variant_str_no_samples(self):
is not None
)

def test_variant_str_no_site():
def test_variant_str_no_site(self):
tables = tskit.TableCollection(10)
ts = tables.tree_sequence()
v = tskit.Variant(ts)
s = str(v)
assert len(s.splitlines()) == 3
assert len(s.splitlines()) == 5
assert (
"This variant has not yet been decoded at a specific site,"
+ "call Variant.decode to set the site"
Expand Down

0 comments on commit bffe447

Please sign in to comment.