def test_number_of_calls(self): # Test that genetic map citations are converted. species = stdpopsim.get_species("HomSap") genetic_map = species.get_genetic_map("HapMapII_GRCh37") contig = species.get_contig("chr20", genetic_map=genetic_map.id) model = stdpopsim.PiecewiseConstantSize(species.population_size) engine = stdpopsim.get_default_engine() local_cites = stdpopsim.Citation.merge( [stdpopsim.citations._stdpopsim_citation] + genetic_map.citations + model.citations + engine.citations + species.genome.citations + species.citations ) dois = set([ref.doi for ref in local_cites]) ncite = len(dois) assert ncite == len(local_cites) cli_cites = cli.get_citations(engine, model, contig, species) assert len(cli_cites) == len(local_cites) # Patch out writing to a file, then # ensure that the method is called # the correct number of times. with mock.patch("builtins.open", mock.mock_open()): with open("tmp.bib", "w") as bib: with mock.patch.object( stdpopsim.citations.Citation, "fetch_bibtex", autospec=True ) as mock_bib: cli.write_bibtex(engine, model, contig, species, bib) assert mock_bib.call_count == ncite
def test_number_of_calls(self): # Test that genetic map citations are converted. species = stdpopsim.get_species("HomSap") genetic_map = species.get_genetic_map("HapMapII_GRCh37") contig = species.get_contig("chr22", genetic_map=genetic_map.id) model = stdpopsim.PiecewiseConstantSize(species.population_size) engine = stdpopsim.get_default_engine() cites_and_cites = [ genetic_map.citations, model.citations, engine.citations, species.genome.mutation_rate_citations, species.genome.recombination_rate_citations, species.genome.assembly_citations, ] ncite = len(set([ref.doi for cites in cites_and_cites for ref in cites])) # Patch out writing to a file, then # ensure that the method is called # the correct number of times. with mock.patch("builtins.open", mock.mock_open()): with open('tmp.bib', 'w') as bib: with mock.patch.object( stdpopsim.citations.Citation, "fetch_bibtex") as mock_bib: cli.write_bibtex(engine, model, contig, species, bib) self.assertEqual(mock_bib.call_count, ncite)