1
0

test_virtualenv_mod.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import tempfile
  5. import salt.utils.path
  6. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
  7. from tests.support.case import ModuleCase
  8. from tests.support.helpers import slowTest
  9. from tests.support.runtests import RUNTIME_VARS
  10. from tests.support.unit import skipIf
  11. @skipIf(
  12. salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
  13. )
  14. class VirtualenvModuleTest(ModuleCase):
  15. """
  16. Validate the virtualenv module
  17. """
  18. def setUp(self):
  19. super(VirtualenvModuleTest, self).setUp()
  20. self.venv_test_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  21. self.venv_dir = os.path.join(self.venv_test_dir, "venv")
  22. @slowTest
  23. def test_create_defaults(self):
  24. """
  25. virtualenv.managed
  26. """
  27. self.run_function("virtualenv.create", [self.venv_dir])
  28. pip_file = os.path.join(self.venv_dir, "bin", "pip")
  29. self.assertTrue(os.path.exists(pip_file))
  30. @slowTest
  31. def test_site_packages(self):
  32. pip_bin = os.path.join(self.venv_dir, "bin", "pip")
  33. self.run_function(
  34. "virtualenv.create", [self.venv_dir], system_site_packages=True
  35. )
  36. with_site = self.run_function("pip.freeze", bin_env=pip_bin)
  37. self.run_function("file.remove", [self.venv_dir])
  38. self.run_function("virtualenv.create", [self.venv_dir])
  39. without_site = self.run_function("pip.freeze", bin_env=pip_bin)
  40. self.assertFalse(with_site == without_site)
  41. @slowTest
  42. def test_clear(self):
  43. pip_bin = os.path.join(self.venv_dir, "bin", "pip")
  44. self.run_function("virtualenv.create", [self.venv_dir])
  45. self.run_function("pip.install", [], pkgs="pep8", bin_env=pip_bin)
  46. self.run_function("virtualenv.create", [self.venv_dir], clear=True)
  47. packages = self.run_function("pip.list", prefix="pep8", bin_env=pip_bin)
  48. self.assertFalse("pep8" in packages)
  49. def test_virtualenv_ver(self):
  50. ret = self.run_function("virtualenv.virtualenv_ver", [self.venv_dir])
  51. assert isinstance(ret, list)
  52. assert all([isinstance(x, int) for x in ret])
  53. def tearDown(self):
  54. self.run_function("file.remove", [self.venv_test_dir])