Exemplo n.º 1
0
            extra = str(uuid.uuid1())
            photons_app = {"extra": extra}
            configuration = MergedOptions()
            collector = Collector()
            register = mock.Mock(name="register")
            args_dict = mock.Mock(name="args_dict")

            with self.mocks(collector, configuration, args_dict, photons_app, register):
                collector.extra_prepare(configuration, args_dict)

            class AFuture:
                def __eq__(self, other):
                    return isinstance(other, asyncio.Future)

            self.assertIs(collector.register, register)
            self.assertEqual(configuration.as_dict()
                , { "$@": extra
                  , "collector": collector
                  , "photons_app": photons_app
                  , "final_future": AFuture()
                  }
                )

    describe "find_photons_app_options":
        it "returns us a dictionary with options from configuration and args_dict":
            configuration = MergedOptions.using({"photons_app": {"one": 1, "two": 2}})
            args_dict = {"photons_app": {"one": 3, "three": 4}}

            photons_app = Collector().find_photons_app_options(configuration, args_dict)
            self.assertEqual(photons_app, {"one": 3, "two": 2, "three": 4})
Exemplo n.º 2
0
            source = MergedOptions.using({"a":5, "b":2, "c": {"e":7}})
            hp.merge_into_dict(target, source)
            self.assertEqual(target, {"a":5, "b":2, "c": {"e": 7}})

        it "merges a MergedOptions into a full dictionary":
            target = {"a":5, "b":2, "c": {"f":7}}
            source = MergedOptions.using({"a":1, "b":2, "c": {"e":7}})
            hp.merge_into_dict(target, source)
            self.assertEqual(target, {"a":1, "b":2, "c": {"f": 7, "e": 7}})

        it "merges a MergedOptions with prefixed data into an empty dictionary":
            target = {"a":5, "b":2, "c": {"f":7}}
            source = MergedOptions()
            source["c"] = {"e": 7}
            hp.merge_into_dict(target, source)
            self.assertEqual(target, {"a":5, "b":2, "c": {"f": 7, "e": 7}})

        it "merges a nested MergedOptions into a dictionary":
            source1 = MergedOptions.using({"one": 1, "two": 2, "three": {"four": 4}})
            source2 = MergedOptions.using({"one": "ONE"})
            source3 = MergedOptions.using({"four": "FOUR"})
            source = MergedOptions.using({"a": 1}, source1, {"cap": source2})
            source["three"] = source3

            self.assertEqual(source.as_dict(), {"a":1, "cap":{"one": "ONE"}, "three": {"four": "FOUR"}, "one": 1, "two": 2})

            target = {"one": "thousand", "and": "fifteen"}
            hp.merge_into_dict(target, source)
            self.assertEqual(target, {"and": "fifteen", "a":1, "cap":{"one": "ONE"}, "three": {"four": "FOUR"}, "one": 1, "two": 2})