1 | n/a | """Tests for distutils.command.clean.""" |
---|
2 | n/a | import os |
---|
3 | n/a | import unittest |
---|
4 | n/a | |
---|
5 | n/a | from distutils.command.clean import clean |
---|
6 | n/a | from distutils.tests import support |
---|
7 | n/a | from test.support import run_unittest |
---|
8 | n/a | |
---|
9 | n/a | class cleanTestCase(support.TempdirManager, |
---|
10 | n/a | support.LoggingSilencer, |
---|
11 | n/a | unittest.TestCase): |
---|
12 | n/a | |
---|
13 | n/a | def test_simple_run(self): |
---|
14 | n/a | pkg_dir, dist = self.create_dist() |
---|
15 | n/a | cmd = clean(dist) |
---|
16 | n/a | |
---|
17 | n/a | # let's add some elements clean should remove |
---|
18 | n/a | dirs = [(d, os.path.join(pkg_dir, d)) |
---|
19 | n/a | for d in ('build_temp', 'build_lib', 'bdist_base', |
---|
20 | n/a | 'build_scripts', 'build_base')] |
---|
21 | n/a | |
---|
22 | n/a | for name, path in dirs: |
---|
23 | n/a | os.mkdir(path) |
---|
24 | n/a | setattr(cmd, name, path) |
---|
25 | n/a | if name == 'build_base': |
---|
26 | n/a | continue |
---|
27 | n/a | for f in ('one', 'two', 'three'): |
---|
28 | n/a | self.write_file(os.path.join(path, f)) |
---|
29 | n/a | |
---|
30 | n/a | # let's run the command |
---|
31 | n/a | cmd.all = 1 |
---|
32 | n/a | cmd.ensure_finalized() |
---|
33 | n/a | cmd.run() |
---|
34 | n/a | |
---|
35 | n/a | # make sure the files where removed |
---|
36 | n/a | for name, path in dirs: |
---|
37 | n/a | self.assertFalse(os.path.exists(path), |
---|
38 | n/a | '%s was not removed' % path) |
---|
39 | n/a | |
---|
40 | n/a | # let's run the command again (should spit warnings but succeed) |
---|
41 | n/a | cmd.all = 1 |
---|
42 | n/a | cmd.ensure_finalized() |
---|
43 | n/a | cmd.run() |
---|
44 | n/a | |
---|
45 | n/a | def test_suite(): |
---|
46 | n/a | return unittest.makeSuite(cleanTestCase) |
---|
47 | n/a | |
---|
48 | n/a | if __name__ == "__main__": |
---|
49 | n/a | run_unittest(test_suite()) |
---|