コード例 #1
0
def test_create_one_forecast_existing(template_fx, mocker):
    api, template, site = template_fx
    newfx = template.replace(name='site2 Test Template ac_power', site=site)
    api.list_forecasts = mocker.MagicMock(return_value=[newfx])
    fx = common.create_one_forecast(api,
                                    site,
                                    template,
                                    'ac_power',
                                    piggyback_on='other_fx')
    assert fx == newfx
コード例 #2
0
def test_create_one_forecast_issue_time(template_fx, tz, expected):
    api, template, site = template_fx
    template = template.replace(
        run_length=pd.Timedelta('6h'),
        issue_time_of_day=dt.time(5),
        lead_time_to_start=pd.Timedelta('1h'),
    )
    site = site.replace(timezone=tz)
    fx = common.create_one_forecast(api, site, template, 'ac_power')
    assert fx.issue_time_of_day == expected
コード例 #3
0
def test_create_one_forecast(template_fx):
    api, template, site = template_fx
    fx = common.create_one_forecast(api, site, template, 'ac_power')
    assert fx.name == 'site2 Test Template ac_power'
    assert fx.variable == 'ac_power'
    assert fx.site == site
    assert fx.issue_time_of_day == dt.time(8)
    ep = json.loads(fx.extra_parameters)
    assert ep['is_reference_forecast']
    assert ep['model'] == 'gfs_quarter_deg_hourly_to_hourly_mean'
    assert 'piggyback_on' not in ep
コード例 #4
0
def test_create_one_forecast_long_name(template_fx):
    api, template, site = template_fx
    nn = ''.join(['n'] * 64)
    fx = common.create_one_forecast(api, site.replace(name=nn), template,
                                    'ac_power')
    assert fx.name == 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn Test Template ac_power'  # NOQA
    assert fx.variable == 'ac_power'
    assert fx.issue_time_of_day == dt.time(8)
    ep = json.loads(fx.extra_parameters)
    assert ep['is_reference_forecast']
    assert ep['model'] == 'gfs_quarter_deg_hourly_to_hourly_mean'
    assert 'piggyback_on' not in ep
コード例 #5
0
def test_create_one_forecast_invalid(template_fx):
    api, template, site = template_fx

    def fail(fx):
        raise ValueError('failed')

    fx = common.create_one_forecast(api,
                                    site,
                                    template,
                                    'ac_power',
                                    creation_validation=fail)
    assert fx is None