Esempio n. 1
0
class Contains(OperatorTestCase):
    def test_lists(self):
        ref = 42

        self.assert_no_match([], ref)
        self.assert_no_match(list(range(ref)), ref)

        self.assert_match([ref], ref)
        self.assert_match([None, ref], ref)
        self.assert_match(list(range(ref + 1)), ref)

    def test_strings(self):
        ref = 'x'

        self.assert_no_match('', ref)

        self.assert_match(ref, ref)
        self.assert_match(ref + 'foo', ref)

    def test_sets(self):
        ref = 42

        self.assert_no_match(set(), ref)
        self.assert_no_match(set(range(ref)), ref)

        self.assert_match(set([ref]), ref)
        self.assert_match(set([None, ref]), ref)
        self.assert_match(set(range(ref + 1)), ref)

    test_repr = lambda self: self.assert_repr(__unit__.Contains(42))

    # Assertion functions

    def assert_match(self, value, ref):
        return super(Contains, self) \
            .assert_match(__unit__.Contains(ref), value)

    def assert_no_match(self, value, ref):
        return super(Contains, self) \
            .assert_no_match(__unit__.Contains(ref), value)
Esempio n. 2
0
 def assert_no_match(self, value, ref):
     return super(Contains, self) \
         .assert_no_match(__unit__.Contains(ref), value)