use a proper patch file for pytest support instead of changing the source file directly

Sources are supposed to be unmodified upstream versions.
This commit is contained in:
Felix Schwarz 2022-04-08 22:47:21 +02:00
commit 4c494443b7
3 changed files with 238 additions and 49 deletions

View file

@ -0,0 +1,195 @@
commit a863d1a3c90944b90685680af4dad5d8c7dbc0da
Author: Matthew Davis <redhat-developer@virtual.drop.net>
Date: Fri Jan 28 16:42:42 2022 -0500
Converted tests from python-nose to pytest
diff --git a/tests.py b/tests.py
index 831daab..d4c7622 100644
--- a/tests.py
+++ b/tests.py
@@ -8,12 +8,11 @@ from copy import deepcopy
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 @@ class TestCore():
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 @@ class TestCore():
'''
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 @@ class TestCore():
'''
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 @@ class TestCore():
'''
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 @@ class TestCore():
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 @@ class TestCore():
'''
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 @@ class TestCore():
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 @@ class TestCore():
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 @@ class TestCore():
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))

View file

@ -12,6 +12,8 @@ Source0: %{pypi_source}
# https://raw.githubusercontent.com/kurtraschke/pyRFC3339/master/pyrfc3339/tests/tests.py
# v1.1: git commit e30cc155
Source1: https://raw.githubusercontent.com/kurtraschke/pyRFC3339/e30cc1555adce0ecc7bd65509a2249d47e5a41b4/pyrfc3339/tests/tests.py
# basically the same as https://github.com/kurtraschke/pyRFC3339/pull/16
Patch1: pyrfc3339-use-pytest-in-tests.patch
BuildArch: noarch
@ -37,7 +39,9 @@ RFC 3339-compliant timestamps using Python datetime.datetime objects.
%prep
%autosetup -n %{srcname}-%{version}
%autosetup -n %{srcname}-%{version} -N
cp -a %{SOURCE1} .
%patch1 -p1
%build
%pyproject_wheel
@ -47,7 +51,6 @@ RFC 3339-compliant timestamps using Python datetime.datetime objects.
%pyproject_save_files pyrfc3339
%check
cp -a %{SOURCE1} .
%pytest -v tests.py
%files -n python3-pyrfc3339 -f %{pyproject_files}

View file

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