mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Make test_str.py pass.
This commit is contained in:
parent
2be161dcfa
commit
ea0ebd8075
3 changed files with 15 additions and 17 deletions
|
@ -21,7 +21,7 @@ def base64_encode(input,errors='strict'):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
assert errors == 'strict'
|
assert errors == 'strict'
|
||||||
output = base64.encodestring(input)
|
output = bytes(base64.encodestring(input))
|
||||||
return (output, len(input))
|
return (output, len(input))
|
||||||
|
|
||||||
def base64_decode(input,errors='strict'):
|
def base64_decode(input,errors='strict'):
|
||||||
|
|
|
@ -1102,10 +1102,10 @@ class MixinStrUserStringTest:
|
||||||
|
|
||||||
if test_support.have_unicode:
|
if test_support.have_unicode:
|
||||||
def test_encoding_decoding(self):
|
def test_encoding_decoding(self):
|
||||||
codecs = [('rot13', 'uryyb jbeyq'),
|
codecs = [('rot13', b'uryyb jbeyq'),
|
||||||
('base64', 'aGVsbG8gd29ybGQ=\n'),
|
('base64', b'aGVsbG8gd29ybGQ=\n'),
|
||||||
('hex', '68656c6c6f20776f726c64'),
|
('hex', b'68656c6c6f20776f726c64'),
|
||||||
('uu', 'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
|
('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
|
||||||
for encoding, data in codecs:
|
for encoding, data in codecs:
|
||||||
self.checkequal(data, 'hello world', 'encode', encoding)
|
self.checkequal(data, 'hello world', 'encode', encoding)
|
||||||
self.checkequal('hello world', data, 'decode', encoding)
|
self.checkequal('hello world', data, 'decode', encoding)
|
||||||
|
@ -1115,7 +1115,7 @@ class MixinStrUserStringTest:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
data = 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
|
data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
|
||||||
self.checkequal(data, 'hello world', 'encode', 'zlib')
|
self.checkequal(data, 'hello world', 'encode', 'zlib')
|
||||||
self.checkequal('hello world', data, 'decode', 'zlib')
|
self.checkequal('hello world', data, 'decode', 'zlib')
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,6 @@ class StrTest(
|
||||||
|
|
||||||
def test_conversion(self):
|
def test_conversion(self):
|
||||||
# Make sure __str__() behaves properly
|
# Make sure __str__() behaves properly
|
||||||
class Foo0:
|
|
||||||
def __unicode__(self):
|
|
||||||
return "foo"
|
|
||||||
|
|
||||||
class Foo1:
|
class Foo1:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -45,15 +42,15 @@ class StrTest(
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "foo"
|
return "foo"
|
||||||
|
|
||||||
class Foo4(str):
|
class Foo4(str8):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "foo"
|
return "foo"
|
||||||
|
|
||||||
class Foo5(str):
|
class Foo5(str):
|
||||||
def __str__(self):
|
def __unicode__(self):
|
||||||
return "foo"
|
return "foo"
|
||||||
|
|
||||||
class Foo6(str):
|
class Foo6(str8):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "foos"
|
return "foos"
|
||||||
|
|
||||||
|
@ -72,22 +69,23 @@ class StrTest(
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
class Foo9(str):
|
class Foo9(str8):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "string"
|
return "string"
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "not unicode"
|
return "not unicode"
|
||||||
|
|
||||||
self.assert_(str(Foo0()).startswith("<")) # this is different from __unicode__
|
|
||||||
self.assertEqual(str(Foo1()), "foo")
|
self.assertEqual(str(Foo1()), "foo")
|
||||||
self.assertEqual(str(Foo2()), "foo")
|
self.assertEqual(str(Foo2()), "foo")
|
||||||
self.assertEqual(str(Foo3()), "foo")
|
self.assertEqual(str(Foo3()), "foo")
|
||||||
self.assertEqual(str(Foo4("bar")), "foo")
|
self.assertEqual(str(Foo4("bar")), "foo")
|
||||||
self.assertEqual(str(Foo5("bar")), "foo")
|
self.assertEqual(str(Foo5("bar")), "foo")
|
||||||
self.assertEqual(str(Foo6("bar")), "foos")
|
self.assertEqual(str8(Foo6("bar")), "foos")
|
||||||
self.assertEqual(str(Foo7("bar")), "foos")
|
self.assertEqual(str(Foo6("bar")), "foou")
|
||||||
|
self.assertEqual(str8(Foo7("bar")), "foos")
|
||||||
|
self.assertEqual(str(Foo7("bar")), "foou")
|
||||||
self.assertEqual(str(Foo8("foo")), "foofoo")
|
self.assertEqual(str(Foo8("foo")), "foofoo")
|
||||||
self.assertEqual(str(Foo9("foo")), "string")
|
self.assertEqual(str8(Foo9("foo")), "string")
|
||||||
self.assertEqual(str(Foo9("foo")), "not unicode")
|
self.assertEqual(str(Foo9("foo")), "not unicode")
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue