summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-10-11 15:01:39 +0200
committerJason R. Coombs <jaraco@jaraco.com>2017-10-11 15:01:39 +0200
commitb8936cee54cc023ba6c6081e03e0425bce20b1f7 (patch)
treecac95703592f92d2939d282c5398f197d4752130
parentc292a995eaa090c88c2d3edab6716cdb77629e42 (diff)
downloadpython-setuptools-git-b8936cee54cc023ba6c6081e03e0425bce20b1f7.tar.gz
Use natural byte literals in test_sdist
-rw-r--r--setuptools/tests/test_sdist.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index f84c57dc..1b5422f4 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -41,6 +41,8 @@ if six.PY3:
else:
LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py'
+utf_8_filename = LATIN1_FILENAME.decode('latin-1').encode('utf-8')
+
@contextlib.contextmanager
def quiet():
@@ -52,17 +54,10 @@ def quiet():
sys.stdout, sys.stderr = old_stdout, old_stderr
-# Fake byte literals for Python <= 2.5
-def b(s, encoding='utf-8'):
- if six.PY3:
- return s.encode(encoding)
- return s
-
-
# Convert to POSIX path
def posix(path):
if six.PY3 and not isinstance(path, str):
- return path.replace(os.sep.encode('ascii'), b('/'))
+ return path.replace(os.sep.encode('ascii'), b'/')
else:
return path.replace(os.sep, '/')
@@ -200,8 +195,7 @@ class TestSdistTest:
mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
os.mkdir('sdist_test.egg-info')
- # UTF-8 filename
- filename = os.path.join(b('sdist_test'), b('smörbröd.py'))
+ filename = os.path.join(b'sdist_test', utf_8_filename)
# Must touch the file or risk removal
open(filename, "w").close()
@@ -240,7 +234,7 @@ class TestSdistTest:
os.mkdir('sdist_test.egg-info')
# Latin-1 filename
- filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
+ filename = os.path.join(b'sdist_test', LATIN1_FILENAME)
# Add filename with surrogates and write manifest
with quiet():
@@ -274,10 +268,10 @@ class TestSdistTest:
cmd.run()
# Add UTF-8 filename to manifest
- filename = os.path.join(b('sdist_test'), b('smörbröd.py'))
+ filename = os.path.join(b'sdist_test', utf_8_filename)
cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
manifest = open(cmd.manifest, 'ab')
- manifest.write(b('\n') + filename)
+ manifest.write(b'\n' + filename)
manifest.close()
# The file must exist to be included in the filelist
@@ -306,10 +300,10 @@ class TestSdistTest:
cmd.run()
# Add Latin-1 filename to manifest
- filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
+ filename = os.path.join(b'sdist_test', LATIN1_FILENAME)
cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
manifest = open(cmd.manifest, 'ab')
- manifest.write(b('\n') + filename)
+ manifest.write(b'\n' + filename)
manifest.close()
# The file must exist to be included in the filelist
@@ -333,7 +327,7 @@ class TestSdistTest:
cmd.ensure_finalized()
# UTF-8 filename
- filename = os.path.join(b('sdist_test'), b('smörbröd.py'))
+ filename = os.path.join(b'sdist_test', utf_8_filename)
open(filename, 'w').close()
with quiet():
@@ -367,7 +361,7 @@ class TestSdistTest:
cmd.ensure_finalized()
# Latin-1 filename
- filename = os.path.join(b('sdist_test'), LATIN1_FILENAME)
+ filename = os.path.join(b'sdist_test', LATIN1_FILENAME)
open(filename, 'w').close()
assert os.path.isfile(filename)