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:
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)
......
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