Commit b8936cee authored by Jason R. Coombs's avatar Jason R. Coombs

Use natural byte literals in test_sdist

parent c292a995
...@@ -41,6 +41,8 @@ if six.PY3: ...@@ -41,6 +41,8 @@ if six.PY3:
else: else:
LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py' LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py'
utf_8_filename = LATIN1_FILENAME.decode('latin-1').encode('utf-8')
@contextlib.contextmanager @contextlib.contextmanager
def quiet(): def quiet():
...@@ -52,17 +54,10 @@ def quiet(): ...@@ -52,17 +54,10 @@ def quiet():
sys.stdout, sys.stderr = old_stdout, old_stderr 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 # Convert to POSIX path
def posix(path): def posix(path):
if six.PY3 and not isinstance(path, str): 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: else:
return path.replace(os.sep, '/') return path.replace(os.sep, '/')
...@@ -200,8 +195,7 @@ class TestSdistTest: ...@@ -200,8 +195,7 @@ class TestSdistTest:
mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt') mm.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
os.mkdir('sdist_test.egg-info') os.mkdir('sdist_test.egg-info')
# UTF-8 filename filename = os.path.join(b'sdist_test', utf_8_filename)
filename = os.path.join(b('sdist_test'), b('smörbröd.py'))
# Must touch the file or risk removal # Must touch the file or risk removal
open(filename, "w").close() open(filename, "w").close()
...@@ -240,7 +234,7 @@ class TestSdistTest: ...@@ -240,7 +234,7 @@ class TestSdistTest:
os.mkdir('sdist_test.egg-info') os.mkdir('sdist_test.egg-info')
# Latin-1 filename # 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 # Add filename with surrogates and write manifest
with quiet(): with quiet():
...@@ -274,10 +268,10 @@ class TestSdistTest: ...@@ -274,10 +268,10 @@ class TestSdistTest:
cmd.run() cmd.run()
# Add UTF-8 filename to manifest # 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') cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
manifest = open(cmd.manifest, 'ab') manifest = open(cmd.manifest, 'ab')
manifest.write(b('\n') + filename) manifest.write(b'\n' + filename)
manifest.close() manifest.close()
# The file must exist to be included in the filelist # The file must exist to be included in the filelist
...@@ -306,10 +300,10 @@ class TestSdistTest: ...@@ -306,10 +300,10 @@ class TestSdistTest:
cmd.run() cmd.run()
# Add Latin-1 filename to manifest # 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') cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
manifest = open(cmd.manifest, 'ab') manifest = open(cmd.manifest, 'ab')
manifest.write(b('\n') + filename) manifest.write(b'\n' + filename)
manifest.close() manifest.close()
# The file must exist to be included in the filelist # The file must exist to be included in the filelist
...@@ -333,7 +327,7 @@ class TestSdistTest: ...@@ -333,7 +327,7 @@ class TestSdistTest:
cmd.ensure_finalized() cmd.ensure_finalized()
# UTF-8 filename # 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() open(filename, 'w').close()
with quiet(): with quiet():
...@@ -367,7 +361,7 @@ class TestSdistTest: ...@@ -367,7 +361,7 @@ class TestSdistTest:
cmd.ensure_finalized() cmd.ensure_finalized()
# Latin-1 filename # 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() open(filename, 'w').close()
assert os.path.isfile(filename) assert os.path.isfile(filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment