blob: c605afd86012b693bc5e14c9d5005fda2694d52e [file] [log] [blame]
Tarek Ziadébaf51802009-03-31 21:37:16 +00001"""Tests for distutils.command.clean."""
Tarek Ziadébaf51802009-03-31 21:37:16 +00002import os
3import unittest
Tarek Ziadébaf51802009-03-31 21:37:16 +00004
5from distutils.command.clean import clean
6from distutils.tests import support
Éric Araujob344dd02011-02-02 21:38:37 +00007from test.support import run_unittest
Tarek Ziadébaf51802009-03-31 21:37:16 +00008
9class cleanTestCase(support.TempdirManager,
Tarek Ziadéea261632009-04-05 18:33:34 +000010 support.LoggingSilencer,
Tarek Ziadébaf51802009-03-31 21:37:16 +000011 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:
Serhiy Storchaka39989152013-11-17 00:17:46 +020037 self.assertFalse(os.path.exists(path),
Tarek Ziadébaf51802009-03-31 21:37:16 +000038 '%s was not removed' % path)
39
Ezio Melotti13925002011-03-16 11:05:33 +020040 # let's run the command again (should spit warnings but succeed)
Tarek Ziadébaf51802009-03-31 21:37:16 +000041 cmd.all = 1
42 cmd.ensure_finalized()
43 cmd.run()
44
45def test_suite():
46 return unittest.makeSuite(cleanTestCase)
47
48if __name__ == "__main__":
Éric Araujob344dd02011-02-02 21:38:37 +000049 run_unittest(test_suite())