Ejemplo n.º 1
0
    def testcomplex02(self):
        @typeconstraints([
            int,
            ARRAYOF(
                ARRAYOF(
                    MIXEDDICT({
                        "foo": str,
                        "bar": ANYOF([int, float]),
                        "baz": NONNABLE(bool)
                    })))
        ])
        def foo25(num, dct):
            return True

        self.assertRaises(AssertionError, foo25, 42, [[{
            "foo": "bilbo",
            "bar": 17,
            "baz": True
        }, {
            "foo": "frodo",
            "bar": 3.1414926,
            "baz": False
        }], [{
            "foo": "peppin",
            "bar": 11,
            "baz": "NOTGOOD"
        }]])
Ejemplo n.º 2
0
    def testmixeddict03(self):
        @typeconstraints([
            int,
            MIXEDDICT({
                "bar": str,
                "baz": float,
                "qux": bool
            },
                      optionals=["qux"])
        ])
        def foo21(num, dct):
            return True

        self.assertTrue(foo21(42, {"bar": "Bushmills", "baz": 3.1415927}))
Ejemplo n.º 3
0
    def testmixeddict02(self):
        @typeconstraints(
            [int, MIXEDDICT({
                "bar": str,
                "baz": float,
                "qux": bool
            })])
        def foo20(num, dct):
            return True

        self.assertRaises(AssertionError, foo20, 42, {
            "bar": "Bushmills",
            "baz": 3.1415927,
            "qux": 17
        })
Ejemplo n.º 4
0
    def testmixeddict01(self):
        @typeconstraints(
            [int, MIXEDDICT({
                "bar": str,
                "baz": float,
                "qux": bool
            })])
        def foo19(num, dct):
            return True

        self.assertTrue(
            foo19(42, {
                "bar": "Bushmills",
                "baz": 3.1415927,
                "qux": False
            }))
Ejemplo n.º 5
0
    def testmixeddict06(self):
        @typeconstraints([
            int,
            MIXEDDICT({
                "bar": str,
                "baz": float,
                "qux": bool
            },
                      ignore_extra=False)
        ])
        def foo24(num, dct):
            return True

        self.assertRaises(AssertionError, foo24, 42, {
            "bar": "Bushmills",
            "baz": 3.1415927,
            "qux": False,
            "quux": 17
        })
Ejemplo n.º 6
0
    def testmixeddict05(self):
        @typeconstraints([
            int,
            MIXEDDICT({
                "bar": str,
                "baz": float,
                "qux": bool
            },
                      ignore_extra=True)
        ])
        def foo23(num, dct):
            return True

        self.assertTrue(
            foo23(42, {
                "bar": "Bushmills",
                "baz": 3.1415927,
                "qux": False,
                "quux": 17
            }))