From 1fa75c9a094ae4b86d940cd5959605db275297c3 Mon Sep 17 00:00:00 2001 From: Shing Zhan Date: Wed, 27 Jul 2022 15:48:25 +0100 Subject: [PATCH] Add test_variant_str_no_samples and test_variant_str_no_site --- python/tests/test_genotypes.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/python/tests/test_genotypes.py b/python/tests/test_genotypes.py index caa5cb0df8..c49a7096de 100644 --- a/python/tests/test_genotypes.py +++ b/python/tests/test_genotypes.py @@ -2153,6 +2153,33 @@ def test_variant_str(self): str(v), ) + 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") + ts = tables.tree_sequence() + v = next(ts.variants(samples=[])) + for allele in v.alleles: + if allele is not None: + assert ( + re.search( + rf"║Samples with allele '{allele}'\s*│\s*0\s*\(nan\%\)║", str(v) + ) + is not None + ) + + def test_variant_str_no_site(): + tables = tskit.TableCollection(10) + ts = tables.tree_sequence() + v = tskit.Variant(ts) + s = str(v) + assert len(s.splitlines()) == 3 + assert ( + "This variant has not yet been decoded at a specific site," + + "call Variant.decode to set the site" + in s + ) + def test_variant_html_repr(self, ts_fixture): v = next(ts_fixture.variants()) html = v._repr_html_()