Exemplo n.º 1
0
    def test_repr(self):
        def userfunc(x):
            return True

        matcher = _get_matcher(userfunc)
        self.assertEqual(repr(matcher), 'userfunc')

        userlambda = lambda x: True
        matcher = _get_matcher(userlambda)
        self.assertEqual(repr(matcher), '<lambda>')
Exemplo n.º 2
0
    def test_identity(self):
        def always_false(x):
            return False

        matcher = _get_matcher(always_false)

        self.assertTrue(matcher == always_false)
Exemplo n.º 3
0
    def test_identity_with_error(self):
        def fails_internally(x):  # <- Helper function.
            raise TypeError('raising an error')

        matcher = _get_matcher(fails_internally)

        self.assertTrue(matcher == fails_internally)
Exemplo n.º 4
0
    def test_isinstance(self):
        matcher = _get_matcher(int)

        self.assertTrue(matcher == 0)
        self.assertTrue(matcher == 1)
        self.assertFalse(matcher == 0.0)
        self.assertFalse(matcher == 1.0)
Exemplo n.º 5
0
    def test_error(self):
        def fails_internally(x):  # <- Helper function.
            raise TypeError('raising an error')

        matcher = _get_matcher(fails_internally)

        with self.assertRaises(TypeError):
            self.assertFalse(matcher == 'abc')
Exemplo n.º 6
0
    def test_error(self):
        matcher = _get_matcher(re.compile('abc'))

        with self.assertRaisesRegex(TypeError, "got int: 123"):
            self.assertFalse(matcher == 123)  # Regex fails with TypeError.

        with self.assertRaisesRegex(TypeError, "got tuple: \('a', 'b'\)"):
            self.assertFalse(matcher == ('a', 'b'))
Exemplo n.º 7
0
    def test_returned_difference(self):
        """If predicate function returns a difference object, it
        should count as False.
        """
        def true_or_difference(x):
            return x == 'foo' or Missing(x)

        matcher = _get_matcher(true_or_difference)

        self.assertTrue(matcher == 'foo')
        self.assertFalse(matcher == 'bar')
Exemplo n.º 8
0
    def test_equality(self):
        def divisible3or5(x):  # <- Helper function.
            return (x % 3 == 0) or (x % 5 == 0)

        matcher = _get_matcher(divisible3or5)

        self.assertFalse(matcher == 1)
        self.assertFalse(matcher == 2)
        self.assertTrue(matcher == 3)
        self.assertFalse(matcher == 4)
        self.assertTrue(matcher == 5)
        self.assertTrue(matcher == 6)
Exemplo n.º 9
0
    def test_equality(self):
        matcher = _get_matcher(re.compile('(Ch|H)ann?ukk?ah?'))

        self.assertTrue(matcher == 'Happy Hanukkah')
        self.assertTrue(matcher == 'Happy Chanukah')
        self.assertFalse(matcher == 'Merry Christmas')
Exemplo n.º 10
0
    def test_repr(self):
        matcher = _get_matcher(Ellipsis)

        self.assertEqual(repr(matcher), '...')
Exemplo n.º 11
0
    def test_equality(self):
        matcher = _get_matcher(Ellipsis)

        self.assertTrue(matcher == 1)
        self.assertTrue(matcher == object())
        self.assertTrue(matcher == None)
Exemplo n.º 12
0
    def test_repr(self):
        matcher = _get_matcher(set(['a']))

        self.assertEqual(repr(matcher), repr(set(['a'])))
Exemplo n.º 13
0
    def test_whole_set_equality(self):
        matcher = _get_matcher(set(['a', 'b', 'c']))

        self.assertTrue(matcher == set(['a', 'b', 'c']))
Exemplo n.º 14
0
    def test_equality(self):
        matcher = _get_matcher(set(['a', 'e', 'i', 'o', 'u']))

        self.assertTrue(matcher == 'a')
        self.assertFalse(matcher == 'x')
Exemplo n.º 15
0
    def test_repr(self):
        matcher = _get_matcher(re.compile('abc'))

        self.assertEqual(repr(matcher), "re.compile('abc')")
Exemplo n.º 16
0
    def test_identity(self):
        regex = re.compile('abc')
        matcher = _get_matcher(regex)

        self.assertTrue(matcher == regex)