~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_timestamp.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2007, 2009, 2010, 2011, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
58
58
        # offset of three minutes
59
59
        self.assertEqual((1173193459, +3 * 60),
60
60
            timestamp.parse_patch_date('2007-03-06 15:07:19 +0003'))
 
61
        # No space between time and offset
 
62
        self.assertEqual((1173193459, -5 * 3600),
 
63
            timestamp.parse_patch_date('2007-03-06 10:04:19-0500'))
 
64
        # Extra spacing
 
65
        self.assertEqual((1173193459, -5 * 3600),
 
66
            timestamp.parse_patch_date('2007-03-06     10:04:19     -0500'))
 
67
 
 
68
    def test_parse_patch_date_bad(self):
 
69
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
70
            'NOT A TIME')
 
71
        # Extra data at end
 
72
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
73
            '2007-03-06 10:04:19 -0500x')
 
74
        # Missing day
 
75
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
76
            '2007-03 10:04:19 -0500')
 
77
        # Missing seconds
 
78
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
79
            '2007-03-06 10:04 -0500')
 
80
        # Missing offset
 
81
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
82
            '2007-03-06 10:04:19')
 
83
        # Missing plus or minus in offset
 
84
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
85
            '2007-03-06 10:04:19 0500')
 
86
        # Invalid hour in offset
 
87
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
88
            '2007-03-06 10:04:19 +2400')
 
89
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
90
            '2007-03-06 10:04:19 -2400')
 
91
        # Invalid minute in offset
 
92
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
93
            '2007-03-06 10:04:19 -0560')
 
94
        # Too many digits in offset
 
95
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
96
            '2007-03-06 10:04:19 79500')
 
97
        # Minus sign in middle of offset
 
98
        self.assertRaises(ValueError, timestamp.parse_patch_date,
 
99
            '2007-03-06 10:04:19 +05-5')
61
100
 
62
101
 
63
102
class UnpackHighresDateTests(tests.TestCase):
64
103
 
65
104
    def test_unpack_highres_date(self):
66
 
        self.assertEquals(
 
105
        self.assertEqual(
67
106
            (1120153132.3508501, -18000),
68
107
            timestamp.unpack_highres_date('Thu 2005-06-30 12:38:52.350850105 -0500'))
69
 
        self.assertEquals(
 
108
        self.assertEqual(
70
109
            (1120153132.3508501, 0),
71
110
            timestamp.unpack_highres_date('Thu 2005-06-30 17:38:52.350850105 +0000'))
72
 
        self.assertEquals(
 
111
        self.assertEqual(
73
112
            (1120153132.3508501, 7200),
74
113
            timestamp.unpack_highres_date('Thu 2005-06-30 19:38:52.350850105 +0200'))
75
 
        self.assertEquals(
 
114
        self.assertEqual(
76
115
            (1152428738.867522, 19800),
77
116
            timestamp.unpack_highres_date('Sun 2006-07-09 12:35:38.867522001 +0530'))
78
117
 
80
119
        t = time.time()
81
120
        o = local_time_offset()
82
121
        t2, o2 = timestamp.unpack_highres_date(timestamp.format_highres_date(t, o))
83
 
        self.assertEquals(t, t2)
84
 
        self.assertEquals(o, o2)
 
122
        self.assertEqual(t, t2)
 
123
        self.assertEqual(o, o2)
85
124
        t -= 24*3600*365*2 # Start 2 years ago
86
125
        o = -12*3600
87
126
        for count in xrange(500):
89
128
            o = ((o/3600 + 13) % 25 - 12)*3600 # Add 1 wrap around from [-12, 12]
90
129
            date = timestamp.format_highres_date(t, o)
91
130
            t2, o2 = timestamp.unpack_highres_date(date)
92
 
            self.assertEquals(t, t2,
 
131
            self.assertEqual(t, t2,
93
132
                'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))
94
 
            self.assertEquals(o, o2,
 
133
            self.assertEqual(o, o2,
95
134
                'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))