summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-10-24 18:55:37 (GMT)
committerGeorg Brandl <georg@python.org>2007-10-24 18:55:37 (GMT)
commitbd1c68c94f0d5bc25b48f62c7527f51c754f2b6b (patch)
treea468fcccf4193f6d26ce71246e2596de6ffc9eec /Lib/test
parent97f9d4f31224e72e5c714ea7e509c4fd0044f0e2 (diff)
downloadcpython-bd1c68c94f0d5bc25b48f62c7527f51c754f2b6b.zip
cpython-bd1c68c94f0d5bc25b48f62c7527f51c754f2b6b.tar.gz
cpython-bd1c68c94f0d5bc25b48f62c7527f51c754f2b6b.tar.bz2
Patch #1303: Adapt str8 constructor to bytes (now buffer) one.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_builtin.py3
-rw-r--r--Lib/test/test_bytes.py62
-rw-r--r--Lib/test/test_codeccallbacks.py6
-rw-r--r--Lib/test/test_compile.py2
-rw-r--r--Lib/test/test_io.py2
-rw-r--r--Lib/test/test_locale.py2
-rw-r--r--Lib/test/test_struct.py40
-rw-r--r--Lib/test/test_sys.py4
-rw-r--r--Lib/test/test_unicode.py4
-rw-r--r--Lib/test/test_unicodedata.py2
-rw-r--r--Lib/test/testcodec.py2
11 files changed, 67 insertions, 62 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index b6b45ee..9670be0 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -580,7 +580,8 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(hash(1), hash(1))
self.assertEqual(hash(1), hash(1.0))
hash('spam')
- self.assertEqual(hash('spam'), hash(str8('spam')))
+ self.assertEqual(hash('spam'), hash(str8(b'spam'))) # remove str8()
+ # when b"" is immutable
hash((0,1,2,3))
def f(): pass
self.assertRaises(TypeError, hash, [])
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index c7c6bd3..2a4b6d8 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -103,33 +103,33 @@ class BytesTest(unittest.TestCase):
self.failIf(b3 <= b2)
def test_compare_to_str(self):
- self.assertEqual(b"abc" == str8("abc"), True)
- self.assertEqual(b"ab" != str8("abc"), True)
- self.assertEqual(b"ab" <= str8("abc"), True)
- self.assertEqual(b"ab" < str8("abc"), True)
- self.assertEqual(b"abc" >= str8("ab"), True)
- self.assertEqual(b"abc" > str8("ab"), True)
-
- self.assertEqual(b"abc" != str8("abc"), False)
- self.assertEqual(b"ab" == str8("abc"), False)
- self.assertEqual(b"ab" > str8("abc"), False)
- self.assertEqual(b"ab" >= str8("abc"), False)
- self.assertEqual(b"abc" < str8("ab"), False)
- self.assertEqual(b"abc" <= str8("ab"), False)
-
- self.assertEqual(str8("abc") == b"abc", True)
- self.assertEqual(str8("ab") != b"abc", True)
- self.assertEqual(str8("ab") <= b"abc", True)
- self.assertEqual(str8("ab") < b"abc", True)
- self.assertEqual(str8("abc") >= b"ab", True)
- self.assertEqual(str8("abc") > b"ab", True)
-
- self.assertEqual(str8("abc") != b"abc", False)
- self.assertEqual(str8("ab") == b"abc", False)
- self.assertEqual(str8("ab") > b"abc", False)
- self.assertEqual(str8("ab") >= b"abc", False)
- self.assertEqual(str8("abc") < b"ab", False)
- self.assertEqual(str8("abc") <= b"ab", False)
+ self.assertEqual(b"abc" == str8(b"abc"), True)
+ self.assertEqual(b"ab" != str8(b"abc"), True)
+ self.assertEqual(b"ab" <= str8(b"abc"), True)
+ self.assertEqual(b"ab" < str8(b"abc"), True)
+ self.assertEqual(b"abc" >= str8(b"ab"), True)
+ self.assertEqual(b"abc" > str8(b"ab"), True)
+
+ self.assertEqual(b"abc" != str8(b"abc"), False)
+ self.assertEqual(b"ab" == str8(b"abc"), False)
+ self.assertEqual(b"ab" > str8(b"abc"), False)
+ self.assertEqual(b"ab" >= str8(b"abc"), False)
+ self.assertEqual(b"abc" < str8(b"ab"), False)
+ self.assertEqual(b"abc" <= str8(b"ab"), False)
+
+ self.assertEqual(str8(b"abc") == b"abc", True)
+ self.assertEqual(str8(b"ab") != b"abc", True)
+ self.assertEqual(str8(b"ab") <= b"abc", True)
+ self.assertEqual(str8(b"ab") < b"abc", True)
+ self.assertEqual(str8(b"abc") >= b"ab", True)
+ self.assertEqual(str8(b"abc") > b"ab", True)
+
+ self.assertEqual(str8(b"abc") != b"abc", False)
+ self.assertEqual(str8(b"ab") == b"abc", False)
+ self.assertEqual(str8(b"ab") > b"abc", False)
+ self.assertEqual(str8(b"ab") >= b"abc", False)
+ self.assertEqual(str8(b"abc") < b"ab", False)
+ self.assertEqual(str8(b"abc") <= b"ab", False)
# Byte comparisons with unicode should always fail!
# Test this for all expected byte orders and Unicode character sizes
@@ -345,7 +345,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
def test_from_buffer(self):
- sample = str8("Hello world\n\x80\x81\xfe\xff")
+ sample = str8(b"Hello world\n\x80\x81\xfe\xff")
buf = memoryview(sample)
b = bytes(buf)
self.assertEqual(b, bytes(sample))
@@ -367,8 +367,8 @@ class BytesTest(unittest.TestCase):
b1 = b"abc"
b2 = b"def"
self.assertEqual(b1 + b2, b"abcdef")
- self.assertEqual(b1 + str8("def"), b"abcdef")
- self.assertEqual(str8("def") + b1, b"defabc")
+ self.assertEqual(b1 + str8(b"def"), b"abcdef")
+ self.assertEqual(str8(b"def") + b1, b"defabc")
self.assertRaises(TypeError, lambda: b1 + "def")
self.assertRaises(TypeError, lambda: "abc" + b2)
@@ -391,7 +391,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b, b"abcdef")
self.assertEqual(b, b1)
self.failUnless(b is b1)
- b += str8("xyz")
+ b += str8(b"xyz")
self.assertEqual(b, b"abcdefxyz")
try:
b += ""
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index eedd48a..0256eb6 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -181,7 +181,7 @@ class CodecCallbackTest(unittest.TestCase):
# mapped through the encoding again. This means, that
# to be able to use e.g. the "replace" handler, the
# charmap has to have a mapping for "?".
- charmap = dict((ord(c), str8(2*c.upper())) for c in "abcdefgh")
+ charmap = dict((ord(c), str8(2*c.upper(), 'ascii')) for c in "abcdefgh")
sin = "abc"
sout = b"AABBCC"
self.assertEquals(codecs.charmap_encode(sin, "strict", charmap)[0], sout)
@@ -189,7 +189,7 @@ class CodecCallbackTest(unittest.TestCase):
sin = "abcA"
self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap)
- charmap[ord("?")] = str8("XYZ")
+ charmap[ord("?")] = str8(b"XYZ")
sin = "abcDEF"
sout = b"AABBCCXYZXYZXYZ"
self.assertEquals(codecs.charmap_encode(sin, "replace", charmap)[0], sout)
@@ -309,7 +309,7 @@ class CodecCallbackTest(unittest.TestCase):
# check with one argument too much
self.assertRaises(TypeError, exctype, *(args + ["too much"]))
# check with one argument of the wrong type
- wrongargs = [ "spam", str8("eggs"), b"spam", 42, 1.0, None ]
+ wrongargs = [ "spam", str8(b"eggs"), b"spam", 42, 1.0, None ]
for i in range(len(args)):
for wrongarg in wrongargs:
if type(wrongarg) is type(args[i]):
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index d6a51dd..1d54953 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -157,7 +157,7 @@ if 1:
s256 = "".join(["\n"] * 256 + ["spam"])
co = compile(s256, 'fn', 'exec')
self.assertEqual(co.co_firstlineno, 257)
- self.assertEqual(co.co_lnotab, str8(''))
+ self.assertEqual(co.co_lnotab, str8())
def test_literals_with_leading_zeroes(self):
for arg in ["077787", "0xj", "0x.", "0e", "090000000000000",
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 644593d..e826ff4 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -88,7 +88,7 @@ class IOTest(unittest.TestCase):
self.assertEqual(f.tell(), 6)
self.assertEqual(f.seek(-1, 1), 5)
self.assertEqual(f.tell(), 5)
- self.assertEqual(f.write(str8(" world\n\n\n")), 9)
+ self.assertEqual(f.write(str8(b" world\n\n\n")), 9)
self.assertEqual(f.seek(0), 0)
self.assertEqual(f.write(b"h"), 1)
self.assertEqual(f.seek(-1, 2), 13)
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 1bfb3b3..5fcba6f 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -82,7 +82,7 @@ finally:
# Test BSD Rune locale's bug for isctype functions.
def teststrop(s, method, output):
- s = str8(s)
+ s = str8(s, 'latin1') # XXX
if verbose:
print("%s.%s() =? %s ..." % (repr(s), method, repr(output)), end=' ')
result = getattr(s, method)()
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 7942045..d2b5643 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -101,7 +101,7 @@ s = struct.pack('ii', 1, 2)
simple_err(struct.unpack, 'iii', s)
simple_err(struct.unpack, 'i', s)
-c = str8('a')
+c = str8(b'a')
b = 1
h = 255
i = 65535
@@ -186,7 +186,7 @@ for fmt, arg, big, lil, asy in tests:
if isinstance(arg, str):
# Strings are returned as str8 since you can't know the encoding of
# the string when packed.
- arg = str8(arg)
+ arg = str8(arg, 'latin1')
if rev != arg and not asy:
raise TestFailed("unpack(%r, %r) -> (%r,) # expected (%r,)" % (
fmt, res, rev, arg))
@@ -428,14 +428,14 @@ for args in [("bB", 1),
def test_p_code():
for code, input, expected, expectedback in [
- ('p','abc', '\x00', str8('')),
- ('1p', 'abc', '\x00', str8('')),
- ('2p', 'abc', '\x01a', str8('a')),
- ('3p', 'abc', '\x02ab', str8('ab')),
- ('4p', 'abc', '\x03abc', str8('abc')),
- ('5p', 'abc', '\x03abc\x00', str8('abc')),
- ('6p', 'abc', '\x03abc\x00\x00', str8('abc')),
- ('1000p', 'x'*1000, '\xff' + 'x'*999, str8('x'*255))]:
+ ('p','abc', '\x00', str8()),
+ ('1p', 'abc', '\x00', str8()),
+ ('2p', 'abc', '\x01a', str8(b'a')),
+ ('3p', 'abc', '\x02ab', str8(b'ab')),
+ ('4p', 'abc', '\x03abc', str8(b'abc')),
+ ('5p', 'abc', '\x03abc\x00', str8(b'abc')),
+ ('6p', 'abc', '\x03abc\x00\x00', str8(b'abc')),
+ ('1000p', 'x'*1000, '\xff' + 'x'*999, str8(b'x'*255))]:
expected = bytes(expected, "latin-1")
got = struct.pack(code, input)
if got != expected:
@@ -564,20 +564,24 @@ def test_unpack_from():
if verbose:
print("test_unpack_from using", cls.__name__)
data = cls(test_string)
- vereq(s.unpack_from(data), (str8('abcd'),))
- vereq(s.unpack_from(data, 2), (str8('cd01'),))
- vereq(s.unpack_from(data, 4), (str8('0123'),))
+ if not isinstance(data, (str8, bytes)):
+ bytes_data = str8(data, 'latin1')
+ else:
+ bytes_data = data
+ vereq(s.unpack_from(data), (str8(b'abcd'),))
+ vereq(s.unpack_from(data, 2), (str8(b'cd01'),))
+ vereq(s.unpack_from(data, 4), (str8(b'0123'),))
for i in range(6):
- vereq(s.unpack_from(data, i), (str8(data[i:i+4]),))
+ vereq(s.unpack_from(data, i), (bytes_data[i:i+4],))
for i in range(6, len(test_string) + 1):
simple_err(s.unpack_from, data, i)
for cls in (str, str8, bytes): # XXX + memoryview
data = cls(test_string)
- vereq(struct.unpack_from(fmt, data), (str8('abcd'),))
- vereq(struct.unpack_from(fmt, data, 2), (str8('cd01'),))
- vereq(struct.unpack_from(fmt, data, 4), (str8('0123'),))
+ vereq(struct.unpack_from(fmt, data), (str8(b'abcd'),))
+ vereq(struct.unpack_from(fmt, data, 2), (str8(b'cd01'),))
+ vereq(struct.unpack_from(fmt, data, 4), (str8(b'0123'),))
for i in range(6):
- vereq(struct.unpack_from(fmt, data, i), (str8(data[i:i+4]),))
+ vereq(struct.unpack_from(fmt, data, i), (bytes_data[i:i+4],))
for i in range(6, len(test_string) + 1):
simple_err(struct.unpack_from, fmt, data, i)
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index ddf1876..8741830 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -300,7 +300,7 @@ class SysModuleTest(unittest.TestCase):
def test_intern(self):
self.assertRaises(TypeError, sys.intern)
- s = str8("never interned before")
+ s = str8(b"never interned before")
self.assert_(sys.intern(s) is s)
s2 = s.swapcase().swapcase()
self.assert_(sys.intern(s2) is s)
@@ -314,7 +314,7 @@ class SysModuleTest(unittest.TestCase):
def __hash__(self):
return 123
- self.assertRaises(TypeError, sys.intern, S("abc"))
+ self.assertRaises(TypeError, sys.intern, S(b"abc"))
s = "never interned as unicode before"
self.assert_(sys.intern(s) is s)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 9aad59a..4970845 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -203,8 +203,8 @@ class UnicodeTest(
self.assertRaises(TypeError, 'replace'.replace, "r", 42)
def test_str8_comparison(self):
- self.assertEqual('abc' == str8('abc'), False)
- self.assertEqual('abc' != str8('abc'), True)
+ self.assertEqual('abc' == str8(b'abc'), False)
+ self.assertEqual('abc' != str8(b'abc'), True)
def test_comparison(self):
# Comparisons:
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py
index 58fc73d..ff2dcf5 100644
--- a/Lib/test/test_unicodedata.py
+++ b/Lib/test/test_unicodedata.py
@@ -176,7 +176,7 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest):
def test_east_asian_width(self):
eaw = self.db.east_asian_width
- self.assertRaises(TypeError, eaw, str8('a'))
+ self.assertRaises(TypeError, eaw, str8(b'a'))
self.assertRaises(TypeError, eaw, '')
self.assertRaises(TypeError, eaw, 'ra')
self.assertEqual(eaw('\x1e'), 'N')
diff --git a/Lib/test/testcodec.py b/Lib/test/testcodec.py
index e7f836b..0db18c1 100644
--- a/Lib/test/testcodec.py
+++ b/Lib/test/testcodec.py
@@ -36,7 +36,7 @@ def getregentry():
decoding_map = codecs.make_identity_dict(range(256))
decoding_map.update({
0x78: "abc", # 1-n decoding mapping
- str8("abc"): 0x0078,# 1-n encoding mapping
+ str8(b"abc"): 0x0078,# 1-n encoding mapping
0x01: None, # decoding mapping to <undefined>
0x79: "", # decoding mapping to <remove character>
})