Beispiel #1
0
    def test_match_type_strict_no_match(self):
        tests = {
            str: String('spam'),
            int: Integer(10),
        }
        for datatype, value in tests.items():
            with self.subTest(datatype):
                param = SimpleParameter(datatype, strict=True)
                handler = param.match_type(value)

                self.assertIs(handler, None)
Beispiel #2
0
    def test_match_type_strict_match(self):
        tests = {
            str: 'spam',
            int: 10,
            bool: True,
        }
        for datatype, value in tests.items():
            with self.subTest(datatype):
                param = SimpleParameter(datatype, strict=True)
                handler = param.match_type(value)

                self.assertIs(handler.datatype, datatype)
Beispiel #3
0
    def test_match_type_match(self):
        tests = [
            (str, 'spam'),
            (str, String('spam')),
            (int, 10),
            (bool, True),
        ]
        for datatype, value in tests:
            with self.subTest((datatype, value)):
                param = SimpleParameter(datatype, strict=False)
                handler = param.match_type(value)

                self.assertIs(handler.datatype, datatype)
Beispiel #4
0
    def test_match_type_no_match(self):
        tests = [
            (int, 'spam'),
            # coercible
            (str, 10),
            (int, 10.0),
            (int, '10'),
            (bool, 1),
            # semi-coercible
            (str, b'spam'),
            (int, 10 + 0j),
            (int, b'\10'),
        ]
        for datatype, value in tests:
            with self.subTest((datatype, value)):
                param = SimpleParameter(datatype, strict=False)
                handler = param.match_type(value)

                self.assertIs(handler, None)