def setup_class(cls): """Ensures that all data tables have been recently downloaded, so we can skip the update in all our tests to improve speed.""" cod.get_data_jhu(data_type="all", region="global", update=True) cod.get_data_jhu(data_type="all", region="us", update=True) cod.get_data_nyt(data_type="all", counties=False, update=True) cod.get_data_nyt(data_type="all", counties=True, update=True)
def test_get_data_jhu(self): for format in formats: for data_type in jhu_data_types: for region in jhu_regions: for update_option in update_options: # Check that logic errors get caught if region == "us" and data_type == "recovered": with pytest.raises( codex.ParameterError) as excinfo: cod.get_data_jhu(format=format, data_type=data_type, region=region, update=update_option) assert str( excinfo.value ) == "JHU does not provide recovery data for US states/counties." elif format == "wide" and data_type == "all": with pytest.raises( codex.ParameterError) as excinfo: cod.get_data_jhu(format=format, data_type=data_type, region=region, update=update_option) assert str( excinfo.value ) == "'wide' table format only allows one data type. You requested 'all'. Please pass 'cases', 'deaths', or 'recovered'." else: df = cod.get_data_jhu(format=format, data_type=data_type, region=region, update=update_option) # Check dimensions assert df.shape[0] > 0 and df.shape[1] > 0 # Check that there aren't duplicates assert not df.duplicated().any() # Check for proper date types if format == "long": assert df["date"].dtype == np.dtype( 'datetime64[ns]') elif format == "wide": assert df.columns.map(lambda x: issubclass( type(x), datetime.date)).any()
def test_calc_daily_change_jhu(self): for data_type in jhu_data_types: for region in jhu_regions: if region == "us" and data_type == "recovered": pass # Invalid table parameter combination else: df = cod.get_data_jhu(format="long", data_type=data_type, region=region, update=False) self._check_daily_change(df, data_type, format="long")
update_options = (True, False) nyt_data_types = ("all", "cases", "deaths") nyt_county_options = (True, False) # Test Johns Hopkins data getter for format in formats: for data_type in jhu_data_types: for region in jhu_regions: for update_option in update_options: # Check that logic errors get caught if region == "us" and data_type == "recovered": try: cod.get_data_jhu(format=format, data_type=data_type, region=region, update=update_option) except codex.ParameterError as e: if str( e ) != "JHU does not provide recovery data for US states/counties.": raise Exception( f"Test failed. format='{format}', data_type='{data_type}', region='{region}', update='{update_option}'" ) else: print( f"Logic error successfully caught! format='{format}', data_type='{data_type}', region='{region}', update='{update_option}'" ) elif format == "wide" and data_type == "all": try: