def test_local_class__py33(self): class Class(object): def __call__(self, _): return True matcher = __unit__.Matching(Class) self.assertIn('<locals>.Class', repr(matcher))
def test_desc__trimmed(self): desc = "Long description with extraneous characters: %s" % ( "x" * __unit__.Matching.MAX_DESC_LENGTH, ) matcher = __unit__.Matching(bool, desc) self.assertNotIn(desc, repr(matcher)) self.assertIn("...", repr(matcher))
def test_desc__nonempty(self): desc = "Truthy" matcher = __unit__.Matching(bool, desc) self.assertIn(desc, repr(matcher))
def tesc_desc__empty(self): matcher = __unit__.Matching(bool, "") self.assertIn('""', repr(matcher))
def assert_no_match(self, value, predicate): return super(Matching, self) \ .assert_no_match(__unit__.Matching(predicate), value)
def test_invalid_predicate(self): with self.assertRaises(TypeError): __unit__.Matching(object())
def test_ctor__matcher(self): matcher = __unit__.Matching(bool) captor = __unit__.Captor(matcher) self.assertIs(matcher, captor.matcher)
class Captor(MatcherTestCase): ARG = object() FALSE_MATCHER = __unit__.Matching(lambda _: False) def test_ctor__no_args(self): captor = __unit__.Captor() self.assertIsInstance(captor.matcher, __unit__.Any) def test_ctor__invalid_matcher(self): not_matcher = object() with self.assertRaisesRegexp(TypeError, r'expected'): __unit__.Captor(not_matcher) def test_ctor__matcher(self): matcher = __unit__.Matching(bool) captor = __unit__.Captor(matcher) self.assertIs(matcher, captor.matcher) def test_ctor__captor(self): captor = __unit__.Captor() with self.assertRaisesRegexp(TypeError, r'captor'): __unit__.Captor(captor) def test_has_value__initial(self): captor = __unit__.Captor() self.assertFalse(captor.has_value()) def test_has_value__not_captured(self): # When the argument fails the matcher test, it should not be captured. captor = __unit__.Captor(self.FALSE_MATCHER) captor.match(self.ARG) self.assertFalse(captor.has_value()) def test_has_value__captured(self): captor = __unit__.Captor() captor.match(self.ARG) self.assertTrue(captor.has_value()) def test_arg__initial(self): captor = __unit__.Captor() with self.assertRaisesRegexp(ValueError, r'no value'): captor.arg def test_arg__not_captured(self): # When the argument fails the matcher test, it should not be captured. captor = __unit__.Captor(self.FALSE_MATCHER) captor.match(self.ARG) with self.assertRaisesRegexp(ValueError, r'no value'): captor.arg def test_arg__captured(self): captor = __unit__.Captor() captor.match(self.ARG) self.assertIs(self.ARG, captor.arg) def test_match__captured(self): captor = __unit__.Captor() self.assertTrue(captor.match(self.ARG)) def test_match___not_captured(self): captor = __unit__.Captor(self.FALSE_MATCHER) self.assertFalse(captor.match(self.ARG)) def test_match__double_capture(self): captor = __unit__.Captor() captor.match(self.ARG) with self.assertRaisesRegexp(ValueError, r'already'): captor.match(self.ARG) def test_repr__not_captured(self): captor = __unit__.Captor() self.assertNotIn("(*)", repr(captor)) def test_repr__captured(self): captor = __unit__.Captor() captor.match(self.ARG) self.assertIn("(*)", repr(captor))
def assert_named_repr(self, name, predicate): matcher = __unit__.Matching(predicate) self.assertIn(':' + name, repr(matcher))
def assert_lambda_repr(self, predicate): matcher = __unit__.Matching(predicate) self.assertIn('<lambda> ', repr(matcher)) # the space matters!
def test_callable_object(self): matcher = __unit__.Matching(Class()) self.assertIn('object at', repr(matcher))
def test_classmethod__function__py2(self): matcher = __unit__.Matching(MatchingRepr.classmethod_function) self.assertIn(' classmethod_function', repr(matcher))
def test_local_function__py33(self): def predicate(_): return True matcher = __unit__.Matching(predicate) self.assertIn('<locals>.predicate', repr(matcher))