summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email/test_utils.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-07-20 15:41:21 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-07-20 15:41:21 (GMT)
commit875048bd4c95ae90c3e541cad681b11436ce1f3f (patch)
treeebd084a91ec6a66f3747cfd16b013da25b9654c1 /Lib/test/test_email/test_utils.py
parent3e44612726ff8be8b7b43aa9043441206a35a08f (diff)
downloadcpython-875048bd4c95ae90c3e541cad681b11436ce1f3f.zip
cpython-875048bd4c95ae90c3e541cad681b11436ce1f3f.tar.gz
cpython-875048bd4c95ae90c3e541cad681b11436ce1f3f.tar.bz2
#665194: support roundtripping RFC2822 date stamps in the email.utils module
Diffstat (limited to 'Lib/test/test_email/test_utils.py')
-rw-r--r--Lib/test/test_email/test_utils.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_utils.py b/Lib/test/test_email/test_utils.py
new file mode 100644
index 0000000..e003a64
--- /dev/null
+++ b/Lib/test/test_email/test_utils.py
@@ -0,0 +1,45 @@
+import datetime
+from email import utils
+import unittest
+
+class DateTimeTests(unittest.TestCase):
+
+ datestring = 'Sun, 23 Sep 2001 20:10:55'
+ dateargs = (2001, 9, 23, 20, 10, 55)
+ offsetstring = ' -0700'
+ utcoffset = datetime.timedelta(hours=-7)
+ tz = datetime.timezone(utcoffset)
+ naive_dt = datetime.datetime(*dateargs)
+ aware_dt = datetime.datetime(*dateargs, tzinfo=tz)
+
+ def test_naive_datetime(self):
+ self.assertEqual(utils.format_datetime(self.naive_dt),
+ self.datestring + ' -0000')
+
+ def test_aware_datetime(self):
+ self.assertEqual(utils.format_datetime(self.aware_dt),
+ self.datestring + self.offsetstring)
+
+ def test_usegmt(self):
+ utc_dt = datetime.datetime(*self.dateargs,
+ tzinfo=datetime.timezone.utc)
+ self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
+ self.datestring + ' GMT')
+
+ def test_usegmt_with_naive_datetime_raises(self):
+ with self.assertRaises(ValueError):
+ utils.format_datetime(self.naive_dt, usegmt=True)
+
+ def test_usegmt_with_non_utc_datetime_raises(self):
+ with self.assertRaises(ValueError):
+ utils.format_datetime(self.aware_dt, usegmt=True)
+
+ def test_parsedate_to_datetime(self):
+ self.assertEqual(
+ utils.parsedate_to_datetime(self.datestring + self.offsetstring),
+ self.aware_dt)
+
+ def test_parsedate_to_datetime_naive(self):
+ self.assertEqual(
+ utils.parsedate_to_datetime(self.datestring + ' -0000'),
+ self.naive_dt)