summaryrefslogtreecommitdiff
path: root/dev-python/pyrfc3339/files/pyrfc3339-1.1-pytest.patch
blob: 82dbbb32f3dc93aa553b67e46a73e036e87d3475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
https://github.com/kurtraschke/pyRFC3339/pull/16
From: Matthew Davis <github@virtual.drop.net>
Date: Thu, 7 Apr 2022 18:29:02 -0400
Subject: [PATCH] Remove python-nose requirements from tests

Converted nose related tests to pytest.
--- a/pyrfc3339/tests/tests.py
+++ b/pyrfc3339/tests/tests.py
@@ -8,12 +8,11 @@
 
 from pyrfc3339 import generate, parse
 from pyrfc3339.utils import timezone
+import unittest
+import pytest
 import pytz
 
-from nose.tools import eq_, raises
-
-
-class TestCore():
+class TestCore(unittest.TestCase):
     '''
     This test suite contains tests to address cases not tested in the doctests,
     as well as additional tests for end-to-end verification.
@@ -24,8 +23,11 @@ def test_timezone_rounding(self):
         Test rounding of timezone values to the nearest second.
 
         '''
-        eq_(timezone(5429), '+01:30')
-        eq_(timezone(5431), '+01:31')
+        if not timezone(5429) == '+01:30':
+            raise AssertionError("%r != %r" % (timezone(5429), '+01:30'))
+
+        if not timezone(5431) == '+01:31':
+            raise AssertionError("%r != %r" % (timezone(5431), '+01:31'))
 
     def test_zero_offset(self):
         '''
@@ -34,11 +36,13 @@ def test_zero_offset(self):
         '''
         timestamp = '2009-01-01T10:02:03+00:00'
         dt = parse(timestamp)
-        eq_(dt.tzinfo, pytz.utc)
+        if not dt.tzinfo == pytz.utc:
+            raise AssertionError("%r != %r" % (dt.tzinfo, pytz.utc))
 
         timestamp = '2009-01-01T10:02:03-00:00'
         dt = parse(timestamp)
-        eq_(dt.tzinfo, pytz.utc)
+        if not dt.tzinfo == pytz.utc:
+            raise AssertionError("%r != %r" % (dt.tzinfo, pytz.utc))
 
     def test_deepcopy(self):
         '''
@@ -56,7 +60,8 @@ def test_parse_microseconds(self):
         '''
         timestamp = '2009-01-01T10:02:03.25Z'
         dt = parse(timestamp)
-        eq_(dt.microsecond, 250000)
+        if not dt.microsecond == 250000:
+            raise AssertionError("%r != %r" % (dt.microsecond, 250000))
 
     def test_generate_microseconds(self):
         '''
@@ -65,7 +70,8 @@ def test_generate_microseconds(self):
         '''
         dt = datetime(2009, 1, 1, 10, 2, 3, 500000, pytz.utc)
         timestamp = generate(dt, microseconds=True)
-        eq_(timestamp, '2009-01-01T10:02:03.500000Z')
+        if not timestamp == '2009-01-01T10:02:03.500000Z':
+            raise AssertionError("%r != %r" % (timestamp, '2009-01-01T10:02:03.500000Z'))
 
     def test_mixed_case(self):
         '''
@@ -76,7 +82,8 @@ def test_mixed_case(self):
         dt1 = parse('2009-01-01t10:01:02z')
         dt2 = datetime(2009, 1, 1, 10, 1, 2, tzinfo=pytz.utc)
 
-        eq_(dt1, dt2)
+        if not dt1 == dt2:
+            raise AssertionError("%r != %r" % (dt1, dt2))
 
     def test_parse_naive_utc(self):
         '''
@@ -84,15 +91,17 @@ def test_parse_naive_utc(self):
 
         '''
         dt1 = parse('2009-01-01T10:01:02Z', produce_naive=True)
-        eq_(dt1.tzinfo, None)
+        if not dt1.tzinfo == None:
+            raise AssertionError("%r != %r" % (dt1.tzinfo, None))
 
-    @raises(ValueError)
     def test_parse_naive_local(self):
         '''
         Test that parsing a local timestamp to a naive datetime fails.
 
         '''
-        parse('2009-01-01T10:01:02-04:00', produce_naive=True)
+        with self.assertRaises(ValueError) as context:
+            parse('2009-01-01T10:01:02-04:00', produce_naive=True)
+
 
     def test_generate_utc_parse_utc(self):
         '''
@@ -103,7 +112,8 @@ def test_generate_utc_parse_utc(self):
         dt1 = dt1.replace(tzinfo=pytz.utc)
 
         dt2 = parse(generate(dt1, microseconds=True))
-        eq_(dt1, dt2)
+        if not dt1 == dt2:
+            raise AssertionError("%r != %r" % (dt1, dt2))
 
     def test_generate_local_parse_local(self):
         '''
@@ -113,7 +123,8 @@ def test_generate_local_parse_local(self):
         eastern = pytz.timezone('US/Eastern')
         dt1 = eastern.localize(datetime.utcnow())
         dt2 = parse(generate(dt1, utc=False, microseconds=True), utc=False)
-        eq_(dt1, dt2)
+        if not dt1 == dt2:
+            raise AssertionError("%r != %r" % (dt1, dt2))
 
     def test_generate_local_parse_utc(self):
         '''
@@ -123,10 +134,12 @@ def test_generate_local_parse_utc(self):
         eastern = pytz.timezone('US/Eastern')
         dt1 = eastern.localize(datetime.utcnow())
         dt2 = parse(generate(dt1, utc=False, microseconds=True))
-        eq_(dt1, dt2)
+        if not dt1 == dt2:
+            raise AssertionError("%r != %r" % (dt1, dt2))
 
 
-class TestExhaustiveRoundtrip():
+@pytest.mark.parametrize('tz_name', pytz.all_timezones)
+class TestExhaustiveRoundtrip:
     '''
     This test suite exhaustively tests parsing and generation by generating
     a local RFC 3339 timestamp for every timezone supported by pytz,
@@ -135,36 +148,32 @@ class TestExhaustiveRoundtrip():
 
     slow = True
 
-    def test_local_roundtrip(self):
-        for tz_name in pytz.all_timezones:
-            yield self.local_roundtrip, tz_name
-
-    def local_roundtrip(self, tz_name):
+    def test_local_roundtrip(self, tz_name):
         '''
         Generates a local datetime using the given timezone,
         produces a local timestamp from the datetime, parses the timestamp
         to a local datetime, and verifies that the two datetimes are equal.
 
         '''
-        tzinfo = pytz.timezone(tz_name)
-        dt1 = tzinfo.localize(datetime.utcnow())
-        timestamp = generate(dt1, utc=False, microseconds=True)
-        dt2 = parse(timestamp, utc=False)
-        eq_(dt1, dt2)
-
-    def test_utc_roundtrip(self):
-        for tz_name in pytz.all_timezones:
-            yield self.utc_roundtrip, tz_name
+        if not tz_name == 'leapseconds':
+            tzinfo = pytz.timezone(tz_name)
+            dt1 = tzinfo.localize(datetime.utcnow())
+            timestamp = generate(dt1, utc=False, microseconds=True)
+            dt2 = parse(timestamp, utc=False)
+            if not dt1 == dt2:
+                raise AssertionError("%r != %r" % (dt1, dt2))
 
-    def utc_roundtrip(self, tz_name):
+    def test_utc_roundtrip(self, tz_name):
         '''
         Generates a local datetime using the given timezone,
         produces a local timestamp from the datetime, parses the timestamp
         to a UTC datetime, and verifies that the two datetimes are equal.
 
         '''
-        tzinfo = pytz.timezone(tz_name)
-        dt1 = tzinfo.localize(datetime.utcnow())
-        timestamp = generate(dt1, utc=False, microseconds=True)
-        dt2 = parse(timestamp)
-        eq_(dt1, dt2)
+        if not tz_name == 'leapseconds':
+            tzinfo = pytz.timezone(tz_name)
+            dt1 = tzinfo.localize(datetime.utcnow())
+            timestamp = generate(dt1, utc=False, microseconds=True)
+            dt2 = parse(timestamp)
+            if not dt1 == dt2:
+                raise AssertionError("%r != %r" % (dt1, dt2))