Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b5c7f4

Browse files
committed
Remove unused code from packaging.tests.__init__
1 parent 3650034 commit 9b5c7f4

4 files changed

Lines changed: 10 additions & 108 deletions

File tree

Lib/packaging/tests/__init__.py

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -14,117 +14,15 @@
1414
import os
1515
import sys
1616
import unittest
17-
from io import StringIO
1817

19-
# XXX move helpers to support, add tests for them, remove things that
20-
# duplicate test.support (or keep them for the backport; needs thinking)
21-
22-
here = os.path.dirname(__file__) or os.curdir
23-
verbose = 1
2418

2519
def test_suite():
2620
suite = unittest.TestSuite()
21+
here = os.path.dirname(__file__) or os.curdir
2722
for fn in os.listdir(here):
2823
if fn.startswith("test") and fn.endswith(".py"):
2924
modname = "packaging.tests." + fn[:-3]
3025
__import__(modname)
3126
module = sys.modules[modname]
3227
suite.addTest(module.test_suite())
3328
return suite
34-
35-
36-
class Error(Exception):
37-
"""Base class for regression test exceptions."""
38-
39-
40-
class TestFailed(Error):
41-
"""Test failed."""
42-
43-
44-
class BasicTestRunner:
45-
def run(self, test):
46-
result = unittest.TestResult()
47-
test(result)
48-
return result
49-
50-
51-
def _run_suite(suite, verbose_=1):
52-
"""Run tests from a unittest.TestSuite-derived class."""
53-
global verbose
54-
verbose = verbose_
55-
if verbose_:
56-
runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
57-
else:
58-
runner = BasicTestRunner()
59-
60-
result = runner.run(suite)
61-
if not result.wasSuccessful():
62-
if len(result.errors) == 1 and not result.failures:
63-
err = result.errors[0][1]
64-
elif len(result.failures) == 1 and not result.errors:
65-
err = result.failures[0][1]
66-
else:
67-
err = "errors occurred; run in verbose mode for details"
68-
raise TestFailed(err)
69-
70-
71-
def run_unittest(classes, verbose_=1):
72-
"""Run tests from unittest.TestCase-derived classes.
73-
74-
Originally extracted from stdlib test.test_support and modified to
75-
support unittest2.
76-
"""
77-
valid_types = (unittest.TestSuite, unittest.TestCase)
78-
suite = unittest.TestSuite()
79-
for cls in classes:
80-
if isinstance(cls, str):
81-
if cls in sys.modules:
82-
suite.addTest(unittest.findTestCases(sys.modules[cls]))
83-
else:
84-
raise ValueError("str arguments must be keys in sys.modules")
85-
elif isinstance(cls, valid_types):
86-
suite.addTest(cls)
87-
else:
88-
suite.addTest(unittest.makeSuite(cls))
89-
_run_suite(suite, verbose_)
90-
91-
92-
def reap_children():
93-
"""Use this function at the end of test_main() whenever sub-processes
94-
are started. This will help ensure that no extra children (zombies)
95-
stick around to hog resources and create problems when looking
96-
for refleaks.
97-
98-
Extracted from stdlib test.support.
99-
"""
100-
101-
# Reap all our dead child processes so we don't leave zombies around.
102-
# These hog resources and might be causing some of the buildbots to die.
103-
if hasattr(os, 'waitpid'):
104-
any_process = -1
105-
while True:
106-
try:
107-
# This will raise an exception on Windows. That's ok.
108-
pid, status = os.waitpid(any_process, os.WNOHANG)
109-
if pid == 0:
110-
break
111-
except:
112-
break
113-
114-
115-
def captured_stdout(func, *args, **kw):
116-
orig_stdout = getattr(sys, 'stdout')
117-
setattr(sys, 'stdout', StringIO())
118-
try:
119-
res = func(*args, **kw)
120-
sys.stdout.seek(0)
121-
return res, sys.stdout.read()
122-
finally:
123-
setattr(sys, 'stdout', orig_stdout)
124-
125-
126-
def unload(name):
127-
try:
128-
del sys.modules[name]
129-
except KeyError:
130-
pass

Lib/packaging/tests/test_command_bdist.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests for distutils.command.bdist."""
22
import os
3+
from test.support import captured_stdout
34
from packaging.command.bdist import bdist, show_formats
4-
from packaging.tests import unittest, support, captured_stdout
5+
from packaging.tests import unittest, support
56

67

78
class BuildTestCase(support.TempdirManager,
@@ -42,7 +43,9 @@ def test_skip_build(self):
4243
'%s should take --skip-build from bdist' % name)
4344

4445
def test_show_formats(self):
45-
__, stdout = captured_stdout(show_formats)
46+
with captured_stdout() as stdout:
47+
show_formats()
48+
stdout = stdout.getvalue()
4649

4750
# the output should be a header line + one line per format
4851
num_formats = len(bdist.format_commands)

Lib/packaging/tests/test_command_sdist.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from packaging.errors import PackagingOptionError
1818
from packaging.command.sdist import sdist, show_formats
1919

20+
from test.support import captured_stdout
2021
from packaging.tests import support, unittest
21-
from packaging.tests import captured_stdout
2222
from packaging.tests.support import requires_zlib
2323

2424

@@ -234,7 +234,9 @@ def test_metadata_check_option(self):
234234
self.assertIn("'setup.cfg' file not found", warnings[1])
235235

236236
def test_show_formats(self):
237-
__, stdout = captured_stdout(show_formats)
237+
with captured_stdout() as stdout:
238+
show_formats()
239+
stdout = stdout.getvalue()
238240

239241
# the output should be a header line + one line per format
240242
num_formats = len(get_archive_formats())

Lib/packaging/tests/test_dist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from packaging.dist import Distribution
99
from packaging.command.cmd import Command
1010
from packaging.errors import PackagingModuleError, PackagingOptionError
11-
from packaging.tests import captured_stdout
1211
from packaging.tests import support, unittest
1312
from packaging.tests.support import create_distribution, use_command
1413
from test.support import unload

0 commit comments

Comments
 (0)