2017-09-29 10:34:09 +00:00
|
|
|
|
|
|
|
import os
|
2018-07-17 22:16:54 +00:00
|
|
|
import sys
|
2017-11-11 22:59:38 +00:00
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
import unittest2
|
2017-09-29 10:34:09 +00:00
|
|
|
|
|
|
|
import mitogen
|
|
|
|
|
|
|
|
import testlib
|
|
|
|
|
|
|
|
|
2018-07-17 22:16:54 +00:00
|
|
|
def get_sys_executable():
|
|
|
|
return sys.executable
|
|
|
|
|
|
|
|
|
|
|
|
def get_os_environ():
|
|
|
|
return dict(os.environ)
|
|
|
|
|
|
|
|
|
2018-11-06 12:43:12 +00:00
|
|
|
class ConstructionTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
stub_python_path = testlib.data_path('stubs/stub-python.py')
|
2017-09-29 10:34:09 +00:00
|
|
|
|
|
|
|
def test_stream_name(self):
|
|
|
|
context = self.router.local()
|
|
|
|
pid = context.call(os.getpid)
|
|
|
|
self.assertEquals('local.%d' % (pid,), context.name)
|
|
|
|
|
2018-11-06 12:43:12 +00:00
|
|
|
def test_python_path_inherited(self):
|
2018-07-17 22:16:54 +00:00
|
|
|
context = self.router.local()
|
|
|
|
self.assertEquals(sys.executable, context.call(get_sys_executable))
|
|
|
|
|
2018-11-06 12:43:12 +00:00
|
|
|
def test_python_path_string(self):
|
2018-07-17 22:16:54 +00:00
|
|
|
context = self.router.local(
|
2018-11-06 12:43:12 +00:00
|
|
|
python_path=self.stub_python_path,
|
2018-07-17 22:16:54 +00:00
|
|
|
)
|
|
|
|
env = context.call(get_os_environ)
|
2018-11-06 12:43:12 +00:00
|
|
|
self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])
|
2018-07-17 22:16:54 +00:00
|
|
|
|
2018-11-06 12:43:12 +00:00
|
|
|
def test_python_path_list(self):
|
2018-07-17 22:16:54 +00:00
|
|
|
context = self.router.local(
|
|
|
|
python_path=[
|
2018-11-06 12:43:12 +00:00
|
|
|
self.stub_python_path,
|
2018-07-17 22:16:54 +00:00
|
|
|
"magic_first_arg",
|
|
|
|
sys.executable
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.assertEquals(sys.executable, context.call(get_sys_executable))
|
|
|
|
env = context.call(get_os_environ)
|
2018-11-06 12:43:12 +00:00
|
|
|
self.assertEquals('magic_first_arg', env['STUB_PYTHON_FIRST_ARG'])
|
|
|
|
self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])
|
2018-07-17 22:16:54 +00:00
|
|
|
|
|
|
|
|
2017-09-29 10:34:09 +00:00
|
|
|
if __name__ == '__main__':
|
2017-11-12 12:42:27 +00:00
|
|
|
unittest2.main()
|