summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-30 14:57:56 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-30 14:57:56 (GMT)
commit7aa5341164794efc5367f63636cbe8327ca40393 (patch)
tree72cabf6ebcc9d1319649e7e60043f8624837693f /Lib
parent802d45b6604b82ee636fdd795cc6a7d9e655855d (diff)
downloadcpython-7aa5341164794efc5367f63636cbe8327ca40393.zip
cpython-7aa5341164794efc5367f63636cbe8327ca40393.tar.gz
cpython-7aa5341164794efc5367f63636cbe8327ca40393.tar.bz2
Reverting my previous commit.
Something went horribly wrong when I was doing `hg rebase`.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/string.py9
-rw-r--r--Lib/test/test_collections.py7
-rw-r--r--Lib/test/test_dictviews.py22
-rw-r--r--Lib/test/test_symbol.py45
4 files changed, 7 insertions, 76 deletions
diff --git a/Lib/string.py b/Lib/string.py
index e7b692d..f3365c6 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -112,7 +112,10 @@ class Template(metaclass=_TemplateMetaclass):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
- return str(mapping[named])
+ val = mapping[named]
+ # We use this idiom instead of str() because the latter will
+ # fail if val is a Unicode containing non-ASCII characters.
+ return '%s' % (val,)
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
@@ -139,7 +142,9 @@ class Template(metaclass=_TemplateMetaclass):
named = mo.group('named') or mo.group('braced')
if named is not None:
try:
- return str(mapping[named])
+ # We use this idiom instead of str() because the latter
+ # will fail if val is a Unicode containing non-ASCII
+ return '%s' % (mapping[named],)
except KeyError:
return mo.group()
if mo.group('escaped') is not None:
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index c6db13e..3bb326a 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -1965,14 +1965,7 @@ class OrderedDictTests:
od = OrderedDict(**d)
self.assertGreater(sys.getsizeof(od), sys.getsizeof(d))
- def test_views(self):
OrderedDict = self.module.OrderedDict
- # See http://bugs.python.org/issue24286
- s = 'the quick brown fox jumped over a lazy dog yesterday before dawn'.split()
- od = OrderedDict.fromkeys(s)
- self.assertEqual(od.keys(), dict(od).keys())
- self.assertEqual(od.items(), dict(od).items())
-
def test_override_update(self):
OrderedDict = self.module.OrderedDict
# Verify that subclasses can override update() without breaking __init__()
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index d96832e..280353a 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -1,4 +1,3 @@
-import collections
import unittest
class DictSetTest(unittest.TestCase):
@@ -198,27 +197,6 @@ class DictSetTest(unittest.TestCase):
d[42] = d.values()
self.assertRaises(RuntimeError, repr, d)
- def test_abc_registry(self):
- d = dict(a=1)
-
- self.assertIsInstance(d.keys(), collections.KeysView)
- self.assertIsInstance(d.keys(), collections.MappingView)
- self.assertIsInstance(d.keys(), collections.Set)
- self.assertIsInstance(d.keys(), collections.Sized)
- self.assertIsInstance(d.keys(), collections.Iterable)
- self.assertIsInstance(d.keys(), collections.Container)
-
- self.assertIsInstance(d.values(), collections.ValuesView)
- self.assertIsInstance(d.values(), collections.MappingView)
- self.assertIsInstance(d.values(), collections.Sized)
-
- self.assertIsInstance(d.items(), collections.ItemsView)
- self.assertIsInstance(d.items(), collections.MappingView)
- self.assertIsInstance(d.items(), collections.Set)
- self.assertIsInstance(d.items(), collections.Sized)
- self.assertIsInstance(d.items(), collections.Iterable)
- self.assertIsInstance(d.items(), collections.Container)
-
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_symbol.py b/Lib/test/test_symbol.py
deleted file mode 100644
index 4475bbc..0000000
--- a/Lib/test/test_symbol.py
+++ /dev/null
@@ -1,45 +0,0 @@
-import unittest
-from test import support
-import filecmp
-import os
-import sys
-import subprocess
-
-
-SYMBOL_FILE = support.findfile('symbol.py')
-GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
- '..', '..', 'Include', 'graminit.h')
-TEST_PY_FILE = 'symbol_test.py'
-
-
-class TestSymbolGeneration(unittest.TestCase):
-
- def _copy_file_without_generated_symbols(self, source_file, dest_file):
- with open(source_file, 'rb') as fp:
- lines = fp.readlines()
- nl = lines[0][len(lines[0].rstrip()):]
- with open(dest_file, 'wb') as fp:
- fp.writelines(lines[:lines.index(b"#--start constants--" + nl) + 1])
- fp.writelines(lines[lines.index(b"#--end constants--" + nl):])
-
- def _generate_symbols(self, grammar_file, target_symbol_py_file):
- proc = subprocess.Popen([sys.executable,
- SYMBOL_FILE,
- grammar_file,
- target_symbol_py_file], stderr=subprocess.PIPE)
- stderr = proc.communicate()[1]
- return proc.returncode, stderr
-
- @unittest.skipIf(not os.path.exists(GRAMMAR_FILE),
- 'test only works from source build directory')
- def test_real_grammar_and_symbol_file(self):
- self._copy_file_without_generated_symbols(SYMBOL_FILE, TEST_PY_FILE)
- self.addCleanup(support.unlink, TEST_PY_FILE)
- self.assertFalse(filecmp.cmp(SYMBOL_FILE, TEST_PY_FILE))
- self.assertEqual((0, b''), self._generate_symbols(GRAMMAR_FILE,
- TEST_PY_FILE))
- self.assertTrue(filecmp.cmp(SYMBOL_FILE, TEST_PY_FILE))
-
-
-if __name__ == "__main__":
- unittest.main()