mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
bpo-40275: Use new test.support helper submodules in tests (GH-21448)
This commit is contained in:
parent
bb0424b122
commit
4660597b51
20 changed files with 185 additions and 154 deletions
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
from io import StringIO
|
||||
from test import support
|
||||
from test.support import os_helper
|
||||
|
||||
|
||||
import optparse
|
||||
|
|
@ -1021,10 +1022,10 @@ def setUp(self):
|
|||
self.parser.add_option("-f", "--file", type="file", dest="file")
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.isdir(support.TESTFN):
|
||||
os.rmdir(support.TESTFN)
|
||||
elif os.path.isfile(support.TESTFN):
|
||||
os.unlink(support.TESTFN)
|
||||
if os.path.isdir(os_helper.TESTFN):
|
||||
os.rmdir(os_helper.TESTFN)
|
||||
elif os.path.isfile(os_helper.TESTFN):
|
||||
os.unlink(os_helper.TESTFN)
|
||||
|
||||
class MyOption (Option):
|
||||
def check_file(option, opt, value):
|
||||
|
|
@ -1039,21 +1040,21 @@ def check_file(option, opt, value):
|
|||
TYPE_CHECKER["file"] = check_file
|
||||
|
||||
def test_filetype_ok(self):
|
||||
support.create_empty_file(support.TESTFN)
|
||||
self.assertParseOK(["--file", support.TESTFN, "-afoo"],
|
||||
{'file': support.TESTFN, 'a': 'foo'},
|
||||
os_helper.create_empty_file(os_helper.TESTFN)
|
||||
self.assertParseOK(["--file", os_helper.TESTFN, "-afoo"],
|
||||
{'file': os_helper.TESTFN, 'a': 'foo'},
|
||||
[])
|
||||
|
||||
def test_filetype_noexist(self):
|
||||
self.assertParseFail(["--file", support.TESTFN, "-afoo"],
|
||||
self.assertParseFail(["--file", os_helper.TESTFN, "-afoo"],
|
||||
"%s: file does not exist" %
|
||||
support.TESTFN)
|
||||
os_helper.TESTFN)
|
||||
|
||||
def test_filetype_notfile(self):
|
||||
os.mkdir(support.TESTFN)
|
||||
self.assertParseFail(["--file", support.TESTFN, "-afoo"],
|
||||
os.mkdir(os_helper.TESTFN)
|
||||
self.assertParseFail(["--file", os_helper.TESTFN, "-afoo"],
|
||||
"%s: not a regular file" %
|
||||
support.TESTFN)
|
||||
os_helper.TESTFN)
|
||||
|
||||
|
||||
class TestExtendAddActions(BaseTest):
|
||||
|
|
@ -1497,7 +1498,7 @@ def make_parser(self, columns):
|
|||
# we must restore its original value -- otherwise, this test
|
||||
# screws things up for other tests when it's part of the Python
|
||||
# test suite.
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env['COLUMNS'] = str(columns)
|
||||
return InterceptingOptionParser(option_list=options)
|
||||
|
||||
|
|
@ -1522,7 +1523,7 @@ def test_help_long_opts_first(self):
|
|||
self.assertHelpEquals(_expected_help_long_opts_first)
|
||||
|
||||
def test_help_title_formatter(self):
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env["COLUMNS"] = "80"
|
||||
self.parser.formatter = TitledHelpFormatter()
|
||||
self.assertHelpEquals(_expected_help_title_formatter)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue