|
2 | 2 | Tests for simulation model infrastructure.
|
3 | 3 | """
|
4 | 4 | import unittest
|
| 5 | +from unittest import mock |
| 6 | +import inspect |
5 | 7 | import itertools
|
6 | 8 | import io
|
7 | 9 | import sys
|
@@ -222,7 +224,7 @@ def test_different_types(self):
|
222 | 224 | msprime.PopulationParametersChange(time=1, initial_size=1),
|
223 | 225 | msprime.MigrationRateChange(time=1, rate=1),
|
224 | 226 | msprime.MassMigration(time=1, source=1),
|
225 |
| - msprime.SimpleBottleneck(time=1)] |
| 227 | + msprime.SimpleBottleneck(time=1, population=0)] |
226 | 228 | for a, b in itertools.combinations(events, 2):
|
227 | 229 | self.assertFalse(models.demographic_events_equal([a], [b], 1))
|
228 | 230 | self.assertFalse(models.demographic_events_equal([b], [a], 1))
|
@@ -322,6 +324,47 @@ def f(time=1, population=1, proportion=1):
|
322 | 324 | models.verify_demographic_events_equal([a], [b], 1)
|
323 | 325 |
|
324 | 326 |
|
| 327 | +# Test compatibility shim for get_ll_representation change in msprime. See #518. |
| 328 | +# TODO: remove this when we depend on msprime 1.0. |
| 329 | +def wrap_get_ll(get_ll_func): |
| 330 | + num_params = len(inspect.signature( |
| 331 | + msprime.MassMigration.get_ll_representation).parameters) |
| 332 | + if num_params == 2: |
| 333 | + # Wrapper for msprime <= 0.7.4 to check for msprime >= 1.0 compat. |
| 334 | + def new_func(self): |
| 335 | + return get_ll_func(self, num_populations=1) |
| 336 | + elif num_params == 1: |
| 337 | + # Wrapper for msprime >= 1.0 to check for msprime <= 0.7.4 compat. |
| 338 | + def new_func(self, num_populations=1): |
| 339 | + return get_ll_func(self) |
| 340 | + else: |
| 341 | + raise RuntimeError( |
| 342 | + "Unexpected signature for msprime.MassMigration.get_ll_representation") |
| 343 | + return new_func |
| 344 | + |
| 345 | + |
| 346 | +@mock.patch( |
| 347 | + "msprime.PopulationParametersChange.get_ll_representation", |
| 348 | + wrap_get_ll(msprime.PopulationParametersChange.get_ll_representation)) |
| 349 | +@mock.patch( |
| 350 | + "msprime.MigrationRateChange.get_ll_representation", |
| 351 | + wrap_get_ll(msprime.MigrationRateChange.get_ll_representation)) |
| 352 | +@mock.patch( |
| 353 | + "msprime.MassMigration.get_ll_representation", |
| 354 | + wrap_get_ll(msprime.MassMigration.get_ll_representation)) |
| 355 | +@mock.patch( |
| 356 | + "msprime.SimpleBottleneck.get_ll_representation", |
| 357 | + wrap_get_ll(msprime.SimpleBottleneck.get_ll_representation)) |
| 358 | +@mock.patch( |
| 359 | + "msprime.InstantaneousBottleneck.get_ll_representation", |
| 360 | + wrap_get_ll(msprime.InstantaneousBottleneck.get_ll_representation)) |
| 361 | +@mock.patch( |
| 362 | + "msprime.CensusEvent.get_ll_representation", |
| 363 | + wrap_get_ll(msprime.CensusEvent.get_ll_representation)) |
| 364 | +class TestDemographicEventsEqualMsprimeGetLLCompat(TestDemographicEventsEqual): |
| 365 | + pass |
| 366 | + |
| 367 | + |
325 | 368 | class TestRegisterQCModel(unittest.TestCase):
|
326 | 369 |
|
327 | 370 | def make_model(self, name):
|
|
0 commit comments