Skip to content

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

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 3 commits into from
Jul 9, 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
100 changes: 51 additions & 49 deletions Lib/test/test_cmd_line_script.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import unittest
from test import support
from test.support import warnings_helper

from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
import io
Expand Down Expand Up @@ -305,7 +306,7 @@ def test_filename(self):

def test_warning(self):
# Test that the warning is only returned once.
with support.check_warnings((".*literal", SyntaxWarning)) as w:
with warnings_helper.check_warnings((".*literal", SyntaxWarning)) as w:
compile_command("0 is 0")
self.assertEqual(len(w.warnings), 1)

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
from contextlib import * # Tests __all__
from test import support
from test.support import os_helper
import weakref


Expand Down Expand Up @@ -327,7 +328,7 @@ def testWithOpen(self):
1 / 0
self.assertTrue(f.closed)
finally:
support.unlink(tfn)
os_helper.unlink(tfn)

class LockContextTestCase(unittest.TestCase):

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_dbm_ndbm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from test import support
support.import_module("dbm.ndbm") #skip if not supported
from test.support import import_helper
import_helper.import_module("dbm.ndbm") #skip if not supported
import os
import unittest
import dbm.ndbm
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import string
import sys
from test import support
from test.support import import_helper
# Skip this test if the _testcapi module isn't available.
_testcapi = support.import_module('_testcapi')
_testcapi = import_helper.import_module('_testcapi')
from _testcapi import getargs_keywords, getargs_keyword_only

# > How about the following counterproposal. This also changes some of
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

from test import support
from test.support import os_helper


# TODO:
Expand Down Expand Up @@ -129,14 +130,14 @@ def setUp(self):
fp.write(base64.decodebytes(UMO_DATA))
with open(MMOFILE, 'wb') as fp:
fp.write(base64.decodebytes(MMO_DATA))
self.env = support.EnvironmentVarGuard()
self.env = os_helper.EnvironmentVarGuard()
self.env['LANGUAGE'] = 'xx'
gettext._translations.clear()

def tearDown(self):
self.env.__exit__()
del self.env
support.rmtree(os.path.split(LOCALEDIR)[0])
os_helper.rmtree(os.path.split(LOCALEDIR)[0])

GNU_MO_DATA_ISSUE_17898 = b'''\
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
import unittest

from test.support import (TESTFN, skip_unless_symlink,
can_symlink, create_empty_file, change_cwd)
from test.support.os_helper import (TESTFN, skip_unless_symlink,
can_symlink, create_empty_file, change_cwd)


class GlobTests(unittest.TestCase):
Expand Down
23 changes: 12 additions & 11 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
from unittest import mock

import test.support
from test.support import (
TESTFN, forget, is_jython,
make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask,
unlink, unload, cpython_only, TESTFN_UNENCODABLE,
temp_dir, DirsOnSysPath)
from test.support import os_helper
from test.support import (is_jython, swap_attr, swap_item, cpython_only)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, DirsOnSysPath)
from test.support.os_helper import (
TESTFN, rmtree, temp_umask, TESTFN_UNENCODABLE, temp_dir)
from test.support import script_helper
from test.support import threading_helper
from test.test_importlib.util import uncache
Expand Down Expand Up @@ -997,22 +998,22 @@ class TestSymbolicallyLinkedPackage(unittest.TestCase):
tagged = package_name + '-tagged'

def setUp(self):
test.support.rmtree(self.tagged)
test.support.rmtree(self.package_name)
os_helper.rmtree(self.tagged)
os_helper.rmtree(self.package_name)
self.orig_sys_path = sys.path[:]

# create a sample package; imagine you have a package with a tag and
# you want to symbolically link it from its untagged name.
os.mkdir(self.tagged)
self.addCleanup(test.support.rmtree, self.tagged)
self.addCleanup(os_helper.rmtree, self.tagged)
init_file = os.path.join(self.tagged, '__init__.py')
test.support.create_empty_file(init_file)
os_helper.create_empty_file(init_file)
assert os.path.exists(init_file)

# now create a symlink to the tagged package
# sample -> sample-tagged
os.symlink(self.tagged, self.package_name, target_is_directory=True)
self.addCleanup(test.support.unlink, self.package_name)
self.addCleanup(os_helper.unlink, self.package_name)
importlib.invalidate_caches()

self.assertEqual(os.path.isdir(self.package_name), True)
Expand All @@ -1027,7 +1028,7 @@ def tearDown(self):
not hasattr(sys, 'getwindowsversion')
or sys.getwindowsversion() >= (6, 0),
"Windows Vista or later required")
@test.support.skip_unless_symlink
@os_helper.skip_unless_symlink
def test_symlinked_dir_importable(self):
# make sure sample can only be imported from the current directory.
sys.path[:] = ['.']
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_locale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.support import verbose, is_android, check_warnings
from test.support import verbose, is_android
from test.support.warnings_helper import check_warnings
import unittest
import locale
import sys
Expand Down
41 changes: 21 additions & 20 deletions Lib/test/test_mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io
import tempfile
from test import support
from test.support import os_helper
import unittest
import textwrap
import mailbox
Expand Down Expand Up @@ -38,9 +39,9 @@ def _check_sample(self, msg):
def _delete_recursively(self, target):
# Delete a file or delete a directory recursively
if os.path.isdir(target):
support.rmtree(target)
os_helper.rmtree(target)
elif os.path.exists(target):
support.unlink(target)
os_helper.unlink(target)


class TestMailbox(TestBase):
Expand All @@ -51,7 +52,7 @@ class TestMailbox(TestBase):
_template = 'From: foo\n\n%s\n'

def setUp(self):
self._path = support.TESTFN
self._path = os_helper.TESTFN
self._delete_recursively(self._path)
self._box = self._factory(self._path)

Expand Down Expand Up @@ -926,7 +927,7 @@ def refreshed():
# the mtime and should cause a re-read. Note that "sleep
# emulation" is still in effect, as skewfactor is -3.
filename = os.path.join(self._path, 'cur', 'stray-file')
support.create_empty_file(filename)
os_helper.create_empty_file(filename)
os.unlink(filename)
self._box._refresh()
self.assertTrue(refreshed())
Expand Down Expand Up @@ -980,7 +981,7 @@ def tearDown(self):
self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
support.unlink(lock_remnant)
os_helper.unlink(lock_remnant)

def assertMailboxEmpty(self):
with open(self._path) as f:
Expand Down Expand Up @@ -1312,7 +1313,7 @@ def tearDown(self):
self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(glob.escape(self._path) + '.*'):
support.unlink(lock_remnant)
os_helper.unlink(lock_remnant)

def test_labels(self):
# Get labels from the mailbox
Expand Down Expand Up @@ -1369,7 +1370,7 @@ class TestMessage(TestBase, unittest.TestCase):
_factory = mailbox.Message # Overridden by subclasses to reuse tests

def setUp(self):
self._path = support.TESTFN
self._path = os_helper.TESTFN

def tearDown(self):
self._delete_recursively(self._path)
Expand Down Expand Up @@ -2019,7 +2020,7 @@ def _test_close(self, proxy):
class TestProxyFile(TestProxyFileBase, unittest.TestCase):

def setUp(self):
self._path = support.TESTFN
self._path = os_helper.TESTFN
self._file = open(self._path, 'wb+')

def tearDown(self):
Expand Down Expand Up @@ -2068,7 +2069,7 @@ def test_close(self):
class TestPartialFile(TestProxyFileBase, unittest.TestCase):

def setUp(self):
self._path = support.TESTFN
self._path = os_helper.TESTFN
self._file = open(self._path, 'wb+')

def tearDown(self):
Expand Down Expand Up @@ -2131,11 +2132,11 @@ class MaildirTestCase(unittest.TestCase):

def setUp(self):
# create a new maildir mailbox to work with:
self._dir = support.TESTFN
self._dir = os_helper.TESTFN
if os.path.isdir(self._dir):
support.rmtree(self._dir)
os_helper.rmtree(self._dir)
elif os.path.isfile(self._dir):
support.unlink(self._dir)
os_helper.unlink(self._dir)
os.mkdir(self._dir)
os.mkdir(os.path.join(self._dir, "cur"))
os.mkdir(os.path.join(self._dir, "tmp"))
Expand All @@ -2145,10 +2146,10 @@ def setUp(self):

def tearDown(self):
list(map(os.unlink, self._msgfiles))
support.rmdir(os.path.join(self._dir, "cur"))
support.rmdir(os.path.join(self._dir, "tmp"))
support.rmdir(os.path.join(self._dir, "new"))
support.rmdir(self._dir)
os_helper.rmdir(os.path.join(self._dir, "cur"))
os_helper.rmdir(os.path.join(self._dir, "tmp"))
os_helper.rmdir(os.path.join(self._dir, "new"))
os_helper.rmdir(self._dir)

def createMessage(self, dir, mbox=False):
t = int(time.time() % 1000000)
Expand All @@ -2174,23 +2175,23 @@ def test_empty_maildir(self):
"""Test an empty maildir mailbox"""
# Test for regression on bug #117490:
# Make sure the boxes attribute actually gets set.
self.mbox = mailbox.Maildir(support.TESTFN)
self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertTrue(hasattr(self.mbox, "boxes"))
#self.assertEqual(len(self.mbox.boxes), 0)
self.assertIsNone(self.mbox.next())
self.assertIsNone(self.mbox.next())

def test_nonempty_maildir_cur(self):
self.createMessage("cur")
self.mbox = mailbox.Maildir(support.TESTFN)
self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 1)
self.assertIsNotNone(self.mbox.next())
self.assertIsNone(self.mbox.next())
self.assertIsNone(self.mbox.next())

def test_nonempty_maildir_new(self):
self.createMessage("new")
self.mbox = mailbox.Maildir(support.TESTFN)
self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 1)
self.assertIsNotNone(self.mbox.next())
self.assertIsNone(self.mbox.next())
Expand All @@ -2199,7 +2200,7 @@ def test_nonempty_maildir_new(self):
def test_nonempty_maildir_both(self):
self.createMessage("cur")
self.createMessage("new")
self.mbox = mailbox.Maildir(support.TESTFN)
self.mbox = mailbox.Maildir(os_helper.TESTFN)
#self.assertEqual(len(self.mbox.boxes), 2)
self.assertIsNotNone(self.mbox.next())
self.assertIsNotNone(self.mbox.next())
Expand Down
Loading