diff Lib/test/test_bytes.py @ 40894:0ea24f4f2467

Bytes literal.
author Thomas Wouters <thomas@python.org>
date Fri, 23 Feb 2007 19:56:57 +0000
parents 1c26505c1de6
children b58a4374ac21
line wrap: on
line diff
--- a/Lib/test/test_bytes.py	Fri Feb 23 15:07:44 2007 +0000
+++ b/Lib/test/test_bytes.py	Fri Feb 23 19:56:57 2007 +0000
@@ -403,7 +403,19 @@
             self.assertEqual(bytes.join(tuple(lst)), bytes("abc"))
             self.assertEqual(bytes.join(iter(lst)), bytes("abc"))
         # XXX more...
-            
+
+    def test_literal(self):
+        tests =  [
+            (b"Wonderful spam", u"Wonderful spam"),
+            (br"Wonderful spam too", u"Wonderful spam too"),
+            (b"\xaa\x00\000\200", u"\xaa\x00\000\200"),
+            (br"\xaa\x00\000\200", ur"\xaa\x00\000\200"),
+        ]
+        for b, s in tests:
+            self.assertEqual(b, bytes(s, 'latin-1'))
+        for c in range(128, 256):
+            self.assertRaises(SyntaxError, eval,
+                              'b"%s"' % chr(c))
 
     # Optimizations:
     # __iter__? (optimization)