コード例 #1
0
class WeatherForecastContainer(DeclarativeContainer):
    weather_forecast_repository = Dependency()
    weather_forecast_loader = Dependency()

    timestamp_round_algorithm = Factory(CeilTimestampRoundAlgorithm,
                                        round_step=TIME_TICK)
    weather_forecast_preprocessor = Factory(
        SoftMWeatherProcessor,
        timestamp_round_algorithm=timestamp_round_algorithm,
        timestamp_interpolation_algorithm=Factory(
            TimestampInterpolationAlgorithm, timestamp_round_algorithm,
            TIME_TICK),
        timestamp_filter_algorithm=Factory(FullClosedTimestampFilterAlgorithm),
        border_values_interpolation_algorithm=Factory(
            LinearInsideValueInterpolationAlgorithm),
        internal_values_interpolation_algorithm=Factory(
            LinearOutsideValueInterpolationAlgorithm))

    weather_forecast_service = Factory(
        SimpleWeatherForecastService,
        weather_forecast_loader=weather_forecast_loader,
        weather_forecast_processor=weather_forecast_preprocessor,
        weather_forecast_repository=weather_forecast_repository,
        preload_timedelta=Object(pd.Timedelta(hours=3)),
        executor=None)
コード例 #2
0
def test_create_project_aborts_when_path_invalid() -> None:
    create_fake_lean_cli_directory()

    path_validator = mock.Mock()
    path_validator.is_path_valid.return_value = False
    container.path_validator.override(Object(path_validator))

    result = CliRunner().invoke(
        lean, ["create-project", "--language", "python", "My First Project"])

    assert result.exit_code != 0
コード例 #3
0
class Repositories(DeclarativeContainer):
    config = Configuration(strict=True)

    temp_graph_repository = Singleton(SyncTempGraphInMemoryDumperLoader)
    weather_forecast_repository = Singleton(
        WeatherForecastRepository,
        filter_algorithm=Factory(FullClosedTimestampFilterAlgorithm))
    control_actions_repository = Singleton(ControlActionsRepository)
    dynamic_settings_repository = Resource(
        DynamicSettingsRepositoryResource,
        session_factory=Resource(AsyncSettingsDBSessionFactory,
                                 db_engine=Resource(
                                     AsyncSettingsDBEngine,
                                     db_url=config.db_settings_url)),
        dtype_converters=Object([
            dtype_converters.BooleanDTypeConverter(),
            dtype_converters.DatetimeDTypeConverter(),
            dtype_converters.FloatDTypeConverter(),
            dtype_converters.IntDTypeConverter(),
            dtype_converters.StrDTypeConverter(),
            dtype_converters.NoneDTypeConverter(),
            dtype_converters.TimedeltaDTypeConverter()
        ]),
        default_settings=Object(default_config.DICT))
コード例 #4
0
def test_path_parameter_fails_when_input_not_valid_path() -> None:
    @click.command()
    @click.argument("arg",
                    type=PathParameter(exists=False,
                                       file_okay=True,
                                       dir_okay=True))
    def command(arg: Path) -> None:
        pass

    path_validator = mock.Mock()
    path_validator.is_path_valid.return_value = False
    container.path_validator.override(Object(path_validator))

    result = CliRunner().invoke(command, ["invalid-path.txt"])

    assert result.exit_code != 0
コード例 #5
0
class WSGI(DeclarativeContainer):
    config = Configuration(strict=True)

    app = Resource(FastAPIApp,
                   api_routers=Object([
                       api_v1.api_router, api_v2.api_router, api_v3.api_router
                   ]))

    server = Singleton(
        uvicorn.Server,
        config=Factory(
            uvicorn.Config,
            app=app,
            host=config.host,
            port=config.port,
            # log_config=None
        ))
コード例 #6
0
class Services(DeclarativeContainer):
    ids = Callable(lambda: [1, 2, 3])
    api_url = Object('https://ya.ru')

    sync_service: t.Callable[[], SyncProto] = Singleton(SyncService).add_attributes(ids=ids, api_url=api_url)
コード例 #7
0
 def object(self, alias, instance):
     setattr(self.container, alias, Object(instance))