Skip to content

bpo-40275: Use new test.support helper submodules in tests #21452

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

Merged
merged 2 commits into from
Aug 4, 2020
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
13 changes: 7 additions & 6 deletions Lib/test/eintrdata/eintr_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest

from test import support
from test.support import os_helper
from test.support import socket_helper

@contextlib.contextmanager
Expand Down Expand Up @@ -314,16 +315,16 @@ def test_accept(self):
@support.requires_freebsd_version(10, 3)
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'needs mkfifo()')
def _test_open(self, do_open_close_reader, do_open_close_writer):
filename = support.TESTFN
filename = os_helper.TESTFN

# Use a fifo: until the child opens it for reading, the parent will
# block when trying to open it for writing.
support.unlink(filename)
os_helper.unlink(filename)
try:
os.mkfifo(filename)
except PermissionError as e:
self.skipTest('os.mkfifo(): %s' % e)
self.addCleanup(support.unlink, filename)
self.addCleanup(os_helper.unlink, filename)

code = '\n'.join((
'import os, time',
Expand Down Expand Up @@ -486,16 +487,16 @@ def test_devpoll(self):

class FNTLEINTRTest(EINTRBaseTest):
def _lock(self, lock_func, lock_name):
self.addCleanup(support.unlink, support.TESTFN)
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
code = '\n'.join((
"import fcntl, time",
"with open('%s', 'wb') as f:" % support.TESTFN,
"with open('%s', 'wb') as f:" % os_helper.TESTFN,
" fcntl.%s(f, fcntl.LOCK_EX)" % lock_name,
" time.sleep(%s)" % self.sleep_time))
start_time = time.monotonic()
proc = self.subprocess(code)
with kill_on_error(proc):
with open(support.TESTFN, 'wb') as f:
with open(os_helper.TESTFN, 'wb') as f:
while True: # synchronize the subprocess
dt = time.monotonic() - start_time
if dt > 60.0:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from email import quoprimime

from test.support import threading_helper
from test.support import unlink
from test.support.os_helper import unlink
from test.test_email import openfile, TestEmailBase

# These imports are documented to work, but we are testing them using a
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_multibytecodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#

from test import support
from test.support import TESTFN
from test.support import os_helper
from test.support.os_helper import TESTFN
import unittest, io, codecs, sys
import _multibytecodec

Expand Down Expand Up @@ -57,7 +58,7 @@ def test_codingspec(self):
code = '# coding: {}\n'.format(enc)
exec(code)
finally:
support.unlink(TESTFN)
os_helper.unlink(TESTFN)

def test_init_segfault(self):
# bug #3305: this used to segfault
Expand Down Expand Up @@ -296,7 +297,7 @@ def test_bug1728403(self):
finally:
f.close()
finally:
support.unlink(TESTFN)
os_helper.unlink(TESTFN)

class Test_StreamWriter(unittest.TestCase):
def test_gb18030(self):
Expand Down
48 changes: 24 additions & 24 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from contextlib import ExitStack
from io import StringIO
from test import support
from test.support import os_helper
# This little helper class is essential for testing pdb under doctest.
from test.test_doctest import _FakeInput
from unittest.mock import patch
Expand Down Expand Up @@ -1188,10 +1188,10 @@ def test_pdb_issue_20766():

class PdbTestCase(unittest.TestCase):
def tearDown(self):
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)

def _run_pdb(self, pdb_args, commands):
self.addCleanup(support.rmtree, '__pycache__')
self.addCleanup(os_helper.rmtree, '__pycache__')
cmd = [sys.executable, '-m', 'pdb'] + pdb_args
with subprocess.Popen(
cmd,
Expand All @@ -1210,31 +1210,31 @@ def run_pdb_script(self, script, commands):
filename = 'main.py'
with open(filename, 'w') as f:
f.write(textwrap.dedent(script))
self.addCleanup(support.unlink, filename)
self.addCleanup(os_helper.unlink, filename)
return self._run_pdb([filename], commands)

def run_pdb_module(self, script, commands):
"""Runs the script code as part of a module"""
self.module_name = 't_main'
support.rmtree(self.module_name)
os_helper.rmtree(self.module_name)
main_file = self.module_name + '/__main__.py'
init_file = self.module_name + '/__init__.py'
os.mkdir(self.module_name)
with open(init_file, 'w') as f:
pass
with open(main_file, 'w') as f:
f.write(textwrap.dedent(script))
self.addCleanup(support.rmtree, self.module_name)
self.addCleanup(os_helper.rmtree, self.module_name)
return self._run_pdb(['-m', self.module_name], commands)

def _assert_find_function(self, file_content, func_name, expected):
with open(support.TESTFN, 'wb') as f:
with open(os_helper.TESTFN, 'wb') as f:
f.write(file_content)

expected = None if not expected else (
expected[0], support.TESTFN, expected[1])
expected[0], os_helper.TESTFN, expected[1])
self.assertEqual(
expected, pdb.find_function(func_name, support.TESTFN))
expected, pdb.find_function(func_name, os_helper.TESTFN))

def test_find_function_empty_file(self):
self._assert_find_function(b'', 'foo', None)
Expand Down Expand Up @@ -1284,9 +1284,9 @@ def bœr():

def test_issue7964(self):
# open the file as binary so we can force \r\n newline
with open(support.TESTFN, 'wb') as f:
with open(os_helper.TESTFN, 'wb') as f:
f.write(b'print("testing my pdb")\r\n')
cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
cmd = [sys.executable, '-m', 'pdb', os_helper.TESTFN]
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def bar():
"""
with open('bar.py', 'w') as f:
f.write(textwrap.dedent(bar))
self.addCleanup(support.unlink, 'bar.py')
self.addCleanup(os_helper.unlink, 'bar.py')
stdout, stderr = self.run_pdb_script(script, commands)
self.assertTrue(
any('main.py(5)foo()->None' in l for l in stdout.splitlines()),
Expand All @@ -1337,7 +1337,7 @@ def test_issue13120(self):
# Invoking "continue" on a non-main thread triggered an exception
# inside signal.signal.

with open(support.TESTFN, 'wb') as f:
with open(os_helper.TESTFN, 'wb') as f:
f.write(textwrap.dedent("""
import threading
import pdb
Expand All @@ -1349,7 +1349,7 @@ def start_pdb():

t = threading.Thread(target=start_pdb)
t.start()""").encode('ascii'))
cmd = [sys.executable, '-u', support.TESTFN]
cmd = [sys.executable, '-u', os_helper.TESTFN]
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
Expand All @@ -1363,7 +1363,7 @@ def start_pdb():

def test_issue36250(self):

with open(support.TESTFN, 'wb') as f:
with open(os_helper.TESTFN, 'wb') as f:
f.write(textwrap.dedent("""
import threading
import pdb
Expand All @@ -1379,7 +1379,7 @@ def start_pdb():
pdb.Pdb(readrc=False).set_trace()
evt.set()
t.join()""").encode('ascii'))
cmd = [sys.executable, '-u', support.TESTFN]
cmd = [sys.executable, '-u', os_helper.TESTFN]
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
Expand Down Expand Up @@ -1412,7 +1412,7 @@ def test_readrc_kwarg(self):

save_home = os.environ.pop('HOME', None)
try:
with support.temp_cwd():
with os_helper.temp_cwd():
with open('.pdbrc', 'w') as f:
f.write("invalid\n")

Expand All @@ -1437,7 +1437,7 @@ def test_readrc_kwarg(self):

def test_readrc_homedir(self):
save_home = os.environ.pop("HOME", None)
with support.temp_dir() as temp_dir, patch("os.path.expanduser"):
with os_helper.temp_dir() as temp_dir, patch("os.path.expanduser"):
rc_path = os.path.join(temp_dir, ".pdbrc")
os.path.expanduser.return_value = rc_path
try:
Expand Down Expand Up @@ -1506,12 +1506,12 @@ def test_run_pdb_with_pdb(self):

def test_module_without_a_main(self):
module_name = 't_main'
support.rmtree(module_name)
os_helper.rmtree(module_name)
init_file = module_name + '/__init__.py'
os.mkdir(module_name)
with open(init_file, 'w') as f:
pass
self.addCleanup(support.rmtree, module_name)
self.addCleanup(os_helper.rmtree, module_name)
stdout, stderr = self._run_pdb(['-m', module_name], "")
self.assertIn("ImportError: No module named t_main.__main__",
stdout.splitlines())
Expand All @@ -1531,11 +1531,11 @@ def test_blocks_at_first_code_line(self):

def test_relative_imports(self):
self.module_name = 't_main'
support.rmtree(self.module_name)
os_helper.rmtree(self.module_name)
main_file = self.module_name + '/__main__.py'
init_file = self.module_name + '/__init__.py'
module_file = self.module_name + '/module.py'
self.addCleanup(support.rmtree, self.module_name)
self.addCleanup(os_helper.rmtree, self.module_name)
os.mkdir(self.module_name)
with open(init_file, 'w') as f:
f.write(textwrap.dedent("""
Expand Down Expand Up @@ -1569,11 +1569,11 @@ def test_relative_imports(self):
def test_relative_imports_on_plain_module(self):
# Validates running a plain module. See bpo32691
self.module_name = 't_main'
support.rmtree(self.module_name)
os_helper.rmtree(self.module_name)
main_file = self.module_name + '/runme.py'
init_file = self.module_name + '/__init__.py'
module_file = self.module_name + '/module.py'
self.addCleanup(support.rmtree, self.module_name)
self.addCleanup(os_helper.rmtree, self.module_name)
os.mkdir(self.module_name)
with open(init_file, 'w') as f:
f.write(textwrap.dedent("""
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_urllib2_localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import unittest
import hashlib

from test import support
from test.support import hashlib_helper
from test.support import threading_helper
from test.support import warnings_helper

try:
import ssl
Expand Down Expand Up @@ -567,7 +567,7 @@ def test_https(self):

def test_https_with_cafile(self):
handler = self.start_https_server(certfile=CERT_localhost)
with support.check_warnings(('', DeprecationWarning)):
with warnings_helper.check_warnings(('', DeprecationWarning)):
# Good cert
data = self.urlopen("https://localhost:%s/bizarre" % handler.port,
cafile=CERT_localhost)
Expand All @@ -585,7 +585,7 @@ def test_https_with_cafile(self):
def test_https_with_cadefault(self):
handler = self.start_https_server(certfile=CERT_localhost)
# Self-signed cert should fail verification with system certificate store
with support.check_warnings(('', DeprecationWarning)):
with warnings_helper.check_warnings(('', DeprecationWarning)):
with self.assertRaises(urllib.error.URLError) as cm:
self.urlopen("https://localhost:%s/bizarre" % handler.port,
cadefault=True)
Expand Down
Loading