@@ -244,6 +244,39 @@ def test_current_ts(self):
244244 assert command == "sim_mutations"
245245 assert prov ["tree_sequence" ] == ts1
246246
247+ def test_demography (self ):
248+ demography = msprime .Demography .island_model ([1 , 1 ], 1 / 3 )
249+ ts = msprime .sim_ancestry (
250+ demography = demography ,
251+ samples = [
252+ msprime .SampleSet (1 , population = 0 ),
253+ msprime .SampleSet (1 , population = 1 ),
254+ ],
255+ random_seed = 3 ,
256+ )
257+ command , prov = msprime .provenance .parse_provenance (ts .provenance (- 1 ), ts )
258+ assert command == "sim_ancestry"
259+ assert prov ["demography" ] == demography
260+
261+ def test_bad_demography (self ):
262+ demography = msprime .Demography .island_model ([1 , 1 ], 1 / 3 )
263+ ts = msprime .sim_ancestry (
264+ demography = demography ,
265+ samples = [
266+ msprime .SampleSet (1 , population = 0 ),
267+ msprime .SampleSet (1 , population = 1 ),
268+ ],
269+ random_seed = 3 ,
270+ )
271+ prov = ts .provenance (- 1 )
272+ record = json .loads (prov .record )
273+ # Corrupt the provenance record
274+ assert len (record ["parameters" ]["demography" ]["migration_matrix" ]) == 2
275+ record ["parameters" ]["demography" ]["migration_matrix" ] = [1 , 0 , 0 ]
276+ prov .record = json .dumps (record )
277+ with pytest .raises (ValueError , match = "Migration matrix must be square" ):
278+ msprime .provenance .parse_provenance (prov , ts )
279+
247280
248281class TestRoundTrip :
249282 """
0 commit comments