blob: b1b79ba89532a869add27465c40c788b2aa18a19 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for virtualenv_wrapper"""
from __future__ import print_function
import os
import sys
from chromite.lib import cros_test_lib
from chromite.scripts import virtualenv_wrapper
_MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
class VirtualEnvTest(cros_test_lib.TestCase):
"""Test that we are running in a virtualenv."""
# pylint: disable=protected-access
def testModuleIsFromVenv(self):
"""Test that we import |six| from the virtualenv."""
# Note: The |six| module is chosen somewhat arbitrarily, but it happens to
# be provided inside the chromite virtualenv.
six = __import__('six')
req_path = os.path.dirname(os.path.realpath(six.__file__))
self.assertIn('/.cache/cros_venv/', req_path)
def testInsideVenv(self):
"""Test that we are inside a virtualenv."""
# pylint: disable=protected-access
(hasattr(sys, 'real_prefix') or
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)))
def testVenvMarkers(self):
"""Test that the virtualenv marker functions work."""
# pylint: disable=protected-access
test_env = {'PATH': '/bin:/usr/bin'}
new_test_env = virtualenv_wrapper._CreateVenvEnvironment(test_env)
def testCreateVenvEnvironmentNoSideEffect(self):
"""Test that _CreateVenvEnvironment doesn't modify input dict."""
# pylint: disable=protected-access
test_env = {'PATH': '/bin:/usr/bin'}
original = test_env.copy()
self.assertEqual(test_env, original)