Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_simplify(self):
ts = msprime.simulate(5, random_seed=1)
ts = ts.simplify()
prov = json.loads(ts.provenance(1).record)
tskit.validate_provenance(prov)
self.assertEqual(prov["parameters"]["command"], "simplify")
def test_mutate(self):
ts = msprime.simulate(5, random_seed=1)
ts = msprime.mutate(ts, rate=1, random_seed=1)
prov = json.loads(ts.provenance(1).record)
tskit.validate_provenance(prov)
self.assertEqual(prov["parameters"]["command"], "mutate")
def verify_provenance(self, ts):
for u in ts.provenances():
tskit.validate_provenance(json.loads(u.record))
def test_minimal(self):
minimal = {
"schema_version": "1",
"software": {
"name": "x",
"version": "y",
},
"environment": {},
"parameters": {}
}
tskit.validate_provenance(minimal)
def test_extra_stuff(self):
extra = {
"you": "can",
"schema_version": "1",
"software": {
"put": "anything",
"name": "x",
"version": "y",
},
"environment": {"extra": ["you", "want"]},
"parameters": {"so": ["long", "its", "JSON", 0]}
}
tskit.validate_provenance(extra)
def test_missing_keys(self):
minimal = get_provenance()
tskit.validate_provenance(minimal)
for key in minimal.keys():
copy = dict(minimal)
del copy[key]
with self.assertRaises(tskit.ProvenanceValidationError):
tskit.validate_provenance(copy)
copy = dict(minimal)
del copy["software"]["name"]
with self.assertRaises(tskit.ProvenanceValidationError):
tskit.validate_provenance(copy)
copy = dict(minimal)
del copy["software"]["version"]
with self.assertRaises(tskit.ProvenanceValidationError):
tskit.validate_provenance(copy)
def validate_ts(self, ts):
for prov in ts.provenances():
p_doc = json.loads(prov.record)
tskit.validate_provenance(p_doc)
def test_software_types(self):
for bad_type in [0, [1, 2, 3], {}]:
doc = get_provenance(software_name=bad_type)
with self.assertRaises(tskit.ProvenanceValidationError):
tskit.validate_provenance(doc)
doc = get_provenance(software_version=bad_type)
with self.assertRaises(tskit.ProvenanceValidationError):
tskit.validate_provenance(doc)
(is_slim, file_version), record = slim_prov[len(slim_prov)-1]
if not (float(file_version) < 0.4):
warnings.warn("File version is not older than 0.4; not doing anything.")
if not is_slim:
raise ValueError("Not a SLiM provenance entry.")
if file_version == "0.1":
new_record = make_slim_provenance_dict(
record['model_type'],
record['generation'])
new_record['parameters']['command'] = ['pyslim', 'convert']
else:
new_record = make_slim_provenance_dict(
record['parameters']['model_type'],
record['slim']['generation'])
new_record['parameters']['command'] = ['pyslim', 'convert']
tskit.validate_provenance(new_record)
tables.provenances.add_row(json.dumps(new_record))