Skip to content

Commit 6ccbd22

Browse files
committed
Fix unit testing to work with msprime > 0.7.4.
Closes #518.
1 parent c19fd69 commit 6ccbd22

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

stdpopsim/models.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,16 @@ def verify_demographic_events_equal(
127127
to the specified tolerances and raises a UnequalModelsError otherwise.
128128
"""
129129
# Get the low-level dictionary representations of the events.
130-
dicts1 = [event.get_ll_representation(num_populations) for event in events1]
131-
dicts2 = [event.get_ll_representation(num_populations) for event in events2]
130+
# XXX: Msprime introduced a breaking change between 0.7.4 and 1.0, removing
131+
# the num_populations parameter to get_ll_representation(). See #518.
132+
# When we depend on msprime 1.0, this should be changed to instead use
133+
# msprime.DemographicEvent.asdict().
134+
from inspect import signature
135+
ll_args = ()
136+
if len(signature(msprime.MassMigration.get_ll_representation).parameters) == 2:
137+
ll_args = (num_populations, )
138+
dicts1 = [event.get_ll_representation(*ll_args) for event in events1]
139+
dicts2 = [event.get_ll_representation(*ll_args) for event in events2]
132140
if len(dicts1) != len(dicts2):
133141
raise UnequalModelsError("Different numbers of demographic events")
134142
for d1, d2 in zip(dicts1, dicts2):

tests/test_models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_different_types(self):
222222
msprime.PopulationParametersChange(time=1, initial_size=1),
223223
msprime.MigrationRateChange(time=1, rate=1),
224224
msprime.MassMigration(time=1, source=1),
225-
msprime.SimpleBottleneck(time=1)]
225+
msprime.SimpleBottleneck(time=1, population=0)]
226226
for a, b in itertools.combinations(events, 2):
227227
self.assertFalse(models.demographic_events_equal([a], [b], 1))
228228
self.assertFalse(models.demographic_events_equal([b], [a], 1))

0 commit comments

Comments
 (0)