Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_tz_unaware(interpretation):
start_date = datetime(2000, 1, 1)
end_date = datetime(2000, 1, 2)
with pytest.raises(ValueError):
ModelingPeriod(interpretation, start_date, end_date)
def test_grouping_out_of_order():
modeling_periods = {
"modeling_period_1": ModelingPeriod(
"BASELINE",
end_date=datetime(2000, 1, 1, tzinfo=pytz.UTC),
),
"modeling_period_2": ModelingPeriod(
"REPORTING",
start_date=datetime(2000, 2, 1, tzinfo=pytz.UTC),
),
}
grouping = [
("modeling_period_2", "modeling_period_1"),
]
with pytest.raises(ValueError):
ModelingPeriodSet(modeling_periods, grouping)
def test_repr(interpretation):
start_date = datetime(2000, 1, 1, tzinfo=pytz.UTC)
end_date = datetime(2000, 1, 2, tzinfo=pytz.UTC)
mp = ModelingPeriod(interpretation, start_date, end_date)
assert str(mp).startswith("ModelingPeriod")
def test_start_date_blank_reporting_not_ok(interpretation):
end_date = datetime(2000, 1, 2, tzinfo=pytz.UTC)
with pytest.raises(ValueError):
ModelingPeriod("REPORTING", end_date=end_date)
def test_create_basic():
modeling_period_1 = ModelingPeriod(
"BASELINE",
end_date=datetime(2000, 1, 1, tzinfo=pytz.UTC),
)
modeling_period_2 = ModelingPeriod(
"REPORTING",
start_date=datetime(2000, 1, 1, tzinfo=pytz.UTC),
)
modeling_periods = {
"modeling_period_1": modeling_period_1,
"modeling_period_2": modeling_period_2,
}
grouping = [
("modeling_period_1", "modeling_period_2"),
]
baseline_period_end = _get_earliest_intervention_start_date(
interventions)
reporting_period_start = _get_latest_intervention_end_date(
interventions)
if reporting_period_start is None:
# fall back to baseline_period_end - interventions are still
# ongoing.
reporting_period_start = baseline_period_end
modeling_periods = {
"baseline": ModelingPeriod(
"BASELINE",
end_date=baseline_period_end
),
"reporting": ModelingPeriod(
"REPORTING",
start_date=reporting_period_start
),
}
groupings = [("baseline", "reporting")]
modeling_period_set = ModelingPeriodSet(modeling_periods, groupings)
logger.info("Created one modeling period group.")
return modeling_period_set
return {
'error': (
'Project serializations must provide key'
' "baseline_period".'
)
}
else:
start_date = baseline_period.get("start", None)
if start_date is not None:
start_date = dateutil.parser.parse(start_date).astimezone(pytz.utc)
end_date = baseline_period.get("end", None)
if end_date is not None:
end_date = dateutil.parser.parse(end_date).astimezone(pytz.utc)
baseline = ModelingPeriod(
"BASELINE",
start_date,
end_date
)
# check for "reporting_period" key
reporting_period = modeling_period_group.get('reporting_period', None)
if reporting_period is None:
return {
'error': (
'Project serializations must provide key'
' "reporting_period".'
)
}
else:
start_date = reporting_period.get("start", None)
return {
'error': (
'Project serializations must provide key'
' "reporting_period".'
)
}
else:
start_date = reporting_period.get("start", None)
if start_date is not None:
start_date = dateutil.parser.parse(start_date).astimezone(pytz.utc)
end_date = reporting_period.get("end", None)
if end_date is not None:
end_date = dateutil.parser.parse(end_date).astimezone(pytz.utc)
reporting = ModelingPeriod(
"REPORTING",
start_date,
end_date
)
modeling_periods = {
"baseline": baseline,
"reporting": reporting,
}
grouping = [
("baseline", "reporting"),
]
mps = ModelingPeriodSet(modeling_periods, grouping)
return {