def test_get_data_nyt(self): for format in formats: for data_type in nyt_data_types: for county_option in nyt_county_options: for update_option in update_options: # Check that logic errors get caught if format == "wide" and data_type == "all": with pytest.raises( codex.ParameterError) as excinfo: cod.get_data_nyt(format=format, data_type=data_type, counties=county_option, 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: # 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 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_calc_daily_change_nyt_long(self): for data_type in nyt_data_types: for county_option in nyt_county_options: df = cod.get_data_nyt(format="long", data_type=data_type, counties=county_option, update=False) self._check_daily_change(df, data_type, format="long")
def test_calc_daily_change_nyt_wide(self): for data_type in nyt_data_types: for county_option in nyt_county_options: if data_type == "all": pass # Invalid table parameter combination else: df = cod.get_data_nyt(format="wide", data_type=data_type, counties=county_option, update=False) self._check_daily_change(df, data_type, format="wide")
f"Dataframe had zero in shape: {df.shape}") print( f"Success! format='{format}', data_type='{data_type}', region='{region}', update='{update_option}, returned {df.shape}'" ) # Test New York Times data getter for format in formats: for data_type in nyt_data_types: for county_option in nyt_county_options: for update_option in update_options: # Check that logic errors get caught if format == "wide" and data_type == "all": try: cod.get_data_nyt(format=format, data_type=data_type, counties=county_option, update=update_option) except codex.ParameterError as e: if str( e ) != "'wide' table format only allows one data type. You requested 'all'. Please pass 'cases', 'deaths', or 'recovered'.": raise Exception( f"Test failed. format='{format}', data_type='{data_type}', counties='{county_option}', update='{update_option}'" ) else: print( f"Logic error successfully caught! format='{format}', data_type='{data_type}', counties='{county_option}', update='{update_option}'" ) else: df = cod.get_data_nyt(format=format, data_type=data_type,