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

Skip to content

Commit bb7c144

Browse files
committed
One unit test for distutils is not much, but is more than we had yesterday.
We need to write more; hopefully the barrier is a little lower now.
1 parent a050171 commit bb7c144

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lib/distutils/tests/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test suite for distutils.
2+
3+
This test suite consists of a collection of test modules in the
4+
distutils.tests package. Each test module has a name starting with
5+
'test' and contains a function test_suite(). The function is expected
6+
to return an initialized unittest.TestSuite instance.
7+
8+
Tests for the command classes in the distutils.command package are
9+
included in distutils.tests as well, instead of using a separate
10+
distutils.command.tests package, since command identification is done
11+
by import rather than matching pre-defined names.
12+
13+
"""
14+
15+
import os
16+
import sys
17+
import unittest
18+
19+
20+
here = os.path.dirname(__file__)
21+
22+
23+
def test_suite():
24+
suite = unittest.TestSuite()
25+
for fn in os.listdir(here):
26+
if fn.startswith("test") and fn.endswith(".py"):
27+
modname = "distutils.tests." + fn[:-3]
28+
__import__(modname)
29+
module = sys.modules[modname]
30+
suite.addTest(module.test_suite())
31+
return suite
32+
33+
34+
if __name__ == "__main__":
35+
unittest.main(defaultTest="test_suite")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Tests for distutils.command.install_scripts."""
2+
3+
import os
4+
import unittest
5+
6+
from distutils.command.install_scripts import install_scripts
7+
from distutils.core import Distribution
8+
9+
10+
class InstallScriptsTestCase(unittest.TestCase):
11+
12+
def test_default_settings(self):
13+
dist = Distribution()
14+
dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
15+
dist.command_obj["install"] = DummyCommand(
16+
install_scripts="/splat/funk",
17+
force=1,
18+
skip_build=1,
19+
)
20+
cmd = install_scripts(dist)
21+
self.assert_(not cmd.force)
22+
self.assert_(not cmd.skip_build)
23+
self.assert_(cmd.build_dir is None)
24+
self.assert_(cmd.install_dir is None)
25+
26+
cmd.finalize_options()
27+
28+
self.assert_(cmd.force)
29+
self.assert_(cmd.skip_build)
30+
self.assertEqual(cmd.build_dir, "/foo/bar")
31+
self.assertEqual(cmd.install_dir, "/splat/funk")
32+
33+
34+
class DummyCommand:
35+
36+
def __init__(self, **kwargs):
37+
for kw, val in kwargs.items():
38+
setattr(self, kw, val)
39+
40+
def ensure_finalized(self):
41+
pass
42+
43+
44+
45+
def test_suite():
46+
return unittest.makeSuite(InstallScriptsTestCase)

Lib/test/test_distutils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Tests for distutils.
2+
3+
The tests for distutils are defined in the distutils.tests package;
4+
the test_suite() function there returns a test suite that's ready to
5+
be run.
6+
"""
7+
8+
import distutils.tests
9+
import test.test_support
10+
11+
12+
def test_main():
13+
test.test_support.run_unittest(distutils.tests.test_suite())
14+
15+
16+
if __name__ == "__main__":
17+
test_main()

0 commit comments

Comments
 (0)