Rev 5581: (jelmer) Convert the doctest on bzrlib.timestamp.unpack_highres_date to a in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Dec 27 02:39:12 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5581 [merge]
revision-id: pqm at pqm.ubuntu.com-20101227023912-prd8bqcc4gzmrzb6
parent: pqm at pqm.ubuntu.com-20101224195728-86ec24997aplx1l0
parent: jelmer at samba.org-20101224231544-wlh932a07xv52k1y
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2010-12-27 02:39:12 +0000
message:
(jelmer) Convert the doctest on bzrlib.timestamp.unpack_highres_date to a
unit test. (Jelmer Vernooij)
modified:
bzrlib/tests/test_timestamp.py test_timestamp.py-20070306153932-r3ejn242c20asagv-1
bzrlib/timestamp.py timestamp.py-20070306142322-ttbb9oulf3jotljd-1
=== modified file 'bzrlib/tests/test_timestamp.py'
--- a/bzrlib/tests/test_timestamp.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_timestamp.py 2010-12-24 23:15:44 +0000
@@ -14,10 +14,16 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import random
+import time
+
+
from bzrlib import (
tests,
timestamp,
)
+from bzrlib.osutils import local_time_offset
+
class TestPatchHeader(tests.TestCase):
@@ -52,3 +58,38 @@
# offset of three minutes
self.assertEqual((1173193459, +3 * 60),
timestamp.parse_patch_date('2007-03-06 15:07:19 +0003'))
+
+
+class UnpackHighresDateTests(tests.TestCase):
+
+ def test_unpack_highres_date(self):
+ self.assertEquals(
+ (1120153132.3508501, -18000),
+ timestamp.unpack_highres_date('Thu 2005-06-30 12:38:52.350850105 -0500'))
+ self.assertEquals(
+ (1120153132.3508501, 0),
+ timestamp.unpack_highres_date('Thu 2005-06-30 17:38:52.350850105 +0000'))
+ self.assertEquals(
+ (1120153132.3508501, 7200),
+ timestamp.unpack_highres_date('Thu 2005-06-30 19:38:52.350850105 +0200'))
+ self.assertEquals(
+ (1152428738.867522, 19800),
+ timestamp.unpack_highres_date('Sun 2006-07-09 12:35:38.867522001 +0530'))
+
+ def test_random(self):
+ t = time.time()
+ o = local_time_offset()
+ t2, o2 = timestamp.unpack_highres_date(timestamp.format_highres_date(t, o))
+ self.assertEquals(t, t2)
+ self.assertEquals(o, o2)
+ t -= 24*3600*365*2 # Start 2 years ago
+ o = -12*3600
+ for count in xrange(500):
+ t += random.random()*24*3600*30
+ o = ((o/3600 + 13) % 25 - 12)*3600 # Add 1 wrap around from [-12, 12]
+ date = timestamp.format_highres_date(t, o)
+ t2, o2 = timestamp.unpack_highres_date(date)
+ self.assertEquals(t, t2,
+ 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))
+ self.assertEquals(o, o2,
+ 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))
=== modified file 'bzrlib/timestamp.py'
--- a/bzrlib/timestamp.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/timestamp.py 2010-12-24 23:15:44 +0000
@@ -72,34 +72,6 @@
:param date: A date formated by format_highres_date
:type date: string
- >>> import time, random
- >>> unpack_highres_date('Thu 2005-06-30 12:38:52.350850105 -0500')
- (1120153132.3508501, -18000)
- >>> unpack_highres_date('Thu 2005-06-30 17:38:52.350850105 +0000')
- (1120153132.3508501, 0)
- >>> unpack_highres_date('Thu 2005-06-30 19:38:52.350850105 +0200')
- (1120153132.3508501, 7200)
- >>> unpack_highres_date('Sun 2006-07-09 12:35:38.867522001 +0530')
- (1152428738.867522, 19800)
- >>> from bzrlib.osutils import local_time_offset
- >>> t = time.time()
- >>> o = local_time_offset()
- >>> t2, o2 = unpack_highres_date(format_highres_date(t, o))
- >>> t == t2
- True
- >>> o == o2
- True
- >>> t -= 24*3600*365*2 # Start 2 years ago
- >>> o = -12*3600
- >>> for count in xrange(500):
- ... t += random.random()*24*3600*30
- ... o = ((o/3600 + 13) % 25 - 12)*3600 # Add 1 wrap around from [-12, 12]
- ... date = format_highres_date(t, o)
- ... t2, o2 = unpack_highres_date(date)
- ... if t != t2 or o != o2:
- ... print 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t)
- ... break
-
"""
# Weekday parsing is locale sensitive, so drop the weekday
space_loc = date.find(' ')
More information about the bazaar-commits
mailing list