

@mock.patch('st2common.util.sandboxing.get_python_lib')
def test_get_sandbox_python_path(self, mock_get_python_lib):
    python_path = get_sandbox_python_path(inherit_from_parent=False, inherit_parent_virtualenv=False)
    self.assertEqual(python_path, ':')
    old_python_path = os.environ.get('PYTHONPATH', '')
    os.environ['PYTHONPATH'] = ':/data/test1:/data/test2'
    python_path = get_sandbox_python_path(inherit_from_parent=True, inherit_parent_virtualenv=False)
    self.assertEqual(python_path, ':/data/test1:/data/test2')
    old_real_prefix = sys.real_prefix
    del sys.real_prefix
    python_path = get_sandbox_python_path(inherit_from_parent=True, inherit_parent_virtualenv=False)
    self.assertEqual(python_path, ':/data/test1:/data/test2')
    sys.real_prefix = '/usr'
    mock_get_python_lib.return_value = (sys.prefix + '/virtualenvtest')
    python_path = get_sandbox_python_path(inherit_from_parent=True, inherit_parent_virtualenv=True)
    self.assertEqual(python_path, (':/data/test1:/data/test2:%s/virtualenvtest' % sys.prefix))
    os.environ['PYTHONPATH'] = old_python_path
    sys.real_prefix = old_real_prefix

dataset/ETHPy150Open StackStorm/st2/st2common/tests/unit/test_util_sandboxing.py SandboxingUtilsTestCase.test_get_sandbox_python_path/original