def test_url_default_year(self): """ Test that the download URL reflects the default year when no year is passed to thee constructor """ downloader = census_map_downloader.CountiesDownloader() self.assertTrue(str(self.MOST_RECENT_YEAR) in downloader.url)
def test_init_specify_year(self): """ Test that the year attribute is set to the year passed to the constructor """ downloader = census_map_downloader.CountiesDownloader(year=2018) self.assertEqual(downloader.year, 2018)
def test_init_default_year(self): """ Test that a default year attribute is set when no year is passed to constructor """ downloader = census_map_downloader.CountiesDownloader() self.assertEqual(downloader.year, self.MOST_RECENT_YEAR)
def test_run_default_year(self): """ Test that the default year's shapefile is downloaded and processed when no year is passed to the constructor """ # TODO: This is more of an integration test because it makes a request # and touches the filesystem. It might be better to mock # various classes and methods to detect whether things like # urlretrive() are called. We don't need to test their # functionality. downloader = census_map_downloader.CountiesDownloader( data_dir=self.DATA_DIR ) downloader.run() shapefile_zip_path = self.DATA_DIR / "raw" / f"tl_{self.MOST_RECENT_YEAR}_us_county.zip" self.assertTrue(shapefile_zip_path.is_file()) shapefile_path = self.DATA_DIR / "raw" / f"tl_{self.MOST_RECENT_YEAR}_us_county.shp" self.assertTrue(shapefile_path.is_file()) geojson_path = self.DATA_DIR / "processed" / f"counties_{self.MOST_RECENT_YEAR}.geojson" self.assertTrue(geojson_path.is_file())
def test_url_specify_year(self): """ Test that the download URL reflects the year passed to the constructor """ downloader = census_map_downloader.CountiesDownloader(year=2018) self.assertTrue("2018" in downloader.url)
def counties(ctx): obj = census_map_downloader.CountiesDownloader( data_dir=ctx.obj['data_dir'], year=ctx.obj['year']) obj.run()