test_clean.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Tests for distutils.command.clean."""
  2. import os
  3. import unittest
  4. from distutils.command.clean import clean
  5. from distutils.tests import support
  6. from test.support import run_unittest
  7. class cleanTestCase(support.TempdirManager,
  8. support.LoggingSilencer,
  9. unittest.TestCase):
  10. def test_simple_run(self):
  11. pkg_dir, dist = self.create_dist()
  12. cmd = clean(dist)
  13. # let's add some elements clean should remove
  14. dirs = [(d, os.path.join(pkg_dir, d))
  15. for d in ('build_temp', 'build_lib', 'bdist_base',
  16. 'build_scripts', 'build_base')]
  17. for name, path in dirs:
  18. os.mkdir(path)
  19. setattr(cmd, name, path)
  20. if name == 'build_base':
  21. continue
  22. for f in ('one', 'two', 'three'):
  23. self.write_file(os.path.join(path, f))
  24. # let's run the command
  25. cmd.all = 1
  26. cmd.ensure_finalized()
  27. cmd.run()
  28. # make sure the files where removed
  29. for name, path in dirs:
  30. self.assertFalse(os.path.exists(path),
  31. '%s was not removed' % path)
  32. # let's run the command again (should spit warnings but succeed)
  33. cmd.all = 1
  34. cmd.ensure_finalized()
  35. cmd.run()
  36. def test_suite():
  37. return unittest.makeSuite(cleanTestCase)
  38. if __name__ == "__main__":
  39. run_unittest(test_suite())