Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 1 | """Tests for distutils.command.clean.""" |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 2 | import os |
| 3 | import unittest |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 4 | |
| 5 | from distutils.command.clean import clean |
| 6 | from distutils.tests import support |
Éric Araujo | b344dd0 | 2011-02-02 21:38:37 +0000 | [diff] [blame] | 7 | from test.support import run_unittest |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 8 | |
| 9 | class cleanTestCase(support.TempdirManager, |
Tarek Ziadé | ea26163 | 2009-04-05 18:33:34 +0000 | [diff] [blame] | 10 | support.LoggingSilencer, |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 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: |
Serhiy Storchaka | 3998915 | 2013-11-17 00:17:46 +0200 | [diff] [blame] | 37 | self.assertFalse(os.path.exists(path), |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 38 | '%s was not removed' % path) |
| 39 | |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 40 | # let's run the command again (should spit warnings but succeed) |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 41 | cmd.all = 1 |
| 42 | cmd.ensure_finalized() |
| 43 | cmd.run() |
| 44 | |
| 45 | def test_suite(): |
| 46 | return unittest.makeSuite(cleanTestCase) |
| 47 | |
| 48 | if __name__ == "__main__": |
Éric Araujo | b344dd0 | 2011-02-02 21:38:37 +0000 | [diff] [blame] | 49 | run_unittest(test_suite()) |