]> granicus.if.org Git - python/commitdiff
#11754: test contents of string module attributes.
authorR David Murray <rdmurray@bitdance.com>
Tue, 14 Apr 2015 00:04:29 +0000 (20:04 -0400)
committerR David Murray <rdmurray@bitdance.com>
Tue, 14 Apr 2015 00:04:29 +0000 (20:04 -0400)
As noted in the comment, while the order of the items in the attributes is not
technically guaranteed, after all this time there is almost certainly user
code out there that relies on it, so we might as well test for it.

Patch by Chalmer Lowe.

Lib/test/test_string.py
Misc/ACKS

index 85b5434e76f6f2ca9f6abe5f7aab8f4cff5508c9..5d37e164cfcd28c2f9993c00ff43f2beab7d1932 100644 (file)
@@ -4,15 +4,19 @@ import unittest, string
 class ModuleTest(unittest.TestCase):
 
     def test_attrs(self):
-        string.whitespace
-        string.ascii_lowercase
-        string.ascii_uppercase
-        string.ascii_letters
-        string.digits
-        string.hexdigits
-        string.octdigits
-        string.punctuation
-        string.printable
+        # While the exact order of the items in these attributes is not
+        # technically part of the "language spec", in practice there is almost
+        # certainly user code that depends on the order, so de-facto it *is*
+        # part of the spec.
+        self.assertEqual(string.whitespace, ' \t\n\r\x0b\x0c')
+        self.assertEqual(string.ascii_lowercase, 'abcdefghijklmnopqrstuvwxyz')
+        self.assertEqual(string.ascii_uppercase, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
+        self.assertEqual(string.ascii_letters, string.ascii_lowercase + string.ascii_uppercase)
+        self.assertEqual(string.digits, '0123456789')
+        self.assertEqual(string.hexdigits, string.digits + 'abcdefABCDEF')
+        self.assertEqual(string.octdigits, '01234567')
+        self.assertEqual(string.punctuation, '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~')
+        self.assertEqual(string.printable, string.digits + string.ascii_lowercase + string.ascii_uppercase + string.punctuation + string.whitespace)
 
     def test_capwords(self):
         self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
index eeb18699e17b5587076c92843307ac15dfdd4212..48d20ef0c337dad5161ca53590ede44236f7b7f7 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -850,6 +850,7 @@ Anne Lord
 Tom Loredo
 Justin Love
 Ned Jackson Lovely
+Chalmer Lowe
 Jason Lowe
 Tony Lownds
 Ray Loyzaga