Пример #1
0
 def test_with_nonstr_sequence_arg_values_resolved(self):
     arg = [
         ("partial", partial(int, "79")),
         ("evaluator", Evaluator(int, "97")),
         ("reference", Reference("number"))
     ]
     evaluator = Evaluator(dict, arg)
     self.assertEqual(
         {"partial": 79, "evaluator": 97, "reference": 101},
         evaluator(self._assembler))
Пример #2
0
 def test_with_dict_keyword_values_resolved(self):
     arg = {
         "partial": partial(int, "79"),
         "evaluator": Evaluator(int, "97"),
         "reference": Reference("number"),
     }
     evaluator = Evaluator(dict, keyword=arg)
     self.assertEqual(
         {"keyword": {"partial": 79, "evaluator": 97, "reference": 101}},
         evaluator(self._assembler))
Пример #3
0
 def test_with_nonstr_sequence_keyword_values_resolved(self):
     arg = [
         ("partial", partial(int, "79")),
         ("evaluator", Evaluator(int, "97")),
         ("reference", Reference("number"))
     ]
     evaluator = Evaluator(dict, keyword=arg)
     self.assertEqual(
         {"keyword":
             [("partial", 79), ("evaluator", 97), ("reference", 101)]},
         evaluator(self._assembler))
    def build_components(self, config):
        container = Binder()

        (container.bind("Config", to=dict).init(config))

        # Loggers
        logger = self.build_logger(config)

        # controller
        (container.bind(
            "weather_controller",
            to="weather_web_app.app.controller.Controller").init(
                logger, Reference("app.RequestDomFactory"),
                Reference("app.request_model_factories.WeatherModelFactory"),
                Reference("domain.services.WeatherService"),
                Reference("views.ViewFactory")))

        # app model factories
        (container.bind(
            "app.request_model_factories.WeatherModelFactory",
            to=
            "weather_web_app.app.request_model_factories.weather_model_factory.WeatherModelFactory"
        ))

        # domain services
        (container.bind(
            "domain.services.WeatherService",
            to="weather_web_app.domain.services.weather_service.WeatherService"
        ).init(Reference("logistics.DarkSkyApiFactory"), Reference("Config"),
               logger, Reference("domain.factories.ValidationFactory"),
               Reference("domain.factories.WeatherServiceFactory")))

        # domain factories
        (container.bind(
            "domain.factories.ValidationFactory",
            to=
            "weather_web_app.domain.factories.validation_factory.ValidationFactory"
        ))
        (container.bind(
            "domain.factories.WeatherServiceFactory",
            to=
            "weather_web_app.domain.factories.weather_service_factory.WeatherServiceFactory"
        ))

        # api factories
        (container.bind(
            "logistics.DarkSkyApiFactory",
            to="weather_web_app.logistics.dark_sky_api_factory.DarkSkyApiFactory"
        ).init(Reference("Config"), logger))

        # request_dom_factory
        (container.bind(
            "app.RequestDomFactory",
            to="weather_web_app.app.request_dom_factory.RequestDomFactory").
         init(logger))

        # view factory
        (container.bind("views.ViewFactory",
                        to="weather_web_app.view.view_factory.ViewFactory"))

        return container
Пример #5
0
 def test_module(self):
     ref = Reference(dummy)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy", ref)
Пример #6
0
 def test_builtin_function(self):
     ref = Reference(hex)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.hex" % hex.__module__, ref)
Пример #7
0
 def test_user_function(self):
     ref = Reference(dummy.factory_function)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.factory_function", ref)
Пример #8
0
 def test_builtin_class(self):
     ref = Reference(float)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.float" % float.__module__, ref)
Пример #9
0
 def test_user_class(self):
     ref = Reference(dummy.ModuleClass)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.ModuleClass", ref)
Пример #10
0
 def test_string(self):
     ref = Reference("test-component-id")
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test-component-id", ref)
Пример #11
0
 def test_with_reference_keyword(self):
     evaluator = Evaluator(dict, test=Reference("test.dummy.ModuleClass"))
     d = evaluator(self._assembler)
     self.assertEqual(1, len(d))
     self.assertTrue(isinstance(d["test"], dummy.ModuleClass))
     self.assertEqual("test", d["test"].arg)
Пример #12
0
 def test_with_reference_arg(self):
     evaluator = Evaluator(
         getattr, Reference("test.dummy.ModuleClass"), "arg")
     self.assertEqual("test", evaluator(self._assembler))
Пример #13
0
 def test_reference_is_string(self):
     self.assertTrue(is_string(Reference("test")))