test_clean.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Tests for distutils.command.clean."""
  2. import os
  3. from distutils.command.clean import clean
  4. from distutils.tests import support
  5. class TestClean(support.TempdirManager):
  6. def test_simple_run(self):
  7. pkg_dir, dist = self.create_dist()
  8. cmd = clean(dist)
  9. # let's add some elements clean should remove
  10. dirs = [
  11. (d, os.path.join(pkg_dir, d))
  12. for d in (
  13. 'build_temp',
  14. 'build_lib',
  15. 'bdist_base',
  16. 'build_scripts',
  17. 'build_base',
  18. )
  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. # let's run the command
  28. cmd.all = 1
  29. cmd.ensure_finalized()
  30. cmd.run()
  31. # make sure the files where removed
  32. for _name, path in dirs:
  33. assert not os.path.exists(path), f'{path} was not removed'
  34. # let's run the command again (should spit warnings but succeed)
  35. cmd.all = 1
  36. cmd.ensure_finalized()
  37. cmd.run()