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