def test_parse_date(self): # parse_date(from_timestamp()) must return the tuple unchanged for timestamp, offset in (1522827734, -7200), (1522827734, 0), (1522827734, +3600): self.assertEqual(parse_date(from_timestamp(timestamp, offset)), (timestamp, offset)) # test all supported formats def assert_rval(rval, veri_time, offset=0): self.assertEqual(len(rval), 2) self.assertIsInstance(rval[0], int) self.assertIsInstance(rval[1], int) self.assertEqual(rval[0], veri_time) self.assertEqual(rval[1], offset) # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) self.assertIsInstance(utctz, str) self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset) # END assert rval utility rfc = ("Thu, 07 Apr 2005 22:13:11 +0000", 0) iso = ("2005-04-07T22:13:11 -0200", 7200) iso2 = ("2005-04-07 22:13:11 +0400", -14400) iso3 = ("2005.04.07 22:13:11 -0000", 0) alt = ("04/07/2005 22:13:11", 0) alt2 = ("07.04.2005 22:13:11", 0) veri_time_utc = 1112911991 # the time this represents, in time since epoch, UTC for date, offset in (rfc, iso, iso2, iso3, alt, alt2): assert_rval(parse_date(date), veri_time_utc, offset) # END for each date type # and failure self.assertRaises(ValueError, parse_date, datetime.now()) # non-aware datetime self.assertRaises(ValueError, parse_date, 'invalid format') self.assertRaises(ValueError, parse_date, '123456789 -02000') self.assertRaises(ValueError, parse_date, ' 123456789 -0200')
def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. :param line: line bytes without trailing newline :raise ValueError: If line could not be parsed""" line = line.decode(defenc) fields = line.split('\t', 1) if len(fields) == 1: info, msg = fields[0], None elif len(fields) == 2: info, msg = fields else: raise ValueError("Line must have up to two TAB-separated fields." " Got %s" % repr(line)) # END handle first split oldhexsha = info[:40] newhexsha = info[41:81] for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): raise ValueError("Invalid hexsha: %r" % (hexsha,)) # END if hexsha re doesn't match # END for each hexsha email_end = info.find('>', 82) if email_end == -1: raise ValueError("Missing token: >") # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) time, tz_offset = parse_date(info[email_end + 2:]) return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg))
def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. :param line: line without trailing newline :raise ValueError: If line could not be parsed""" try: info, msg = line.split('\t', 2) except ValueError: raise ValueError("line is missing tab separator") #END handle first plit oldhexsha = info[:40] newhexsha = info[41:81] for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): raise ValueError("Invalid hexsha: %s" % hexsha) # END if hexsha re doesn't match #END for each hexsha email_end = info.find('>', 82) if email_end == -1: raise ValueError("Missing token: >") #END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) time, tz_offset = parse_date(info[email_end + 2:]) return RefLogEntry( (oldhexsha, newhexsha, actor, (time, tz_offset), msg))
def test_parse_date(self): # test all supported formats def assert_rval(rval, veri_time, offset=0): self.assertEqual(len(rval), 2) self.assertIsInstance(rval[0], int) self.assertIsInstance(rval[1], int) self.assertEqual(rval[0], veri_time) self.assertEqual(rval[1], offset) # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) self.assertIsInstance(utctz, string_types) self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset) # END assert rval utility rfc = ("Thu, 07 Apr 2005 22:13:11 +0000", 0) iso = ("2005-04-07T22:13:11 -0200", 7200) iso2 = ("2005-04-07 22:13:11 +0400", -14400) iso3 = ("2005.04.07 22:13:11 -0000", 0) alt = ("04/07/2005 22:13:11", 0) alt2 = ("07.04.2005 22:13:11", 0) veri_time_utc = 1112911991 # the time this represents, in time since epoch, UTC for date, offset in (rfc, iso, iso2, iso3, alt, alt2): assert_rval(parse_date(date), veri_time_utc, offset) # END for each date type # and failure self.failUnlessRaises(ValueError, parse_date, 'invalid format') self.failUnlessRaises(ValueError, parse_date, '123456789 -02000') self.failUnlessRaises(ValueError, parse_date, ' 123456789 -0200')
def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. :param line: line without trailing newline :raise ValueError: If line could not be parsed""" try: info, msg = line.split('\t', 2) except ValueError: raise ValueError("line is missing tab separator") # END handle first plit oldhexsha = info[:40] newhexsha = info[41:81] for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): raise ValueError("Invalid hexsha: %s" % hexsha) # END if hexsha re doesn't match # END for each hexsha email_end = info.find('>', 82) if email_end == -1: raise ValueError("Missing token: >") # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) time, tz_offset = parse_date(info[email_end + 2:]) return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg))
def test_parse_date(self): # test all supported formats def assert_rval(rval, veri_time, offset=0): assert len(rval) == 2 assert isinstance(rval[0], int) and isinstance(rval[1], int) assert rval[0] == veri_time assert rval[1] == offset # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) assert isinstance(utctz, string_types) assert utctz_to_altz(verify_utctz(utctz)) == offset # END assert rval utility rfc = ("Thu, 07 Apr 2005 22:13:11 +0000", 0) iso = ("2005-04-07T22:13:11 -0200", 7200) iso2 = ("2005-04-07 22:13:11 +0400", -14400) iso3 = ("2005.04.07 22:13:11 -0000", 0) alt = ("04/07/2005 22:13:11", 0) alt2 = ("07.04.2005 22:13:11", 0) veri_time_utc = 1112911991 # the time this represents, in time since epoch, UTC for date, offset in (rfc, iso, iso2, iso3, alt, alt2): assert_rval(parse_date(date), veri_time_utc, offset) # END for each date type # and failure self.failUnlessRaises(ValueError, parse_date, 'invalid format') self.failUnlessRaises(ValueError, parse_date, '123456789 -02000') self.failUnlessRaises(ValueError, parse_date, ' 123456789 -0200')