[Python-checkins] cpython (merge 3.2 -> 3.2): merge heads
eli.bendersky
python-checkins at python.org
Tue Jul 17 13:25:44 CEST 2012
http://hg.python.org/cpython/rev/9c6e726801cf
changeset: 78153:9c6e726801cf
branch: 3.2
parent: 78152:d896fd0a8ba7
parent: 78150:5553a53a230a
user: Eli Bendersky <eliben at gmail.com>
date: Tue Jul 17 14:22:01 2012 +0300
summary:
merge heads
files:
Lib/posixpath.py | 9 +++++----
Lib/test/test_posixpath.py | 25 ++++++++++++++++---------
Lib/test/test_runpy.py | 2 +-
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -83,11 +83,12 @@
else:
path += sep + b
except TypeError:
- strs = [isinstance(s, str) for s in (a, ) + p]
- if any(strs) and not all(strs):
+ valid_types = all(isinstance(s, (str, bytes, bytearray))
+ for s in (a, ) + p)
+ if valid_types:
+ # Must have a mixture of text and binary data
raise TypeError("Can't mix strings and bytes in path components.")
- else:
- raise
+ raise
return path
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -1,6 +1,7 @@
import unittest
from test import support, test_genericpath
+import itertools
import posixpath
import os
import sys
@@ -56,15 +57,21 @@
self.assertEqual(posixpath.join(b"/foo/", b"bar/", b"baz/"),
b"/foo/bar/baz/")
- with self.assertRaises(TypeError) as e:
- posixpath.join(b'bytes', 'str')
- self.assertIn("Can't mix strings and bytes", e.args[0])
- with self.assertRaises(TypeError) as e:
- posixpath.join('str', b'bytes')
- self.assertIn("Can't mix strings and bytes", e.args[0])
- with self.assertRaises(TypeError) as e:
- posixpath.join('str', bytearray(b'bytes'))
- self.assertIn("Can't mix strings and bytes", e.args[0])
+ def check_error_msg(list_of_args, msg):
+ """Check posixpath.join raises friendly TypeErrors."""
+ for args in (item for perm in list_of_args
+ for item in itertools.permutations(perm)):
+ with self.assertRaises(TypeError) as cm:
+ posixpath.join(*args)
+ self.assertEqual(msg, cm.exception.args[0])
+
+ check_error_msg([[b'bytes', 'str'], [bytearray(b'bytes'), 'str']],
+ "Can't mix strings and bytes in path components.")
+ # regression, see #15377
+ with self.assertRaises(TypeError) as cm:
+ os.path.join(None, 'str')
+ self.assertNotEqual("Can't mix strings and bytes in path components.",
+ cm.exception.args[0])
def test_split(self):
self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar"))
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -182,7 +182,7 @@
def _make_pkg(self, source, depth, mod_base="runpy_test"):
pkg_name = "__runpy_pkg__"
test_fname = mod_base+os.extsep+"py"
- pkg_dir = sub_dir = tempfile.mkdtemp()
+ pkg_dir = sub_dir = os.path.realpath(tempfile.mkdtemp())
if verbose > 1: print(" Package tree in:", sub_dir)
sys.path.insert(0, pkg_dir)
if verbose > 1: print(" Updated sys.path:", sys.path[0])
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list