예제 #1
0
class Shorter(OperatorTestCase):
    def test_length_value(self):
        ref = 12

        self.assert_match([], ref)
        self.assert_match([1], ref)
        self.assert_match("Alice", ref)

        self.assert_no_match(range(ref), ref)
        self.assert_no_match('x' * ref, ref)
        self.assert_no_match("Alice has a cat", ref)

    def test_sequence(self):
        ref = [1, 2, 3]

        for s in self.subsets(ref, strict=True):
            self.assert_match(list(s), ref)
        self.assert_match([42] * (len(ref) - 1), ref)

        self.assert_no_match(ref, ref)
        self.assert_no_match(2 * ref, ref)

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

    # Assertion functions

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

    def assert_no_match(self, value, ref):
        return super(Shorter, self) \
            .assert_no_match(__unit__.Shorter(ref), value)
예제 #2
0
 def assert_no_match(self, value, ref):
     return super(Shorter, self) \
         .assert_no_match(__unit__.Shorter(ref), value)