~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Lib/test/test_unicode.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
532
532
 
533
533
        self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd')
534
534
 
 
535
        # Issue #2242: crash on some Windows/MSVC versions
 
536
        self.assertRaises(UnicodeDecodeError, '+\xc1'.decode, 'utf-7')
 
537
 
535
538
    def test_codecs_utf8(self):
536
539
        self.assertEqual(u''.encode('utf-8'), '')
537
540
        self.assertEqual(u'\u20ac'.encode('utf-8'), '\xe2\x82\xac')
1110
1113
        #  will fail
1111
1114
        self.assertRaises(UnicodeEncodeError, "foo{0}".format, u'\u1000bar')
1112
1115
 
 
1116
    def test_raiseMemError(self):
 
1117
        # Ensure that the freelist contains a consistent object, even
 
1118
        # when a string allocation fails with a MemoryError.
 
1119
        # This used to crash the interpreter,
 
1120
        # or leak references when the number was smaller.
 
1121
        charwidth = 4 if sys.maxunicode >= 0x10000 else 2
 
1122
        # Note: sys.maxsize is half of the actual max allocation because of
 
1123
        # the signedness of Py_ssize_t.
 
1124
        alloc = lambda: u"a" * (sys.maxsize // charwidth * 2)
 
1125
        self.assertRaises(MemoryError, alloc)
 
1126
        self.assertRaises(MemoryError, alloc)
 
1127
 
1113
1128
def test_main():
1114
1129
    test_support.run_unittest(__name__)
1115
1130