test_virtualenv_mod.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import tempfile
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  8. from tests.support.unit import skipIf
  9. from tests.support.paths import TMP
  10. # Import salt libs
  11. import salt.utils.path
  12. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
  13. @skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
  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=TMP)
  21. self.venv_dir = os.path.join(self.venv_test_dir, 'venv')
  22. def test_create_defaults(self):
  23. '''
  24. virtualenv.managed
  25. '''
  26. self.run_function('virtualenv.create', [self.venv_dir])
  27. pip_file = os.path.join(self.venv_dir, 'bin', 'pip')
  28. self.assertTrue(os.path.exists(pip_file))
  29. def test_site_packages(self):
  30. pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
  31. self.run_function(
  32. 'virtualenv.create', [self.venv_dir], system_site_packages=True
  33. )
  34. with_site = self.run_function('pip.freeze', bin_env=pip_bin)
  35. self.run_function('file.remove', [self.venv_dir])
  36. self.run_function('virtualenv.create', [self.venv_dir])
  37. without_site = self.run_function('pip.freeze', bin_env=pip_bin)
  38. self.assertFalse(with_site == without_site)
  39. def test_clear(self):
  40. pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
  41. self.run_function('virtualenv.create', [self.venv_dir])
  42. self.run_function('pip.install', [], pkgs='pep8', bin_env=pip_bin)
  43. self.run_function('virtualenv.create', [self.venv_dir], clear=True)
  44. packages = self.run_function(
  45. 'pip.list', prefix='pep8', bin_env=pip_bin
  46. )
  47. self.assertFalse('pep8' in packages)
  48. def tearDown(self):
  49. self.run_function('file.remove', [self.venv_test_dir])