test_install_data.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """Tests for distutils.command.install_data."""
  2. import os
  3. import pathlib
  4. from distutils.command.install_data import install_data
  5. from distutils.tests import support
  6. import pytest
  7. @pytest.mark.usefixtures('save_env')
  8. class TestInstallData(
  9. support.TempdirManager,
  10. ):
  11. def test_simple_run(self):
  12. pkg_dir, dist = self.create_dist()
  13. cmd = install_data(dist)
  14. cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
  15. # data_files can contain
  16. # - simple files
  17. # - a Path object
  18. # - a tuple with a path, and a list of file
  19. one = os.path.join(pkg_dir, 'one')
  20. self.write_file(one, 'xxx')
  21. inst2 = os.path.join(pkg_dir, 'inst2')
  22. two = os.path.join(pkg_dir, 'two')
  23. self.write_file(two, 'xxx')
  24. three = pathlib.Path(pkg_dir) / 'three'
  25. self.write_file(three, 'xxx')
  26. cmd.data_files = [one, (inst2, [two]), three]
  27. assert cmd.get_inputs() == [one, (inst2, [two]), three]
  28. # let's run the command
  29. cmd.ensure_finalized()
  30. cmd.run()
  31. # let's check the result
  32. assert len(cmd.get_outputs()) == 3
  33. rthree = os.path.split(one)[-1]
  34. assert os.path.exists(os.path.join(inst, rthree))
  35. rtwo = os.path.split(two)[-1]
  36. assert os.path.exists(os.path.join(inst2, rtwo))
  37. rone = os.path.split(one)[-1]
  38. assert os.path.exists(os.path.join(inst, rone))
  39. cmd.outfiles = []
  40. # let's try with warn_dir one
  41. cmd.warn_dir = True
  42. cmd.ensure_finalized()
  43. cmd.run()
  44. # let's check the result
  45. assert len(cmd.get_outputs()) == 3
  46. assert os.path.exists(os.path.join(inst, rthree))
  47. assert os.path.exists(os.path.join(inst2, rtwo))
  48. assert os.path.exists(os.path.join(inst, rone))
  49. cmd.outfiles = []
  50. # now using root and empty dir
  51. cmd.root = os.path.join(pkg_dir, 'root')
  52. inst5 = os.path.join(pkg_dir, 'inst5')
  53. four = os.path.join(cmd.install_dir, 'four')
  54. self.write_file(four, 'xx')
  55. cmd.data_files = [one, (inst2, [two]), three, ('inst5', [four]), (inst5, [])]
  56. cmd.ensure_finalized()
  57. cmd.run()
  58. # let's check the result
  59. assert len(cmd.get_outputs()) == 5
  60. assert os.path.exists(os.path.join(inst, rthree))
  61. assert os.path.exists(os.path.join(inst2, rtwo))
  62. assert os.path.exists(os.path.join(inst, rone))