示例#1
0
    def test_get_method_flag(self):
        FLAGS = Flags("PETS", "FARM_ANIMALS", "WILD_ANIMALS", "OTHER")
        registry = FlagRegistry()

        @registry.register(
            flag=(FLAGS.PETS, FLAGS.FARM_ANIMALS, FLAGS.WILD_ANIMALS),
            key=("pets", "farm", "wild"),
        )
        def some_method():
            return "cat", "pig", "rhino"

        @registry.register(flag=FLAGS.OTHER, depends_on=FLAGS.PETS, key="other")
        def method_other():
            pass

        method_flag, method_dependencies = registry._get_method_flag(some_method)

        self.assertEqual(
            method_flag, FLAGS.PETS | FLAGS.FARM_ANIMALS | FLAGS.WILD_ANIMALS
        )
        self.assertEqual(method_dependencies, 0)

        method_flag, method_dependencies = registry._get_method_flag(method_other)

        self.assertEqual(method_flag, FLAGS.OTHER)
        self.assertEqual(method_dependencies, FLAGS.PETS)
    def test_get_method_flag(self):
        FLAGS = Flags('PETS', 'FARM_ANIMALS', 'WILD_ANIMALS', 'OTHER')
        registry = FlagRegistry()

        @registry.register(flag=(FLAGS.PETS, FLAGS.FARM_ANIMALS,
                                 FLAGS.WILD_ANIMALS),
                           key=('pets', 'farm', 'wild'))
        def some_method():
            return 'cat', 'pig', 'rhino'

        @registry.register(flag=FLAGS.OTHER,
                           depends_on=FLAGS.PETS,
                           key='other')
        def method_other():
            pass

        method_flag, method_dependencies = registry._get_method_flag(
            some_method)

        self.assertEqual(method_flag,
                         FLAGS.PETS | FLAGS.FARM_ANIMALS | FLAGS.WILD_ANIMALS)
        self.assertEqual(method_dependencies, 0)

        method_flag, method_dependencies = registry._get_method_flag(
            method_other)

        self.assertEqual(method_flag, FLAGS.OTHER)
        self.assertEqual(method_dependencies, FLAGS.PETS)