def test_records_all(self, jhu_data, population_data, country,
                      oxcgrt_data):
     dhl = DataHandler(country=country, province=None)
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     dhl.records_all()
     dhl.register(extras=[oxcgrt_data])
     dhl.records_all()
Exemplo n.º 2
0
 def test_start(self, jhu_data, population_data, country, province):
     if province == "Abruzzo" and country != "Italy":
         with pytest.raises(KeyError):
             DataHandler(
                 jhu_data, population_data, country, province=province)
         return
     DataHandler(jhu_data, population_data, country, province=province)
 def test_timepoints(self, jhu_data, country):
     dhl = DataHandler(country=country, province=None, jhu_data=jhu_data)
     dhl.timepoints(first_date="01Apr2020", last_date="01Sep2020", today="01Jun2020")
     series = dhl.records_main()[Term.DATE]
     assert series.min().strftime(Term.DATE_FORMAT) == dhl.first_date == "01Apr2020"
     assert series.max().strftime(Term.DATE_FORMAT) == dhl.last_date == "01Sep2020"
     assert dhl.today == "01Jun2020"
 def test_estimate_delay(self, jhu_data, population_data, country,
                         oxcgrt_data, indicator, target):
     dhl = DataHandler(country=country, province=None)
     dhl.register(jhu_data=jhu_data,
                  population_data=population_data,
                  extras=[oxcgrt_data])
     df = dhl.estimate_delay(indicator=indicator, target=target)
     assert isinstance(df, pd.DataFrame)
 def test_population(self, jhu_data, population_data, country):
     dhl = DataHandler(country=country, province=None)
     assert not dhl.main_satisfied
     with pytest.raises(NotRegisteredMainError):
         assert dhl.population == population_data.value(country=country)
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     assert dhl.main_satisfied
     assert dhl.population == population_data.value(country=country)
 def test_population(self, jhu_data, population_data, country):
     warnings.filterwarnings("ignore", category=DeprecationWarning)
     dhl = DataHandler(country=country, province=None)
     assert not dhl.main_satisfied
     with pytest.raises(NotRegisteredMainError):
         assert dhl.population == population_data.value(country=country)
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     assert dhl.main_satisfied
     assert dhl.population == population_data.value(country=country)
 def test_records_main(self, jhu_data, country):
     dhl = DataHandler(country=country, province=None)
     with pytest.raises(NotRegisteredMainError):
         dhl.records_main()
     dhl.register(jhu_data=jhu_data)
     main_df = dhl.records_main()
     assert set(main_df.columns) == set([Term.DATE, Term.C, Term.CI, Term.F, Term.R, Term.S])
Exemplo n.º 8
0
 def test_start_record_range(self, jhu_data, population_data, country):
     # Setting
     dhl = DataHandler(jhu_data, population_data, country)
     dhl.init_records()
     # Test
     dhl.first_date = "01Apr2020"
     assert dhl.first_date == "01Apr2020"
     dhl.last_date = "01May2020"
     assert dhl.last_date == "01May2020"
     with pytest.raises(ValueError):
         dhl.first_date = "01Jan2019"
     with pytest.raises(ValueError):
         tomorrow = Term.tomorrow(datetime.now().strftime(Term.DATE_FORMAT))
         dhl.last_date = tomorrow
Exemplo n.º 9
0
 def test_line_plot(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     # Setting
     dhl = DataHandler(jhu_data, population_data, country)
     dhl.init_records()
     # Interactive / script mode
     assert not dhl.interactive
     with pytest.raises(NotInteractiveError):
         dhl.interactive = True
     dhl.interactive = False
     # Change colors in plotting
     dhl.records(
         variables=["Confirmed", "Infected", "Fatal", "Recovered"],
         color_dict={"Confirmed": "blue", "Infected": "orange", "Fatal": "red", "Recovered": "green"})
Exemplo n.º 10
0
 def test_show_complement(self, jhu_data, population_data, country):
     # Setting
     dhl = DataHandler(jhu_data, population_data, country)
     dhl.init_records()
     dhl.first_date = "01Apr2020"
     dhl.last_date = "01Aug2020"
     # Test
     dhl_df = dhl.show_complement()
     data_df = jhu_data.show_complement(
         country=country, start_date="01Apr2020", end_date="01Aug2020")
     assert dhl_df.equals(data_df)
Exemplo n.º 11
0
 def test_records(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     # Setting
     dhl = DataHandler(jhu_data, population_data, country)
     dhl.init_records()
     dhl.first_date = "01Apr2020"
     dhl.last_date = "01Aug2020"
     # Test
     df = dhl.records(variables=None, show_figure=False)
     assert isinstance(df, pd.DataFrame)
     assert set(df.columns) == set([Term.DATE, Term.CI, Term.F, Term.R])
     dates = df[Term.DATE]
     assert dates.min() == Term.date_obj(dhl.first_date)
     assert dates.max() == Term.date_obj(dhl.last_date)
     df2 = dhl.records(variables=["Susceptible"], show_figure=True)
     assert set(df2.columns) == set([Term.DATE, Term.S])
 def test_register(self, data, country):
     dhl = DataHandler(country=country, province=None)
     # Main datasets
     if isinstance(data, JHUData):
         return dhl.register(jhu_data=data)
     if isinstance(data, PopulationData):
         return dhl.register(population_data=data)
     # Extra datasets
     if isinstance(data, (CountryData, JapanData, OxCGRTData, PCRData, VaccineData)):
         return dhl.register(extras=[data])
     # Un-acceptable datasets
     with pytest.raises(UnExpectedValueError):
         dhl.register(extras=[data])
Exemplo n.º 13
0
 def test_records(self, jhu_data, population_data, country, japan_data,
                  oxcgrt_data, pcr_data, vaccine_data, main, extras, past,
                  future):
     dhl = DataHandler(country=country, province=None)
     # Combination of arguments
     if (not main and not extras) or (not past and not future):
         with pytest.raises(ValueError):
             dhl.records(main=main, extras=extras, past=past, future=future)
         return
     # Register main datasets
     if main:
         with pytest.raises(NotRegisteredMainError):
             dhl.records(main=main, extras=extras, past=past, future=future)
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     dhl.timepoints(first_date="01Apr2020",
                    last_date="01Sep2020",
                    today="01Jun2020")
     # Register extra datasets
     if extras:
         with pytest.raises(NotRegisteredExtraError):
             dhl.records(main=main, extras=extras, past=past, future=future)
     dhl.register(extras=[japan_data, oxcgrt_data, pcr_data, vaccine_data])
     # Get records
     df = dhl.records(main=main, extras=extras, past=past, future=future)
     # Check the start/end date of the records
     if past and future:
         sta, end = "01Apr2020", "01Sep2020"
     elif past:
         sta, end = "01Apr2020", "01Jun2020"
     else:
         sta, end = "02Jun2020", "01Sep2020"
     assert df[Term.DATE].min().strftime(Term.DATE_FORMAT) == sta
     assert df[Term.DATE].max().strftime(Term.DATE_FORMAT) == end
Exemplo n.º 14
0
 def test_register_unknown_area(self, jhu_data, population_data, country):
     dhl = DataHandler(country=country, province=None)
     dhl.register(jhu_data=jhu_data)
     with pytest.raises(SubsetNotFoundError):
         dhl.register(population_data=population_data)
Exemplo n.º 15
0
 def test_records_extras(self, jhu_data, population_data, country,
                         japan_data, oxcgrt_data, pcr_data, vaccine_data):
     dhl = DataHandler(country=country, province=None)
     with pytest.raises(NotRegisteredMainError):
         dhl.records_extras()
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     dhl.timepoints(first_date="01May2020", last_date="01Sep2020")
     with pytest.raises(NotRegisteredExtraError):
         dhl.records_extras()
     dhl.register(extras=[japan_data, oxcgrt_data, pcr_data, vaccine_data])
     series = dhl.records_extras()[Term.DATE]
     assert series.min().strftime(
         Term.DATE_FORMAT) == dhl.first_date == "01May2020"
     assert series.max().strftime(
         Term.DATE_FORMAT) == dhl.last_date == "01Sep2020"
Exemplo n.º 16
0
 def test_records_main(self, jhu_data, population_data, country):
     dhl = DataHandler(country=country, province=None)
     with pytest.raises(NotRegisteredMainError):
         dhl.records_main()
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     assert dhl.population == population_data.value(country=country)
Exemplo n.º 17
0
 def test_recovery_period(self, jhu_data, country):
     dhl = DataHandler(country=country, province=None)
     with pytest.raises(NotRegisteredMainError):
         assert isinstance(dhl.recovery_period(), int)
     dhl.register(jhu_data=jhu_data)
     assert isinstance(dhl.recovery_period(), int)
Exemplo n.º 18
0
 def test_records_diff(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     dhl = DataHandler(jhu_data, population_data, country)
     dhl.init_records()
     dhl.records_diff(window=7, show_figure=False)
     dhl.records_diff(window=100, show_figure=True)
Exemplo n.º 19
0
 def test_complement(self, jhu_data, population_data, country):
     dhl = DataHandler(country=country, province=None)
     with pytest.raises(NotRegisteredMainError):
         assert dhl.complemented is None
     with pytest.raises(NotRegisteredMainError):
         dhl.show_complement()
     dhl.register(jhu_data=jhu_data, population_data=population_data)
     # Not complemented
     dhl.switch_complement(whether=False)
     dhl.records_main()
     dhl.show_complement()
     assert not dhl.complemented
     # Complemented
     dhl.switch_complement(whether=True)
     dhl.records_main()
     dhl.show_complement()
     assert dhl.complemented