def test_one_chrom_from_each_map(self): for gm in stdpopsim.all_genetic_maps(): species = gm.species if gm.id in ("NaterPA_PonAbe2", "NaterPP_PonAbe2"): # XXX: these maps are currently broken: # ValueError: The last entry in the 'rate' column must be zero continue # Just load the first chromosome in the list. # There's no requirement that any given chromosome is actually # in the map, and we don't have a direct way to check # for its presence. But if this chromsome is *not* in the # map, we will recieve a warning (and then fail the test below). chrom = species.genome.chromosomes[0] with pytest.warns(None) as record: gm.get_chromosome_map(chrom.id) # Fail the test if we get any warnings matching the message below. # There doesn't seem to be a way to simply check for the absense # of a specific warning using pytest, so we record all warnings # and check manually. record = [ r for r in record if re.match(r"Recombination map not found", str(r.message)) is not None ] assert len(record) == 0, f"{species.id} / {gm.id}"
def test_reason_for_genetic_map_citations(self): for genetic_map in stdpopsim.all_genetic_maps(): for citation in genetic_map.citations: assert len(citation.reasons) > 0, ( f"No reason given for '{citation.author}' citation " f"in genetic map " f"{genetic_map.species.id}/{genetic_map.id}" )
def setUpModule(): destination = pathlib.Path("_test_cache/tarballs") for genetic_map in stdpopsim.all_genetic_maps(): key = genetic_map.id local_file = destination / (key + ".tar.gz") if not local_file.exists(): cache_dir = local_file.parent cache_dir.mkdir(exist_ok=True, parents=True) # print("Downloading", genetic_map.url) urllib.request.urlretrieve(genetic_map.url, local_file) saved_urls[key] = genetic_map.url genetic_map.url = local_file.resolve().as_uri()
def test_multiple_threads_downloading(self): gm = next(stdpopsim.all_genetic_maps()) gm.download() saved = gm.is_cached try: # Trick the download code into thinking there's several happening # concurrently gm.is_cached = lambda: False with self.assertWarns(UserWarning): gm.download() finally: gm.is_cached = saved
def test_one_chrom_from_each_map(self): for gm in stdpopsim.all_genetic_maps(): species = gm.species if gm.id in ("NaterPA_PonAbe2", "NaterPP_PonAbe2"): # XXX: these maps are currently broken: # ValueError: The last entry in the 'rate' column must be zero continue # Just load the first chromosome in the list. # There's no requirement that any given chromosome is actually # in the map, and we don't have a direct way to check # for its presence. But if this chromsome is *not* in the # map, we will recieve a warning (which is treated as an error # using the warnings filter). chrom = species.genome.chromosomes[0] gm.get_chromosome_map(chrom.id)
def setUpModule(): destination = pathlib.Path("_test_cache/tarballs") for genetic_map in stdpopsim.all_genetic_maps(): key = genetic_map.id local_file = destination / (key + ".tar.gz") if not local_file.exists(): cache_dir = local_file.parent cache_dir.mkdir(exist_ok=True, parents=True) print("Downloading", genetic_map.url) utils.download(genetic_map.url, local_file) # This assertion could fail if we update a file on AWS, # or a developer creates a new genetic map with the wrong checksum # (in the latter case, this should at least be caught during CI tests). assert utils.sha256(local_file) == genetic_map.sha256, ( f"SHA256 for {local_file} doesn't match the SHA256 for " f"{genetic_map.id}. If you didn't add this SHA256 yourself, " f"try deleting {local_file} and restarting the tests.") saved_urls[key] = genetic_map.url genetic_map.url = local_file.resolve().as_uri() genetic_map._cache.url = genetic_map.url
def tearDownModule(): for genetic_map in stdpopsim.all_genetic_maps(): genetic_map.url = saved_urls[genetic_map.id]
def test_ids(self): for gm in stdpopsim.all_genetic_maps(): self.assertIsInstance(gm.id, str) self.assertTrue(utils.is_valid_genetic_map_id(gm.id))
def test_types(self): for gm in stdpopsim.all_genetic_maps(): self.assertIsInstance(gm, genetic_maps.GeneticMap)
def test_non_empty(self): self.assertGreater(len(list(stdpopsim.all_genetic_maps())), 0)
def test_download_over_cache(self): for gm in stdpopsim.all_genetic_maps(): gm.download() self.assertTrue(gm.is_cached()) gm.download() self.assertTrue(gm.is_cached())
def teardown_module(): for genetic_map in stdpopsim.all_genetic_maps(): genetic_map.url = saved_urls[genetic_map.id] genetic_map._cache.url = genetic_map.url
def test_ids(self): for gm in stdpopsim.all_genetic_maps(): assert isinstance(gm.id, str) assert utils.is_valid_genetic_map_id(gm.id)
def test_types(self): for gm in stdpopsim.all_genetic_maps(): assert isinstance(gm, stdpopsim.GeneticMap)
def test_non_empty(self): assert len(list(stdpopsim.all_genetic_maps())) > 0