test_egg.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.integration.setup.test_egg
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. """
  6. # Import python libs
  7. from __future__ import absolute_import, print_function, unicode_literals
  8. import os
  9. import re
  10. import shutil
  11. # Import salt libs
  12. import salt.utils.path
  13. import salt.utils.platform
  14. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
  15. from tests.support.case import ModuleCase
  16. from tests.support.helpers import VirtualEnv, destructiveTest
  17. # Import Salt Testing libs
  18. from tests.support.runtests import RUNTIME_VARS
  19. from tests.support.unit import skipIf
  20. @destructiveTest
  21. @skipIf(
  22. salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
  23. )
  24. class EggSetupTest(ModuleCase):
  25. """
  26. Tests for building and installing egg packages
  27. """
  28. def setUp(self):
  29. # ensure we have a clean build dir
  30. self._clean_build()
  31. def _clean_build(self):
  32. """
  33. helper method to clean the build dir
  34. """
  35. dirs = [
  36. os.path.join(RUNTIME_VARS.CODE_DIR, "build"),
  37. os.path.join(RUNTIME_VARS.CODE_DIR, "salt.egg-info"),
  38. os.path.join(RUNTIME_VARS.CODE_DIR, "dist"),
  39. ]
  40. for _dir in dirs:
  41. if os.path.exists(_dir):
  42. shutil.rmtree(_dir)
  43. @skipIf(True, "SLOWTEST skip")
  44. def test_egg_install(self):
  45. """
  46. test installing an egg package
  47. """
  48. # Let's create the testing virtualenv
  49. with VirtualEnv() as venv:
  50. ret = self.run_function(
  51. "cmd.run",
  52. [
  53. "{0} setup.py install --prefix={1}".format(
  54. venv.venv_python, venv.venv_dir
  55. )
  56. ],
  57. cwd=RUNTIME_VARS.CODE_DIR,
  58. )
  59. self._clean_build()
  60. lib_dir = os.path.join(venv.venv_dir, "lib")
  61. for _dir in os.listdir(lib_dir):
  62. site_pkg = os.path.join(lib_dir, _dir, "site-packages")
  63. for _file in os.listdir(site_pkg):
  64. if _file.startswith("salt-"):
  65. egg = os.path.join(venv.venv_dir, _file)
  66. assert os.path.exists(
  67. os.path.join(site_pkg, _file, "salt", "_version.py")
  68. )
  69. break
  70. # Let's ensure the version is correct
  71. pip_ver = self.run_function("pip.list", bin_env=venv.venv_dir).get("salt")
  72. egg_ver = [
  73. x for x in egg.split("/")[-1:][0].split("-") if re.search(r"^\d.\d*", x)
  74. ][0]
  75. assert pip_ver == egg_ver.replace("_", "-")