def test_assign_parent(self):
        parent = providers.DependenciesContainer()
        provider = providers.DependenciesContainer()

        provider.assign_parent(parent)

        self.assertIs(provider.parent, parent)
Esempio n. 2
0
class ManeuverResolvers(containers.DeclarativeContainer):
    config = providers.Configuration()
    managers = providers.DependenciesContainer()
    action_resolvers = providers.DependenciesContainer()
    logger = providers.Singleton(
        DirectNotify
    )

    passive_observation_resolver = providers.Singleton(
        PassiveObservationManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    movement_resolver = providers.Singleton(
        MoveManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    move_attack_resolver = providers.Singleton(
        MoveAttackManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    yield_turn_resolver = providers.Singleton(
        YieldTurnManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )
class Repository(containers.DeclarativeContainer):
    adapter = providers.DependenciesContainer()
    storage = providers.DependenciesContainer()
    site = providers.Singleton(
        lambda adapter, queue: f"Adapter=[{adapter}], queue=[{queue}]",
        adapter=adapter.tinydb,
        queue=storage.queue,
    )
Esempio n. 4
0
def test_assign_parent():
    parent = providers.DependenciesContainer()
    provider = providers.Container(Core)

    provider.assign_parent(parent)

    assert provider.parent is parent
        class Services(containers.DeclarativeContainer):
            gateways = providers.DependenciesContainer()

            user = providers.Factory(
                UserService,
                db=gateways.database_client,  # <---- missing dependency
            )
Esempio n. 6
0
    def test_init_with_container_and_providers(self):
        provider = providers.DependenciesContainer(
            self.container, dependency=providers.Dependency())
        dependency = provider.dependency

        self.assertTrue(dependency.overridden)
        self.assertIs(dependency.last_overriding, self.container.dependency)
class UseCases(containers.DeclarativeContainer):
    """Use cases container."""

    adapters = providers.DependenciesContainer()

    signup = providers.Factory(SignupUseCase,
                               email_sender=adapters.email_sender)
def test_assign_parent():
    parent = providers.DependenciesContainer()
    container = Container()

    container.assign_parent(parent)

    assert container.parent is parent
    def test_reset_override_only_overridden(self):
        application = TestApplication(config=_copied(TEST_CONFIG_1))
        application.core.override(providers.DependenciesContainer(config=_copied(TEST_CONFIG_2['core'])))

        application.core.reset_override()

        self.assertEqual(application.dict_factory(), {'value': None})
Esempio n. 10
0
class Visual(containers.DeclarativeContainer):
    config = providers.Configuration()
    core = providers.DependenciesContainer()
    fsms = providers.DependenciesContainer()
    data_models = providers.DependenciesContainer()
    managers = providers.DependenciesContainer()

    being = providers.Factory(ActorComponent,
                              parent=core.render,
                              model_file=config.being.model_file)

    grid = providers.Singleton(
        GridComponent,
        parent=core.render,
        data_model=data_models.grid_model_objective,
        entity_component_manager=managers.entity_component_manager)
Esempio n. 11
0
def test_reset_override_only_overridden():
    application = Application(config=_copied(TEST_CONFIG_1))
    application.core.override(providers.DependenciesContainer(config=_copied(TEST_CONFIG_2["core"])))

    application.core.reset_override()

    assert application.dict_factory() == {"value": None}
Esempio n. 12
0
class ActionResolvers(containers.DeclarativeContainer):
    config = providers.Configuration()
    managers = providers.DependenciesContainer()
    rolls = providers.DependenciesContainer()

    logger = providers.Singleton(
        DirectNotify
    )

    get_resolver = providers.Callable(stub_get_resolver)

    generic_action_resolver = providers.Singleton(
        GenericActionResolver,
        resolvers_for_type=get_resolver,
        simulation_manager=managers.simulation_manager
    )

    movement_resolver = providers.Singleton(
        MovementResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger
    )

    melee_attack_resolver = providers.Singleton(
        MeleeAttackResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger
    )

    harvest_resolver = providers.Singleton(
        HarvestResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger
    )

    eat_resolver = providers.Singleton(
        EatResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger
    )

    observation_resolver = providers.Singleton(
        ObservationResolver,
        simulation_manager=managers.simulation_manager,
        roll_versus_factory=rolls.roll_versus.provider,
        logger=logger
    )
Esempio n. 13
0
def test_traversal_default():
    another_provider = providers.Provider()
    provider = providers.DependenciesContainer(default=another_provider)

    all_providers = list(provider.traverse())

    assert len(all_providers) == 1
    assert another_provider in all_providers
 def test_dependencies_attribute(self):
     container = ContainerA()
     container.a1 = providers.Dependency()
     container.a2 = providers.DependenciesContainer()
     self.assertEqual(container.dependencies, {
         'a1': container.a1,
         'a2': container.a2
     })
    def test_traversal_default(self):
        another_provider = providers.Provider()
        provider = providers.DependenciesContainer(default=another_provider)

        all_providers = list(provider.traverse())

        self.assertEqual(len(all_providers), 1)
        self.assertIn(another_provider, all_providers)
    def test_traversal_fluent_interface(self):
        provider = providers.DependenciesContainer()
        provider1 = provider.provider1
        provider2 = provider.provider2

        all_providers = list(provider.traverse())

        self.assertEqual(len(all_providers), 2)
        self.assertIn(provider1, all_providers)
        self.assertIn(provider2, all_providers)
Esempio n. 17
0
def test_traversal_overriding():
    provider1 = providers.Provider()
    provider2 = providers.Provider()
    provider3 = providers.DependenciesContainer(
        provider1=provider1,
        provider2=provider2,
    )

    provider = providers.DependenciesContainer()
    provider.override(provider3)

    all_providers = list(provider.traverse())

    assert len(all_providers) == 5
    assert provider1 in all_providers
    assert provider2 in all_providers
    assert provider3 in all_providers
    assert provider.provider1 in all_providers
    assert provider.provider2 in all_providers
Esempio n. 18
0
def test_traversal_fluent_interface():
    provider = providers.DependenciesContainer()
    provider1 = provider.provider1
    provider2 = provider.provider2

    all_providers = list(provider.traverse())

    assert len(all_providers) == 2
    assert provider1 in all_providers
    assert provider2 in all_providers
    def test_traversal_overriding(self):
        provider1 = providers.Provider()
        provider2 = providers.Provider()
        provider3 = providers.DependenciesContainer(
            provider1=provider1,
            provider2=provider2,
        )

        provider = providers.DependenciesContainer()
        provider.override(provider3)

        all_providers = list(provider.traverse())

        self.assertEqual(len(all_providers), 5)
        self.assertIn(provider1, all_providers)
        self.assertIn(provider2, all_providers)
        self.assertIn(provider3, all_providers)
        self.assertIn(provider.provider1, all_providers)
        self.assertIn(provider.provider2, all_providers)
class InterpreterStateMachineIocContainer(containers.DeclarativeContainer):
    def bootstrap_container(config, logger, common_ioc, state_machine_ioc):
        context_filter = common_ioc.context_filter_provider()
        logger.logger.addFilter(context_filter)
        InterpreterStateMachineIocContainer.instance = InterpreterStateMachineIocContainer(
            config=config,
            common_ioc=common_ioc,
            state_machine_ioc=state_machine_ioc)

        IocUtil.identify_singletons_to_be_skipped_during_deepcopy(
            InterpreterStateMachineIocContainer.instance)

        logger.info("container configuration complete")
        return InterpreterStateMachineIocContainer.instance

    common_ioc = providers.DependenciesContainer()
    state_machine_ioc = providers.DependenciesContainer()

    # Configuration
    config = providers.Configuration('config')
    logging_provider = IocUtil.create_basic_log_adapter(
        providers,
        "bbpyp.interpreter_state_machine",
        extra={"CONTEXT_ID": None})

    # Dependencies provided by third party packages
    interpreter_actions_provider = providers.Dependency()

    # Delegates for consumer's of this package
    interpreter_state_machine_provider = providers.Singleton(
        InterpreterStateMachine,
        logger=logging_provider,
        interpreter_actions=interpreter_actions_provider,
        state_transition_builder=state_machine_ioc.
        state_transition_builder_factory,
        context_service=common_ioc.context_service_provider)

    build = providers.Callable(bootstrap_container,
                               config=config,
                               logger=logging_provider,
                               common_ioc=common_ioc,
                               state_machine_ioc=state_machine_ioc)
Esempio n. 21
0
class DirectObjects(containers.DeclarativeContainer):
    config = providers.Configuration()
    logger = providers.Singleton(DirectNotify)

    managers = providers.DependenciesContainer()

    consciousness_handler = providers.Singleton(
        ConsciousnessHandler,
        being_model_manager=managers.being_model_manager,
        status_effect_manager=managers.status_effect_manager,
        logger=logger)
Esempio n. 22
0
    def test_parent_set_in__setattr__(self):
        class Container(containers.DeclarativeContainer):
            pass

        Container.dependency = providers.Dependency()
        Container.dependencies_container = providers.DependenciesContainer()
        Container.container = providers.Container(ContainerA)

        self.assertIs(Container.dependency.parent, Container)
        self.assertIs(Container.dependencies_container.parent, Container)
        self.assertIs(Container.container.parent, Container)
Esempio n. 23
0
class Fsm(containers.DeclarativeContainer):
    config = providers.Configuration()
    logger = providers.Singleton(DirectNotify)

    managers = providers.DependenciesContainer()
    action_resolvers = providers.DependenciesContainer()

    being = providers.Factory(ActorFSM,
                              simulation_manager=managers.simulation_manager,
                              logger=logger)

    turn_management_fsm = providers.Singleton(
        TurnManagementFSM,
        turn_manager=managers.turn_manager,
        action_resolver=action_resolvers.generic_action_resolver,
        simulation_manager=managers.simulation_manager,
        entity_fsm_manager=managers.entity_fsm_manager,
        interaction_event_manager=managers.interaction_event_manager,
        tick_manager=managers.tick_manager,
        logger=logger)
def test_parent_set_in__setattr__():
    class Container(containers.DeclarativeContainer):
        pass

    Container.dependency = providers.Dependency()
    Container.dependencies_container = providers.DependenciesContainer()
    Container.container = providers.Container(ContainerA)

    assert Container.dependency.parent is Container
    assert Container.dependencies_container.parent is Container
    assert Container.container.parent is Container
Esempio n. 25
0
class Commands(containers.DeclarativeContainer):
    """Dependency structure for Commands"""
    config = providers.Configuration()
    services = providers.DependenciesContainer()
    core = providers.DependenciesContainer()

    plan_command = providers.Singleton(Plan,
                                       plan_service=services.plan_service,
                                       ui_service=services.ui_service,
                                       project=core.project)
    list_command = providers.Singleton(List,
                                       plan_service=services.plan_service,
                                       ui_service=services.ui_service,
                                       project=core.project)
    add_command = providers.Singleton(Add,
                                      plan_service=services.plan_service,
                                      ui_service=services.ui_service,
                                      project=core.project)
    edit_command = providers.Singleton(Edit,
                                       ui_service=services.ui_service,
                                       plan_service=services.plan_service,
                                       project=core.project)
    delete_command = providers.Singleton(Delete,
                                         ui_service=services.ui_service,
                                         plan_service=services.plan_service,
                                         project=core.project)
    commit_command = providers.Singleton(Commit,
                                         ui_service=services.ui_service,
                                         plan_service=services.plan_service,
                                         git_service=services.git_service,
                                         project=core.project)
    init_command = providers.Singleton(
        Init,
        project_service=services.project_service,
        ui_service=services.ui_service,
        project=core.project)
    help_command = providers.Singleton(Help,
                                       ui_service=services.ui_service,
                                       project=core.project)
    def test_parent_deepcopy(self):
        container = containers.DynamicContainer()
        provider = providers.DependenciesContainer()
        container.name = provider

        copied = providers.deepcopy(container)

        self.assertIs(container.name.parent, container)
        self.assertIs(copied.name.parent, copied)

        self.assertIsNot(container, copied)
        self.assertIsNot(container.name, copied.name)
        self.assertIsNot(container.name.parent, copied.name.parent)
Esempio n. 27
0
class OpenSlidesBackendWSGI(containers.DeclarativeContainer):
    """
    Container for dependency injection into OpenSlidesBackendWSGIApplication.
    """

    logging = providers.Object(0)

    view = providers.Object(0)

    services = providers.DependenciesContainer()

    setup = providers.Factory(
        OpenSlidesBackendWSGIApplication, logging=logging, view=view, services=services,
    )
Esempio n. 28
0
class Managers(containers.DeclarativeContainer):
    config = providers.Configuration()
    data_models = providers.DependenciesContainer()

    interaction_event_manager = providers.Singleton(
        InteractionEventManager, event_types=config.interaction.event_types)

    observation_manager = providers.Singleton(ObservationManager)

    entity_model_manager = providers.Singleton(EntityModelManager)
    entity_fsm_manager = providers.Singleton(EntityFsmManager)
    being_model_manager = providers.Singleton(BeingModelManager)
    entity_component_manager = providers.Singleton(
        EntityComponentManager,
        entity_model_manager=entity_model_manager,
        entity_fsm_manager=entity_fsm_manager,
        being_model_manager=being_model_manager)

    turn_manager = providers.Singleton(
        TurnManager, entity_model_manager=entity_model_manager)

    action_manager = providers.Singleton(ActionManager)

    simulation_manager = providers.Singleton(
        SimulationStateManager,
        grid_model=data_models.grid_model_objective,
        entity_component_manager=entity_component_manager,
        action_manager=action_manager,
        observation_manager=observation_manager,
        grid_factory=data_models.grid_model_subjective.provider)
    """ Status effect trigger section """
    def stub_get_resolver():
        raise Exception("This stub needs to be overwritten.")

    get_trigger_resolver = providers.Callable(stub_get_resolver)

    status_effect_trigger_resolver = providers.Singleton(
        StatusEffectTriggerResolver, resolvers_for_type=get_trigger_resolver)

    status_effect_manager = providers.Singleton(
        StatusEffectManager,
        simulation_manager=simulation_manager,
        trigger_resolver=status_effect_trigger_resolver)

    tick_manager = providers.Singleton(
        TickManager,
        status_effect_manager=status_effect_manager,
        tick_value=config.tick_manager.tick_value,
        tick_rate=config.tick_manager.tick_rate)
Esempio n. 29
0
class TriggerResolvers(containers.DeclarativeContainer):
    config = providers.Configuration()
    managers = providers.DependenciesContainer()

    logger = providers.Singleton(DirectNotify)

    starvation_trigger_resolver = providers.Singleton(
        StarvationTriggerResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger)

    dehydrated_trigger_resolver = providers.Singleton(
        DehydrationTriggerResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger)
Esempio n. 30
0
class DataModels(containers.DeclarativeContainer):
    config = providers.Configuration()
    repositories = providers.DependenciesContainer()

    #uuid = providers.Factory(uuid1)
    uuid = providers.Callable(get_id)

    grid_model_objective = providers.Singleton(
        DatabaseBackedGridModel,
        chunk_radius=config.grid.chunk_radius,
        procedural=config.grid.procedural,
        db=repositories.db)

    grid_model_subjective = providers.Factory(SubjectiveGridModel)

    being_model = providers.Factory(Being, entity_id=uuid)