def test_too_many_fields(self): # Python 3.5 removed the limit of 100 named groups in a regular expression, # so only test for the exception if the limit exists. try: re.compile("".join("(?P<n{n}>{n}-)".format(n=i) for i in range(101))) except AssertionError: p = parse.compile('{:ti}' * 15) self.assertRaises(parse.TooManyFields, p.parse, '')
def y(fmt, s, e, str_equals=False): p = parse.compile(fmt) r = p.parse(s) if r is None: self.fail('%r (%r) did not match %r' % (fmt, p._expression, s)) r = r.fixed[0] if str_equals: self.assertEqual(str(r), str(e), '%r found %r in %r, not %r' % (fmt, r, s, e)) else: self.assertEqual(r, e, '%r found %r in %r, not %r' % (fmt, r, s, e))
def y(fmt, s, e, tz=None): p = parse.compile(fmt) r = p.parse(s) if r is None: self.fail('%r (%r) did not match %r' % (fmt, p._expression, s)) r = r.fixed[0] try: self.assertEqual(r, e, '%r found %r in %r, not %r' % (fmt, r, s, e)) except ValueError: self.fail('%r found %r in %r, not %r' % (fmt, r, s, e)) if tz is not None: self.assertEqual(r.tzinfo, tz, '%r found TZ %r in %r, not %r' % (fmt, r.tzinfo, s, e))
def y(fmt, s, e, tz=None): p = parse.compile(fmt) r = p.parse(s) if r is None: self.fail('%r (%r) did not match %r' % (fmt, p._expression, s)) r = r.fixed[0] try: self.assertEqual(r, e, '%r found %r in %r, not %r' % (fmt, r, s, e)) except ValueError: self.fail('%r found %r in %r, not %r' % (fmt, r, s, e)) if tz is not None: self.assertEqual( r.tzinfo, tz, '%r found TZ %r in %r, not %r' % (fmt, r.tzinfo, s, e))
def __init__(self, func, string, step_type=None): super(ParseMatcher, self).__init__(func, string, step_type) self.parser = parse.compile(self.string, self.custom_types)
def test_too_many_fields(self): p = parse.compile('{:ti}' * 15) self.assertRaises(parse.TooManyFields, p.parse, '')