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