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