summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-06-11 21:38:39 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-06-11 21:38:39 (GMT)
commit5de48bdd195b14426c772b4c61290aef7f33e3ec (patch)
treee4411088f62f76b183b18d543b4c4b64d4076d65 /Lib/test
parent80bfb725af0809308264d526ac6a024fc8386643 (diff)
downloadcpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.zip
cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.gz
cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.bz2
Simplify various spots where: str() is called on something
that already is a string or the existence of the str class is checked or a check is done for str twice. These all stem from the initial unicode->str replacement.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_cfgparser.py9
-rw-r--r--Lib/test/test_descr.py57
-rw-r--r--Lib/test/test_iter.py2
-rw-r--r--Lib/test/test_pprint.py12
-rw-r--r--Lib/test/test_set.py16
5 files changed, 37 insertions, 59 deletions
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
index 360998e..076de4a 100644
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -247,13 +247,8 @@ class TestCaseBase(unittest.TestCase):
cf.set("sect", "option1", mystr("splat"))
cf.set("sect", "option2", "splat")
cf.set("sect", "option2", mystr("splat"))
- try:
- str
- except NameError:
- pass
- else:
- cf.set("sect", "option1", str("splat"))
- cf.set("sect", "option2", str("splat"))
+ cf.set("sect", "option1", "splat")
+ cf.set("sect", "option2", "splat")
def test_read_returns_file_list(self):
file1 = test_support.findfile("cfgparser.1")
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index fca0061..bcbd096 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -265,7 +265,7 @@ def test_dir():
del junk
# Just make sure these don't blow up!
- for arg in 2, 2, 2j, 2e0, [2], "2", "2", (2,), {2:2}, type, test_dir:
+ for arg in 2, 2, 2j, 2e0, [2], "2", b"2", (2,), {2:2}, type, test_dir:
dir(arg)
# Test dir on custom classes. Since these have object as a
@@ -1117,34 +1117,29 @@ def slots():
vereq(c.abc, 5)
# Test unicode slot names
+ # Test a single unicode string is not expanded as a sequence.
+ class C(object):
+ __slots__ = "abc"
+ c = C()
+ c.abc = 5
+ vereq(c.abc, 5)
+
+ # _unicode_to_string used to modify slots in certain circumstances
+ slots = ("foo", "bar")
+ class C(object):
+ __slots__ = slots
+ x = C()
+ x.foo = 5
+ vereq(x.foo, 5)
+ veris(type(slots[0]), str)
+ # this used to leak references
try:
- str
- except NameError:
+ class C(object):
+ __slots__ = [chr(128)]
+ except (TypeError, UnicodeEncodeError):
pass
else:
- # Test a single unicode string is not expanded as a sequence.
- class C(object):
- __slots__ = str("abc")
- c = C()
- c.abc = 5
- vereq(c.abc, 5)
-
- # _unicode_to_string used to modify slots in certain circumstances
- slots = (str("foo"), str("bar"))
- class C(object):
- __slots__ = slots
- x = C()
- x.foo = 5
- vereq(x.foo, 5)
- veris(type(slots[0]), str)
- # this used to leak references
- try:
- class C(object):
- __slots__ = [chr(128)]
- except (TypeError, UnicodeEncodeError):
- pass
- else:
- raise TestFailed, "[unichr(128)] slots not caught"
+ raise TestFailed, "[unichr(128)] slots not caught"
# Test leaks
class Counted(object):
@@ -2693,14 +2688,8 @@ def setclass():
__slots__ = ["a", "b"]
class H(object):
__slots__ = ["b", "a"]
- try:
- str
- except NameError:
- class I(object):
- __slots__ = ["a", "b"]
- else:
- class I(object):
- __slots__ = [str("a"), str("b")]
+ class I(object):
+ __slots__ = ["a", "b"]
class J(object):
__slots__ = ["c", "b"]
class K(object):
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 42d4e3e..f7712db 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -526,7 +526,7 @@ class TestCase(unittest.TestCase):
# and pass that on to unicode.join().
try:
got = " - ".join(OhPhooey(f))
- self.assertEqual(got, str("a\n - b\n - fooled you! - c\n"))
+ self.assertEqual(got, "a\n - b\n - fooled you! - c\n")
finally:
f.close()
try:
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index f7f6ac6..8698907 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -2,12 +2,6 @@ import pprint
import test.test_support
import unittest
-try:
- uni = str
-except NameError:
- def uni(x):
- return x
-
# list, tuple and dict subclasses that do or don't overwrite __repr__
class list2(list):
pass
@@ -41,7 +35,7 @@ class QueryTestCase(unittest.TestCase):
# Verify .isrecursive() and .isreadable() w/o recursion
verify = self.assert_
pp = pprint.PrettyPrinter()
- for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"),
+ for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, "yaddayadda",
self.a, self.b):
# module-level convenience functions
verify(not pprint.isrecursive(safe),
@@ -114,12 +108,12 @@ class QueryTestCase(unittest.TestCase):
# multiple lines. For that reason, dicts with more than one element
# aren't tested here.
verify = self.assert_
- for simple in (0, 0, 0+0j, 0.0, "", uni(""),
+ for simple in (0, 0, 0+0j, 0.0, "", b"",
(), tuple2(), tuple3(),
[], list2(), list3(),
{}, dict2(), dict3(),
verify, pprint,
- -6, -6, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6},
+ -6, -6, -6-6j, -1.5, "x", b"x", (3,), [3], {3: 6},
(1,2), [3,4], {5: 6, 7: 8},
tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
[3,4], list2([3,4]), list3([3,4]), list3(range(100)),
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index e411025..ee570f0 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -72,7 +72,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(type(u), self.thetype)
self.assertRaises(PassThru, self.s.union, check_pass_thru())
self.assertRaises(TypeError, self.s.union, [[]])
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd'))
self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg'))
self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc'))
@@ -96,7 +96,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(self.s, self.thetype(self.word))
self.assertEqual(type(i), self.thetype)
self.assertRaises(PassThru, self.s.intersection, check_pass_thru())
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc'))
self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set(''))
self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc'))
@@ -121,7 +121,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(type(i), self.thetype)
self.assertRaises(PassThru, self.s.difference, check_pass_thru())
self.assertRaises(TypeError, self.s.difference, [[]])
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
self.assertEqual(self.thetype('abcba').difference(C('cdc')), set('ab'))
self.assertEqual(self.thetype('abcba').difference(C('efgfe')), set('abc'))
self.assertEqual(self.thetype('abcba').difference(C('ccb')), set('a'))
@@ -146,7 +146,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(type(i), self.thetype)
self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru())
self.assertRaises(TypeError, self.s.symmetric_difference, [[]])
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
self.assertEqual(self.thetype('abcba').symmetric_difference(C('cdc')), set('abd'))
self.assertEqual(self.thetype('abcba').symmetric_difference(C('efgfe')), set('abcefg'))
self.assertEqual(self.thetype('abcba').symmetric_difference(C('ccb')), set('a'))
@@ -390,7 +390,7 @@ class TestSet(TestJointOps):
self.assertRaises(PassThru, self.s.update, check_pass_thru())
self.assertRaises(TypeError, self.s.update, [[]])
for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')):
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
s = self.thetype('abcba')
self.assertEqual(s.update(C(p)), None)
self.assertEqual(s, set(q))
@@ -411,7 +411,7 @@ class TestSet(TestJointOps):
self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru())
self.assertRaises(TypeError, self.s.intersection_update, [[]])
for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')):
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
s = self.thetype('abcba')
self.assertEqual(s.intersection_update(C(p)), None)
self.assertEqual(s, set(q))
@@ -436,7 +436,7 @@ class TestSet(TestJointOps):
self.assertRaises(TypeError, self.s.difference_update, [[]])
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
for p, q in (('cdc', 'ab'), ('efgfe', 'abc'), ('ccb', 'a'), ('ef', 'abc')):
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
s = self.thetype('abcba')
self.assertEqual(s.difference_update(C(p)), None)
self.assertEqual(s, set(q))
@@ -460,7 +460,7 @@ class TestSet(TestJointOps):
self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru())
self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')):
- for C in set, frozenset, dict.fromkeys, str, str, list, tuple:
+ for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
s = self.thetype('abcba')
self.assertEqual(s.symmetric_difference_update(C(p)), None)
self.assertEqual(s, set(q))