ยปCore Development>Code coverage>Lib/distutils/tests/test_config_cmd.py

Python code coverage for Lib/distutils/tests/test_config_cmd.py

#countcontent
1n/a"""Tests for distutils.command.config."""
2n/aimport unittest
3n/aimport os
4n/aimport sys
5n/afrom test.support import run_unittest, missing_compiler_executable
6n/a
7n/afrom distutils.command.config import dump_file, config
8n/afrom distutils.tests import support
9n/afrom distutils import log
10n/a
11n/aclass ConfigTestCase(support.LoggingSilencer,
12n/a support.TempdirManager,
13n/a unittest.TestCase):
14n/a
15n/a def _info(self, msg, *args):
16n/a for line in msg.splitlines():
17n/a self._logs.append(line)
18n/a
19n/a def setUp(self):
20n/a super(ConfigTestCase, self).setUp()
21n/a self._logs = []
22n/a self.old_log = log.info
23n/a log.info = self._info
24n/a
25n/a def tearDown(self):
26n/a log.info = self.old_log
27n/a super(ConfigTestCase, self).tearDown()
28n/a
29n/a def test_dump_file(self):
30n/a this_file = os.path.splitext(__file__)[0] + '.py'
31n/a f = open(this_file)
32n/a try:
33n/a numlines = len(f.readlines())
34n/a finally:
35n/a f.close()
36n/a
37n/a dump_file(this_file, 'I am the header')
38n/a self.assertEqual(len(self._logs), numlines+1)
39n/a
40n/a @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
41n/a def test_search_cpp(self):
42n/a cmd = missing_compiler_executable(['preprocessor'])
43n/a if cmd is not None:
44n/a self.skipTest('The %r command is not found' % cmd)
45n/a pkg_dir, dist = self.create_dist()
46n/a cmd = config(dist)
47n/a
48n/a # simple pattern searches
49n/a match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
50n/a self.assertEqual(match, 0)
51n/a
52n/a match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
53n/a self.assertEqual(match, 1)
54n/a
55n/a def test_finalize_options(self):
56n/a # finalize_options does a bit of transformation
57n/a # on options
58n/a pkg_dir, dist = self.create_dist()
59n/a cmd = config(dist)
60n/a cmd.include_dirs = 'one%stwo' % os.pathsep
61n/a cmd.libraries = 'one'
62n/a cmd.library_dirs = 'three%sfour' % os.pathsep
63n/a cmd.ensure_finalized()
64n/a
65n/a self.assertEqual(cmd.include_dirs, ['one', 'two'])
66n/a self.assertEqual(cmd.libraries, ['one'])
67n/a self.assertEqual(cmd.library_dirs, ['three', 'four'])
68n/a
69n/a def test_clean(self):
70n/a # _clean removes files
71n/a tmp_dir = self.mkdtemp()
72n/a f1 = os.path.join(tmp_dir, 'one')
73n/a f2 = os.path.join(tmp_dir, 'two')
74n/a
75n/a self.write_file(f1, 'xxx')
76n/a self.write_file(f2, 'xxx')
77n/a
78n/a for f in (f1, f2):
79n/a self.assertTrue(os.path.exists(f))
80n/a
81n/a pkg_dir, dist = self.create_dist()
82n/a cmd = config(dist)
83n/a cmd._clean(f1, f2)
84n/a
85n/a for f in (f1, f2):
86n/a self.assertFalse(os.path.exists(f))
87n/a
88n/adef test_suite():
89n/a return unittest.makeSuite(ConfigTestCase)
90n/a
91n/aif __name__ == "__main__":
92n/a run_unittest(test_suite())