def test_upgrade_provenance(self): ts = msprime.simulate(10) for record_text in old_provenance_examples: record = json.loads(record_text) prov = msprime.Provenance(timestamp='2018-08-25T14:59:13', record=json.dumps(record)) is_slim, version = pyslim.slim_provenance_version(prov) self.assertTrue(is_slim) if 'file_version' in record: self.assertEqual(version, "0.1") else: self.assertEqual(version, record['slim']['file_version']) tables = ts.dump_tables() tables.provenances.add_row(json.dumps(record)) pyslim.upgrade_slim_provenance(tables) # modifies the tables new_ts = tables.tree_sequence() self.assertEqual(new_ts.num_provenances, 3) is_slim, version = pyslim.slim_provenance_version( new_ts.provenance(2)) self.assertTrue(is_slim) self.assertEqual(version, "0.4") new_record = json.loads(new_ts.provenance(2).record) if 'model_type' in record: self.assertEqual(record['model_type'], new_record['parameters']['model_type']) self.assertEqual(record['generation'], new_record['slim']["generation"]) else: self.assertEqual(record['parameters']['model_type'], new_record['parameters']['model_type']) self.assertEqual(record['slim']['generation'], new_record['slim']["generation"])
def test_upgrade_provenance(self): ts = msprime.sim_ancestry(10) for record_text in old_provenance_examples: record = json.loads(record_text) prov = tskit.Provenance(id=0, timestamp='2018-08-25T14:59:13', record=json.dumps(record)) is_slim, version = pyslim.slim_provenance_version(prov) assert is_slim if 'file_version' in record: assert version == "0.1" else: assert version == record['slim']['file_version'] tables = ts.dump_tables() tables.provenances.add_row(json.dumps(record)) pyslim.upgrade_slim_provenance(tables) # modifies the tables new_ts = tables.tree_sequence() assert new_ts.num_provenances == 3 is_slim, version = pyslim.slim_provenance_version( new_ts.provenance(2)) assert is_slim assert version == "0.4" new_record = json.loads(new_ts.provenance(2).record) if 'model_type' in record: assert record['model_type'] == new_record['parameters'][ 'model_type'] assert record['generation'] == new_record['slim']["generation"] else: assert record['parameters']['model_type'] == new_record[ 'parameters']['model_type'] assert record['slim']['generation'] == new_record['slim'][ "generation"]
def test_upgrade_provenance(self): ts = msprime.simulate(10) # test bad input with self.assertRaises(ValueError): pyslim.upgrade_slim_provenance(ts.tables) # test good input record = { "program": "SLiM", "version": "3.0", "file_version": "0.1", "model_type": "WF", "generation": 10 } prov = msprime.Provenance(timestamp='2018-08-25T14:59:13', record=json.dumps(record)) is_slim, version = pyslim.provenance._slim_provenance_version( json.loads(prov.record)) self.assertTrue(is_slim) self.assertEqual(version, "0.1") tables = ts.dump_tables() tables.provenances.add_row(json.dumps(record)) pyslim.upgrade_slim_provenance(tables) # modifies the tables new_ts = tables.tree_sequence() self.assertEqual(new_ts.num_provenances, 3) new_record = json.loads(new_ts.provenance(2).record) is_slim, version = pyslim.provenance._slim_provenance_version( new_record) self.assertTrue(is_slim) self.assertEqual(version, "0.2") self.assertEqual(record['model_type'], new_record['parameters']['model_type']) self.assertEqual(record['generation'], new_record['slim']["generation"])
def test_upgrade_provenance_errors(self): ts = msprime.simulate(10) # test bad input with self.assertRaises(ValueError): pyslim.upgrade_slim_provenance(ts.tables)
def test_upgrade_provenance_errors(self): ts = msprime.sim_ancestry(10) # test bad input with pytest.raises(ValueError): pyslim.upgrade_slim_provenance(ts.tables)