Skip to content

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

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
Jun 30, 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
3 changes: 2 additions & 1 deletion Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import test.support.script_helper
from test import support
from test.support import hashlib_helper
from test.support import import_helper
from test.support import socket_helper
from test.support import threading_helper


# Skip tests if _multiprocessing wasn't built.
_multiprocessing = test.support.import_module('_multiprocessing')
_multiprocessing = import_helper.import_module('_multiprocessing')
# Skip tests if sem_open implementation is broken.
support.skip_if_broken_multiprocessing_synchronize()
import threading
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def create_temp_dir(self):
test_cwd = 'test_python_worker_{}'.format(pid)
else:
test_cwd = 'test_python_{}'.format(pid)
test_cwd += support.FS_NONASCII
test_cwd += os_helper.FS_NONASCII
test_cwd = os.path.join(self.tmp_dir, test_cwd)
return test_cwd

Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_base64.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest
from test import support
import base64
import binascii
import os
from array import array
from test.support import os_helper
from test.support import script_helper


Expand Down Expand Up @@ -647,8 +647,8 @@ def test_ErrorHeritage(self):

class TestMain(unittest.TestCase):
def tearDown(self):
if os.path.exists(support.TESTFN):
os.unlink(support.TESTFN)
if os.path.exists(os_helper.TESTFN):
os.unlink(os_helper.TESTFN)

def get_output(self, *args):
return script_helper.assert_python_ok('-m', 'base64', *args).out
Expand All @@ -662,9 +662,9 @@ def test_encode_decode(self):
))

def test_encode_file(self):
with open(support.TESTFN, 'wb') as fp:
with open(os_helper.TESTFN, 'wb') as fp:
fp.write(b'a\xffb\n')
output = self.get_output('-e', support.TESTFN)
output = self.get_output('-e', os_helper.TESTFN)
self.assertEqual(output.rstrip(), b'Yf9iCg==')

def test_encode_from_stdin(self):
Expand All @@ -674,9 +674,9 @@ def test_encode_from_stdin(self):
self.assertIsNone(err)

def test_decode(self):
with open(support.TESTFN, 'wb') as fp:
with open(os_helper.TESTFN, 'wb') as fp:
fp.write(b'Yf9iCg==')
output = self.get_output('-d', support.TESTFN)
output = self.get_output('-d', os_helper.TESTFN)
self.assertEqual(output.rstrip(), b'a\xffb')

if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
from test import support
from test.support import os_helper

import os

Expand Down Expand Up @@ -234,11 +235,11 @@ def test_boolean(self):

def test_fileclosed(self):
try:
with open(support.TESTFN, "w") as f:
with open(os_helper.TESTFN, "w") as f:
self.assertIs(f.closed, False)
self.assertIs(f.closed, True)
finally:
os.remove(support.TESTFN)
os.remove(os_helper.TESTFN)

def test_types(self):
# types are always true.
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_dict_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Test implementation of the PEP 509: dictionary versionning.
"""
import unittest
from test import support
from test.support import import_helper

# PEP 509 is implemented in CPython but other Python implementations
# don't require to implement it
_testcapi = support.import_module('_testcapi')
_testcapi = import_helper.import_module('_testcapi')


class DictVersionTests(unittest.TestCase):
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Python test set -- part 1, grammar.
# This just tests whether the parser accepts them all.

from test.support import check_syntax_error, check_syntax_warning
from test.support import check_syntax_error
from test.support.warnings_helper import check_syntax_warning
import inspect
import unittest
import sys
Expand Down Expand Up @@ -276,7 +277,8 @@ def __getitem__(self, item):

class GrammarTests(unittest.TestCase):

from test.support import check_syntax_error, check_syntax_warning
from test.support import check_syntax_error
from test.support.warnings_helper import check_syntax_warning

# single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
# XXX can't test in a script -- this rule is only used when interactive
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import sys
import unittest
from test.support import run_unittest, TESTFN, unlink, cpython_only
from test.support import run_unittest, cpython_only
from test.support.os_helper import TESTFN, unlink
from test.support import check_free_after_iterating, ALWAYS_EQ, NEVER_EQ
import pickle
import collections.abc
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import unittest

from test.support import (
_4G, TESTFN, import_module, bigmemtest, run_unittest, unlink
_4G, bigmemtest, run_unittest
)
from test.support.import_helper import import_module
from test.support.os_helper import (
TESTFN, unlink
)

lzma = import_module("lzma")
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_mailcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import copy
import test.support
from test.support import os_helper
import unittest

# Location of mailcap file
Expand Down Expand Up @@ -74,7 +75,7 @@ def test_listmailcapfiles(self):
self.assertIsInstance(mcfiles, list)
for m in mcfiles:
self.assertIsInstance(m, str)
with test.support.EnvironmentVarGuard() as env:
with os_helper.EnvironmentVarGuard() as env:
# According to RFC 1524, if MAILCAPS env variable exists, use that
# and only that.
if "MAILCAPS" in env:
Expand Down Expand Up @@ -136,7 +137,7 @@ def test_mock_getcaps(self):
# Test mailcap.getcaps() using mock mailcap file in this dir.
# Temporarily override any existing system mailcap file by pointing the
# MAILCAPS environment variable to our mock file.
with test.support.EnvironmentVarGuard() as env:
with os_helper.EnvironmentVarGuard() as env:
env["MAILCAPS"] = MAILCAPFILE
caps = mailcap.getcaps()
self.assertDictEqual(caps, MAILCAPDICT)
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_memoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import copy
import pickle

from test.support import import_helper


class AbstractMemoryTests:
source_bytes = b"abcdef"
Expand Down Expand Up @@ -508,7 +510,7 @@ class ArrayMemorySliceSliceTest(unittest.TestCase,
class OtherTest(unittest.TestCase):
def test_ctypes_cast(self):
# Issue 15944: Allow all source formats when casting to bytes.
ctypes = test.support.import_module("ctypes")
ctypes = import_helper.import_module("ctypes")
p6 = bytes(ctypes.c_double(0.6))

d = ctypes.c_double()
Expand Down
Loading