Add unit tests for it.
@@ -146,6 +146,7 @@ class SandboxingUtilsTestCase(unittest.TestCase):
@mock.patch('os.path.exists', mock.Mock(return_value=True))
@mock.patch('os.path.isdir', mock.Mock(return_value=True))
@mock.patch('os.listdir', mock.Mock(return_value=['python3.6']))
+ @mock.patch('os.path.realpath', mock.Mock(return_value='/usr/lib/python3.6/abc.py'))
@mock.patch('st2common.util.sandboxing.get_python_lib')
@mock.patch('st2common.util.sandboxing.get_pack_base_path',
mock.Mock(return_value='/tmp/packs/dummy_pack'))
@@ -161,16 +162,17 @@ class SandboxingUtilsTestCase(unittest.TestCase):
inherit_parent_virtualenv=False)
split = python_path.strip(':').split(':')
- self.assertEqual(len(split), 3)
+ self.assertEqual(len(split), 4)
- # First entry should be lib/python3 dir from venv
- self.assertTrue('virtualenvs/dummy_pack/lib/python3.6' in split[0])
+ # First entry should be system lib/python3 dir
+ # Second entry should be lib/python3 dir from venv
+ self.assertTrue('virtualenvs/dummy_pack/lib/python3.6' in split[1])
- # Second entry should be python3 site-packages dir from venv
- self.assertTrue('virtualenvs/dummy_pack/lib/python3.6/site-packages' in split[1])
+ # Third entry should be python3 site-packages dir from venv
+ self.assertTrue('virtualenvs/dummy_pack/lib/python3.6/site-packages' in split[2])
- # Third entry should be actions/lib dir from pack root directory
- self.assertTrue('packs/dummy_pack/actions/lib/' in split[2])
+ # Fourth entry should be actions/lib dir from pack root directory
+ self.assertTrue('packs/dummy_pack/actions/lib/' in split[3])
# Inherit python path from current process
# Mock the current process python path
@@ -179,7 +181,8 @@ class SandboxingUtilsTestCase(unittest.TestCase):
python_path = get_sandbox_python_path_for_python_action(pack='dummy_pack',
inherit_from_parent=True,
inherit_parent_virtualenv=False)
- expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6:'
+ expected = ('/usr/lib/python3.6:'
+ '/tmp/virtualenvs/dummy_pack/lib/python3.6:'
'/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:'
'/tmp/packs/dummy_pack/actions/lib/::/data/test1:/data/test2')
self.assertEqual(python_path, expected)
@@ -198,7 +201,8 @@ class SandboxingUtilsTestCase(unittest.TestCase):
inherit_from_parent=True,
inherit_parent_virtualenv=True)
- expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6:'
+ expected = ('/usr/lib/python3.6:'
+ '/tmp/virtualenvs/dummy_pack/lib/python3.6:'
'/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:'
'/tmp/packs/dummy_pack/actions/lib/::/data/test1:/data/test2:'
'%s/virtualenvtest' % (sys.prefix))
