Пример #1
0
    def test_replace_function_case_insensitive(self):
        class replaceable_func(GenericFunction):
            type = Integer
            identifier = 'replaceable_func'

        assert isinstance(func.Replaceable_Func().type, Integer)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer)
        assert isinstance(func.replaceable_func().type, Integer)

        with expect_warnings(
                "The GenericFunction 'replaceable_func' is already registered and "
                "is going to be overriden.",
                regex=False):

            class replaceable_func_override(GenericFunction):
                type = DateTime
                identifier = 'REPLACEABLE_Func'

        assert isinstance(func.Replaceable_Func().type, DateTime)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, DateTime)
        assert isinstance(func.replaceable_func().type, DateTime)
Пример #2
0
    def test_replace_function_case_sensitive(self):
        reg = functions._registry["_default"]
        cs_reg = functions._case_sensitive_registry["_default"]

        class replaceable_func(GenericFunction):
            type = Integer
            identifier = "REPLACEABLE_FUNC"

        assert isinstance(func.REPLACEABLE_FUNC().type, Integer)
        assert isinstance(func.Replaceable_Func().type, Integer)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer)
        assert isinstance(func.replaceable_func().type, Integer)

        in_("replaceable_func", reg)
        not_in_("REPLACEABLE_FUNC", reg)
        not_in_("Replaceable_Func", reg)
        in_("replaceable_func", cs_reg)
        eq_(set(cs_reg["replaceable_func"].keys()), set(["REPLACEABLE_FUNC"]))

        with testing.expect_deprecated(
                "GenericFunction 'Replaceable_Func' is already registered with"
                " different letter case, so the previously registered function "
                "'REPLACEABLE_FUNC' is switched into case-sensitive mode. "
                "GenericFunction objects will be fully case-insensitive in a "
                "future release.",
                regex=False,
        ):

            class Replaceable_Func(GenericFunction):
                type = DateTime
                identifier = "Replaceable_Func"

        assert isinstance(func.REPLACEABLE_FUNC().type, Integer)
        assert isinstance(func.Replaceable_Func().type, DateTime)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, NullType)
        assert isinstance(func.replaceable_func().type, NullType)

        eq_(reg["replaceable_func"], functions._CASE_SENSITIVE)
        not_in_("REPLACEABLE_FUNC", reg)
        not_in_("Replaceable_Func", reg)
        in_("replaceable_func", cs_reg)
        eq_(
            set(cs_reg["replaceable_func"].keys()),
            set(["REPLACEABLE_FUNC", "Replaceable_Func"]),
        )

        with testing.expect_warnings(
                "The GenericFunction 'REPLACEABLE_FUNC' is already registered and "
                "is going to be overriden.",
                regex=False,
        ):

            class replaceable_func_override(GenericFunction):
                type = DateTime
                identifier = "REPLACEABLE_FUNC"

        with testing.expect_deprecated(
                "GenericFunction(s) '['REPLACEABLE_FUNC', 'Replaceable_Func']' "
                "are already registered with different letter cases and might "
                "interact with 'replaceable_func'. GenericFunction objects will "
                "be fully case-insensitive in a future release.",
                regex=False,
        ):

            class replaceable_func_lowercase(GenericFunction):
                type = String
                identifier = "replaceable_func"

        with testing.expect_warnings(
                "The GenericFunction 'Replaceable_Func' is already registered and "
                "is going to be overriden.",
                regex=False,
        ):

            class Replaceable_Func_override(GenericFunction):
                type = Integer
                identifier = "Replaceable_Func"

        assert isinstance(func.REPLACEABLE_FUNC().type, DateTime)
        assert isinstance(func.Replaceable_Func().type, Integer)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, NullType)
        assert isinstance(func.replaceable_func().type, String)

        eq_(reg["replaceable_func"], functions._CASE_SENSITIVE)
        not_in_("REPLACEABLE_FUNC", reg)
        not_in_("Replaceable_Func", reg)
        in_("replaceable_func", cs_reg)
        eq_(
            set(cs_reg["replaceable_func"].keys()),
            set(["REPLACEABLE_FUNC", "Replaceable_Func", "replaceable_func"]),
        )