test_clean.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """Tests for distutils.command.clean."""
  2. import sys
  3. import os
  4. import unittest
  5. import getpass
  6. from distutils.command.clean import clean
  7. from distutils.tests import support
  8. from test.support import run_unittest
  9. class cleanTestCase(support.TempdirManager,
  10. support.LoggingSilencer,
  11. unittest.TestCase):
  12. def test_simple_run(self):
  13. pkg_dir, dist = self.create_dist()
  14. cmd = clean(dist)
  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. for name, path in dirs:
  20. os.mkdir(path)
  21. setattr(cmd, name, path)
  22. if name == 'build_base':
  23. continue
  24. for f in ('one', 'two', 'three'):
  25. self.write_file(os.path.join(path, f))
  26. # let's run the command
  27. cmd.all = 1
  28. cmd.ensure_finalized()
  29. cmd.run()
  30. # make sure the files where removed
  31. for name, path in dirs:
  32. self.assertFalse(os.path.exists(path),
  33. '%s was not removed' % path)
  34. # let's run the command again (should spit warnings but succeed)
  35. cmd.all = 1
  36. cmd.ensure_finalized()
  37. cmd.run()
  38. def test_suite():
  39. return unittest.makeSuite(cleanTestCase)
  40. if __name__ == "__main__":
  41. run_unittest(test_suite())