blob: eafe80d7eba7601add6594e45268d27c45bb52d7 [file] [log] [blame]
Aviv Keshet39853bd2016-09-22 15:12:05 -07001# 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
7from __future__ import print_function
8
9import os
Aviv Keshet39853bd2016-09-22 15:12:05 -070010
11from chromite.lib import cros_test_lib
12
Allen Li465a0d62016-11-30 14:55:08 -080013_MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
14_VENV_DIR = os.path.abspath(os.path.join(_MODULE_DIR, '..', '.venv'))
15
16
Aviv Keshet39853bd2016-09-22 15:12:05 -070017class VirtualEnvTest(cros_test_lib.TestCase):
18 """Test that we are running in a virtualenv."""
19
Allen Li465a0d62016-11-30 14:55:08 -080020
Aviv Keshet39853bd2016-09-22 15:12:05 -070021 def testModuleIsFromVenv(self):
Allen Li465a0d62016-11-30 14:55:08 -080022 """Test that we import |six| from the virtualenv."""
Aviv Keshet39853bd2016-09-22 15:12:05 -070023 # Note: The |six| module is chosen somewhat arbitrarily, but it happens to
24 # be provided inside the chromite virtualenv.
Allen Li465a0d62016-11-30 14:55:08 -080025 six = __import__('six')
Aviv Keshet39853bd2016-09-22 15:12:05 -070026 req_path = os.path.dirname(os.path.realpath(six.__file__))
Allen Li465a0d62016-11-30 14:55:08 -080027 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)