1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Factored skip condition when pytz isn't installed.

This commit is contained in:
Aymeric Augustin
2015-05-03 09:08:37 +02:00
parent da2c6959c8
commit 06dc6759d8
2 changed files with 16 additions and 12 deletions

View File

@@ -11,6 +11,8 @@ try:
except ImportError:
pytz = None
requires_pytz = unittest.skipIf(pytz is None, "this test requires pytz")
if pytz is not None:
CET = pytz.timezone("Europe/Paris")
EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi
@@ -137,7 +139,7 @@ class TimezoneTests(unittest.TestCase):
with self.assertRaises(ValueError):
timezone.make_naive(datetime.datetime(2011, 9, 1, 13, 20, 30), EAT)
@unittest.skipIf(pytz is None, "this test requires pytz")
@requires_pytz
def test_make_aware2(self):
self.assertEqual(
timezone.make_aware(datetime.datetime(2011, 9, 1, 12, 20, 30), CET),
@@ -145,7 +147,7 @@ class TimezoneTests(unittest.TestCase):
with self.assertRaises(ValueError):
timezone.make_aware(CET.localize(datetime.datetime(2011, 9, 1, 12, 20, 30)), CET)
@unittest.skipIf(pytz is None, "this test requires pytz")
@requires_pytz
def test_make_aware_pytz(self):
self.assertEqual(
timezone.make_naive(CET.localize(datetime.datetime(2011, 9, 1, 12, 20, 30)), CET),
@@ -156,7 +158,7 @@ class TimezoneTests(unittest.TestCase):
with self.assertRaises(ValueError):
timezone.make_naive(datetime.datetime(2011, 9, 1, 12, 20, 30), CET)
@unittest.skipIf(pytz is None, "this test requires pytz")
@requires_pytz
def test_make_aware_pytz_ambiguous(self):
# 2:30 happens twice, once before DST ends and once after
ambiguous = datetime.datetime(2015, 10, 25, 2, 30)
@@ -170,7 +172,7 @@ class TimezoneTests(unittest.TestCase):
self.assertEqual(std.tzinfo.utcoffset(std), datetime.timedelta(hours=1))
self.assertEqual(dst.tzinfo.utcoffset(dst), datetime.timedelta(hours=2))
@unittest.skipIf(pytz is None, "this test requires pytz")
@requires_pytz
def test_make_aware_pytz_non_existent(self):
# 2:30 never happened due to DST
non_existent = datetime.datetime(2015, 3, 29, 2, 30)