Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r63216:2a1f15301125
Date: 2013-04-10 19:15 -0400
http://bitbucket.org/pypy/pypy/changeset/2a1f15301125/

Log:    test for string_escape decode errors

diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -53,26 +53,25 @@
     def test_unicodedecodeerror(self):
         assert str(UnicodeDecodeError(
             "ascii", "g\xfcrk", 1, 2, "ouch")) == "'ascii' codec can't decode 
byte 0xfc in position 1: ouch"
-        
+
         assert str(UnicodeDecodeError(
             "ascii", "g\xfcrk", 1, 3, "ouch")) == "'ascii' codec can't decode 
bytes in position 1-2: ouch"
-        
 
     def test_unicodetranslateerror(self):
         import sys
         assert str(UnicodeTranslateError(
             u"g\xfcrk", 1, 2, "ouch"))== "can't translate character u'\\xfc' 
in position 1: ouch"
-        
+
         assert str(UnicodeTranslateError(
             u"g\u0100rk", 1, 2, "ouch"))== "can't translate character 
u'\\u0100' in position 1: ouch"
-        
+
         assert str(UnicodeTranslateError(
             u"g\uffffrk", 1, 2, "ouch"))== "can't translate character 
u'\\uffff' in position 1: ouch"
-        
+
         if sys.maxunicode > 0xffff and len(unichr(0x10000)) == 1:
             assert str(UnicodeTranslateError(
                 u"g\U00010000rk", 1, 2, "ouch"))== "can't translate character 
u'\\U00010000' in position 1: ouch"
-            
+
         assert str(UnicodeTranslateError(
             u"g\xfcrk", 1, 3, "ouch"))=="can't translate characters in 
position 1-2: ouch"
 
@@ -80,22 +79,22 @@
         import sys
         assert str(UnicodeEncodeError(
             "ascii", u"g\xfcrk", 1, 2, "ouch"))=="'ascii' codec can't encode 
character u'\\xfc' in position 1: ouch"
-            
+
         assert str(UnicodeEncodeError(
             "ascii", u"g\xfcrk", 1, 4, "ouch"))== "'ascii' codec can't encode 
characters in position 1-3: ouch"
-            
+
         assert str(UnicodeEncodeError(
             "ascii", u"\xfcx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\xfc' in position 0: ouch"
 
         assert str(UnicodeEncodeError(
             "ascii", u"\u0100x", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\u0100' in position 0: ouch"
-       
+
         assert str(UnicodeEncodeError(
             "ascii", u"\uffffx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\uffff' in position 0: ouch"
         if sys.maxunicode > 0xffff and len(unichr(0x10000)) == 1:
             assert str(UnicodeEncodeError(
                 "ascii", u"\U00010000x", 0, 1, "ouch")) =="'ascii' codec can't 
encode character u'\\U00010000' in position 0: ouch"
-    
+
     def test_indexerror(self):
         test =   "\\"     # trailing backslash
         raises (ValueError, test.decode,'string-escape')
@@ -136,7 +135,7 @@
                 u"\x00\xff\u07ff\u0800",
                 u"\x00\xff\u07ff\u0800\uffff",
             ]
-            
+
         buffer = ''
         result = u""
         for (c, partialresult) in 
zip(u"\x00\xff\u07ff\u0800\uffff".encode(encoding), check_partial):
@@ -173,13 +172,12 @@
             assert result == partialresult
 
     def test_bug1098990_a(self):
-
         import codecs, StringIO
         self.encoding = 'utf-8'
         s1 = u"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n"
         s2 = u"offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj 
laskd fjasklfzzzzaa%whereisthis!!!\r\n"
         s3 = u"next line.\r\n"
-       
+
         s = (s1+s2+s3).encode(self.encoding)
         stream = StringIO.StringIO(s)
         reader = codecs.getreader(self.encoding)(stream)
@@ -205,8 +203,8 @@
         assert reader.readline() == s3
         assert reader.readline() == s4
         assert reader.readline() == s5
-        assert reader.readline() == u""    
-    
+        assert reader.readline() == u""
+
     def test_seek_utf16le(self):
         # all codecs should be able to encode these
         import codecs, StringIO
@@ -219,7 +217,6 @@
             line = reader.readline()
             assert s[:len(line)] == line
 
-
     def test_unicode_internal_encode(self):
         import sys
         class U(unicode):
@@ -284,6 +281,12 @@
         assert '\\0f'.decode('string_escape') == chr(0) + 'f'
         assert '\\08'.decode('string_escape') == chr(0) + '8'
 
+    def test_escape_decode_errors(self):
+        raises(ValueError, br"\x".decode, 'string_escape')
+        raises(ValueError, br"[\x]".decode, 'string_escape')
+        raises(ValueError, br"\x0".decode, 'string_escape')
+        raises(ValueError, br"[\x0]".decode, 'string_escape')
+
     def test_escape_encode(self):
         assert '"'.encode('string_escape') == '"'
         assert "'".encode('string_escape') == "\\'"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to