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