Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Address warnings about using the default encoding #3399

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tornado/test/autoreload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_reload(self):

spec = getattr(sys.modules[__name__], '__spec__', None)
print(f"Starting {__name__=}, __spec__.name={getattr(spec, 'name', None)}")
exec(open("run_twice_magic.py").read())
exec(open("run_twice_magic.py", encoding="utf-8").read())
"""

# Create temporary test application
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_reload_wrapper_preservation(self):
raise Exception('started without autoreload wrapper')

print('Starting')
exec(open("run_twice_magic.py").read())
exec(open("run_twice_magic.py", encoding="utf-8").read())
"""

self.write_files(
Expand All @@ -219,7 +219,7 @@ def test_reload_wrapper_args(self):

print(os.path.basename(sys.argv[0]))
print(f'argv={sys.argv[1:]}')
exec(open("run_twice_magic.py").read())
exec(open("run_twice_magic.py", encoding="utf-8").read())
"""
# Create temporary test application
self.write_files({"main.py": main})
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_reload_wrapper_until_success(self):
sys.exit(0)
else:
print("reloading")
exec(open("run_twice_magic.py").read())
exec(open("run_twice_magic.py", encoding="utf-8").read())
"""

# Create temporary test application
Expand Down
12 changes: 7 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ setenv =
PYTHONWARNDEFAULTENCODING=1

# Allow shell commands in tests
allowlist_externals = sh
allowlist_externals = sh, env


# All non-comment lines but the last must end in a backslash.
# Tox filters line-by-line based on the environment name.
commands =
# py3*: -b turns on an extra warning when calling
Expand Down Expand Up @@ -111,12 +110,15 @@ commands =
black --check --diff {posargs:tornado demos}
# Many syscalls are defined differently on linux and windows,
# so we have to typecheck both.
mypy --platform linux {posargs:tornado}
mypy --platform windows {posargs:tornado}
# Mypy currently uses the default encoding so we must unset the warning variable
# here (must be completely unset, not just set to zero/empty). Remove this
# (and the allowlist_externals for env) when mypy sets the encoding explicitly.
env -u PYTHONWARNDEFAULTENCODING mypy --platform linux {posargs:tornado}
env -u PYTHONWARNDEFAULTENCODING mypy --platform windows {posargs:tornado}
# We mainly lint on the oldest version of Python we support, since
# we're more likely to catch problems of accidentally depending on
# something new than of depending on something old and deprecated.
# But sometimes something we depend on gets removed so we should also
# test the newest version.
mypy --platform linux --python-version 3.13 {posargs:tornado}
env -u PYTHONWARNDEFAULTENCODING mypy --platform linux --python-version 3.13 {posargs:tornado}
changedir = {toxinidir}