Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 1 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Unittests for virtualenv_wrapper""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | |
| 9 | import os |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 10 | |
| 11 | from chromite.lib import cros_test_lib |
| 12 | |
Allen Li | 465a0d6 | 2016-11-30 14:55:08 -0800 | [diff] [blame^] | 13 | _MODULE_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 14 | _VENV_DIR = os.path.abspath(os.path.join(_MODULE_DIR, '..', '.venv')) |
| 15 | |
| 16 | |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 17 | class VirtualEnvTest(cros_test_lib.TestCase): |
| 18 | """Test that we are running in a virtualenv.""" |
| 19 | |
Allen Li | 465a0d6 | 2016-11-30 14:55:08 -0800 | [diff] [blame^] | 20 | |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 21 | def testModuleIsFromVenv(self): |
Allen Li | 465a0d6 | 2016-11-30 14:55:08 -0800 | [diff] [blame^] | 22 | """Test that we import |six| from the virtualenv.""" |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 23 | # Note: The |six| module is chosen somewhat arbitrarily, but it happens to |
| 24 | # be provided inside the chromite virtualenv. |
Allen Li | 465a0d6 | 2016-11-30 14:55:08 -0800 | [diff] [blame^] | 25 | six = __import__('six') |
Aviv Keshet | 39853bd | 2016-09-22 15:12:05 -0700 | [diff] [blame] | 26 | req_path = os.path.dirname(os.path.realpath(six.__file__)) |
Allen Li | 465a0d6 | 2016-11-30 14:55:08 -0800 | [diff] [blame^] | 27 | self.assertIn(_VENV_DIR, req_path) |
| 28 | |
| 29 | |
| 30 | def testInsideVenv(self): |
| 31 | """Test that we are inside a virtualenv.""" |
| 32 | self.assertIn('VIRTUAL_ENV', os.environ) |
| 33 | venv_dir = os.environ['VIRTUAL_ENV'] |
| 34 | self.assertEqual(_VENV_DIR, venv_dir) |