def test_start(self, jhu_data, population_data, country): # Setting population = population_data.value(country) series = PhaseSeries("01Apr2020", "22Apr2020", population) # Whether units are registered or not assert not series assert series.summary().empty
def test_add_phase(self, jhu_data, population_data, country): # Setting population = population_data.value(country) series = PhaseSeries("01Apr2020", "01Aug2020", population) # Last phase when empty empty_phase = PhaseUnit("31Mar2020", "31Mar2020", population) assert series.unit(phase="last") == empty_phase # Add a phase with specified end date: 0th series.add(end_date="22Apr2020") # Add a phase with specified population value: 1st with pytest.raises(ValueError): series.add(end_date="22Apr2020") series.add(end_date="05May2020", population=int(population * 0.98)) # Add a phase with specified the number of days: 2nd series.add(days=21) # Filling past phases and add a future phase: 3rd, 4th series.add(end_date="01Sep2020") # Add a future phase: 5th series.add(days=30) # Summary df = series.summary() base_cols = [Term.TENSE, Term.START, Term.END, Term.N] assert set(df.columns) == set(base_cols) assert series.to_dict()["0th"]["Type"] == Term.PAST first_len = len(df) assert set(df.loc["3rd", :].tolist()) == set( [Term.PAST, "27May2020", "01Aug2020", 123998518]) assert set(df.loc["4th", :].tolist()) == set( [Term.FUTURE, "02Aug2020", "01Sep2020", 123998518]) # Disable/enable a phase series.disable("0th") assert "0th" not in series.to_dict() assert len(series) == first_len - 1 assert len([unit for unit in series]) == first_len assert len([unit for unit in series if unit]) == first_len - 1 series.enable("0th") assert "0th" in series.to_dict() assert len(series) == first_len # Clear future phases: 4th and 5th will be deleted series.clear(include_past=False) assert "4th" not in series.to_dict() assert len(series) == first_len - 2 assert series # Clear all phases series.clear(include_past=True) assert len(series) == 0 assert not series # Filling past phases: 0th series.add() assert len(series) == 1 # Last phase assert series.unit(phase="last")