diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-03 11:36:26 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-03 11:36:26 -0500 |
commit | 16fd431b079a024750e1b2a4b693a5b80dcf1900 (patch) | |
tree | 87f78ff4c954d4171ac0c8c867b289394db88197 /coverage/files.py | |
parent | 556974fe5d092ce9e7a0b09ed81ebd5486562688 (diff) | |
download | python-coveragepy-git-16fd431b079a024750e1b2a4b693a5b80dcf1900.tar.gz |
refactor: we no longer need to protect against UnicodeError, it was only on 3.6
This was the failure it was protecting against on Python 3.6:
```
___________________________ ProcessTest.test_lang_c ____________________________
[gw0] linux -- Python 3.6.15 /home/runner/work/coveragepy/coveragepy/.tox/py36/bin/python
self = <tests.test_process.ProcessTest object at 0x7fe57e63b198>
@pytest.mark.skipif(env.PYPY, reason="PyPy is unreliable with this test")
# Jython as of 2.7.1rc3 won't compile a filename that isn't utf-8.
@pytest.mark.skipif(env.JYTHON, reason="Jython can't handle this test")
def test_lang_c(self):
# LANG=C forces getfilesystemencoding on Linux to 'ascii', which causes
# failures with non-ascii file names. We don't want to make a real file
# with strange characters, though, because that gets the test runners
# tangled up. This will isolate the concerns to the coverage.py code.
# https://github.com/nedbat/coveragepy/issues/533
self.make_file("weird_file.py", r"""
globs = {}
code = "a = 1\nb = 2\n"
exec(compile(code, "wut\xe9\xea\xeb\xec\x01\x02.py", 'exec'), globs)
print(globs['a'])
print(globs['b'])
""")
self.set_environ("LANG", "C")
out = self.run_command("coverage run weird_file.py")
> assert out == "1\n2\n"
E assert 'Traceback (m...ion by zero\n' == '1\n2\n'
E - 1
E - 2
E + Traceback (most recent call last):
E + File "/home/runner/work/coveragepy/coveragepy/coverage/files.py", line 149, in abs_file
E + path = os.path.realpath(path)
E + File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/posixpath.py", line 395, in realpath
E + path, ok = _joinrealpath(filename[:0], filename, {})
E + File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/posixpath.py", line 429, in _joinrealpath
E + if not islink(newpath):
E + File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/posixpath.py", line 171, in islink
E + st = os.lstat(path)
E + UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-6: ordinal not in range(128)
```
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/coverage/files.py b/coverage/files.py index 3cf87faa..09f09da7 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -145,13 +145,7 @@ else: @contract(returns='unicode') def abs_file(path): """Return the absolute normalized form of `path`.""" - try: - path = os.path.realpath(path) - except UnicodeError: - pass - path = os.path.abspath(path) - path = actual_path(path) - return path + return actual_path(os.path.abspath(os.path.realpath(path))) def python_reported_file(filename): |