blob: e84670dff2b8bf95a94bdfb452c05dec0bd8b609 [file] [log] [blame]
Tarek Ziadé02386282009-03-31 20:50:59 +00001"""Tests for distutils.command.clean."""
2import sys
3import os
4import unittest
5import getpass
6
7from distutils.command.clean import clean
8from distutils.tests import support
Éric Araujo54274ad2011-02-03 00:12:18 +00009from test.test_support import run_unittest
Tarek Ziadé02386282009-03-31 20:50:59 +000010
11class cleanTestCase(support.TempdirManager,
Tarek Ziadé453d9532009-04-05 18:31:24 +000012 support.LoggingSilencer,
Tarek Ziadé02386282009-03-31 20:50:59 +000013 unittest.TestCase):
14
15 def test_simple_run(self):
16 pkg_dir, dist = self.create_dist()
17 cmd = clean(dist)
18
19 # let's add some elements clean should remove
20 dirs = [(d, os.path.join(pkg_dir, d))
21 for d in ('build_temp', 'build_lib', 'bdist_base',
22 'build_scripts', 'build_base')]
23
24 for name, path in dirs:
25 os.mkdir(path)
26 setattr(cmd, name, path)
27 if name == 'build_base':
28 continue
29 for f in ('one', 'two', 'three'):
30 self.write_file(os.path.join(path, f))
31
32 # let's run the command
33 cmd.all = 1
34 cmd.ensure_finalized()
35 cmd.run()
36
37 # make sure the files where removed
38 for name, path in dirs:
Serhiy Storchaka25a23ef2013-11-17 00:29:27 +020039 self.assertFalse(os.path.exists(path),
Tarek Ziadé02386282009-03-31 20:50:59 +000040 '%s was not removed' % path)
41
Ezio Melottic2077b02011-03-16 12:34:31 +020042 # let's run the command again (should spit warnings but succeed)
Tarek Ziadé02386282009-03-31 20:50:59 +000043 cmd.all = 1
44 cmd.ensure_finalized()
45 cmd.run()
46
47def test_suite():
48 return unittest.makeSuite(cleanTestCase)
49
50if __name__ == "__main__":
Éric Araujo54274ad2011-02-03 00:12:18 +000051 run_unittest(test_suite())