Skip to content

Commit 881469f

Browse files
authored
Merge pull request #1328 from benjeffery/assert_equal
Assert equal for tables and collections
2 parents 4f53216 + 0ef4d4f commit 881469f

11 files changed

+527
-130
lines changed

python/CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
- Improve display of tables when ``print``ed, limiting lines set via
3232
``tskit.set_print_options`` (:user:`benjeffery`,:issue:`1270`, :pr:`1300`).
3333

34+
- Add ``Table.assert_equals`` and ``TableCollection.assert_equals`` which give an exact
35+
report of any differences. (:user:`benjeffery`,:issue:`1076`, :pr:`1328`)
36+
3437
**Fixes**
3538

3639
- Tree sequences were not properly init'd after unpickling

python/tests/test_combinatorics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ def test_binary_tree(self):
12331233
t1 = msprime.simulate(10, random_seed=1234).first()
12341234
t2 = t1.split_polytomies(random_seed=1234)
12351235
tables = t1.tree_sequence.dump_tables()
1236-
assert tables.equals(t2.tree_sequence.tables, ignore_provenance=True)
1236+
tables.assert_equals(t2.tree_sequence.tables, ignore_provenance=True)
12371237

12381238
def test_bad_method(self):
12391239
tree = tskit.Tree.generate_star(3)
@@ -1405,7 +1405,7 @@ def test_rank_unrank_round_trip(self, n):
14051405
tree2 = tskit.Tree.unrank(n, rank)
14061406
tables1 = tree1.tree_sequence.tables
14071407
tables2 = tree2.tree_sequence.tables
1408-
assert tables1.equals(tables2, ignore_provenance=True)
1408+
tables1.assert_equals(tables2, ignore_provenance=True)
14091409

14101410
def test_kwargs(self):
14111411
tree = self.method(3, tracked_samples=[0, 1])
@@ -1457,7 +1457,7 @@ def test_rank_unrank_round_trip_arity(self, n, arity):
14571457
tree2 = tskit.Tree.unrank(n, rank)
14581458
tables1 = tree1.tree_sequence.tables
14591459
tables2 = tree2.tree_sequence.tables
1460-
assert tables1.equals(tables2, ignore_provenance=True)
1460+
tables1.assert_equals(tables2, ignore_provenance=True)
14611461

14621462
def test_bad_arity(self):
14631463
for arity in [-1, 0, 1]:
@@ -1505,7 +1505,7 @@ def test_rank_unrank_round_trip_seeds(self, seed):
15051505
tree2 = tskit.Tree.unrank(n, rank)
15061506
tables1 = tree1.tree_sequence.tables
15071507
tables2 = tree2.tree_sequence.tables
1508-
assert tables1.equals(tables2, ignore_provenance=True)
1508+
tables1.assert_equals(tables2, ignore_provenance=True)
15091509

15101510

15111511
class TestGenerateComb(TreeGeneratorTestBase):

python/tests/test_file_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def test_empty_mutation_time(self):
869869
# Null out the time column
870870
t1 = ts1.dump_tables()
871871
t1.mutations.time = np.full_like(t1.mutations.time, tskit.UNKNOWN_TIME)
872-
assert t1 == ts3.tables
872+
t1.assert_equals(ts3.tables)
873873

874874
def test_empty_individual_parents(self):
875875
ts1 = migration_example()
@@ -890,7 +890,7 @@ def test_empty_individual_parents(self):
890890
]
891891
* tables.individuals.num_rows
892892
)
893-
assert tables == ts3.tables
893+
tables.assert_equals(ts3.tables)
894894

895895

896896
class TestFileFormatErrors(TestFileFormat):

python/tests/test_highlevel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ def verify_tables_api_equality(self, ts):
11451145
for samples in [None, list(ts.samples()), ts.samples()]:
11461146
tables = ts.dump_tables()
11471147
tables.simplify(samples=samples)
1148-
assert tables.equals(
1148+
tables.assert_equals(
11491149
ts.simplify(samples=samples).tables, ignore_timestamps=True
11501150
)
11511151

python/tests/test_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,11 +1889,11 @@ def test_equality(self):
18891889
tables.metadata_schema = metadata.MetadataSchema(schema)
18901890
assert tables != tables2
18911891
tables2.metadata_schema = metadata.MetadataSchema(schema2)
1892-
assert tables == tables2
1892+
tables.assert_equals(tables2)
18931893
tables.metadata = collections.OrderedDict(one="tree", two=5)
18941894
assert tables != tables2
18951895
tables2.metadata = collections.OrderedDict(two=5, one="tree")
1896-
assert tables == tables2
1896+
tables.assert_equals(tables2)
18971897

18981898
def test_fixing_uncanonical(self):
18991899
ts = msprime.simulate(10, random_seed=42)

0 commit comments

Comments
 (0)