tests: Pythonize env_wrapper.sh, clean up local_test

issue510
David Wilson 6 years ago
parent a717c5406c
commit 8f1f3de123

@ -1,12 +0,0 @@
#!/bin/bash
# This script exists to test the behavior of Stream.python_path being set to a
# list. It sets an environmnt variable that we can detect, then executes any
# arguments passed to it.
export EXECUTED_VIA_ENV_WRAPPER=1
if [ "${1:0:1}" == "-" ]; then
exec "$PYTHON" "$@"
else
export ENV_WRAPPER_FIRST_ARG="$1"
shift
exec "$@"
fi

@ -0,0 +1,15 @@
#!/usr/bin/env python
import json
import os
import subprocess
import sys
os.environ['ORIGINAL_ARGV'] = json.dumps(sys.argv)
os.environ['THIS_IS_STUB_PYTHON'] = '1'
if sys.argv[1].startswith('-'):
os.execvp(sys.executable, [sys.executable] + sys.argv[1:])
else:
os.environ['STUB_PYTHON_FIRST_ARG'] = sys.argv.pop(1)
os.execvp(sys.executable, sys.argv[1:])

@ -5,11 +5,8 @@ import sys
import unittest2 import unittest2
import mitogen import mitogen
import mitogen.ssh
import mitogen.utils
import testlib import testlib
import plain_old_module
def get_sys_executable(): def get_sys_executable():
@ -20,43 +17,37 @@ def get_os_environ():
return dict(os.environ) return dict(os.environ)
class LocalTest(testlib.RouterMixin, testlib.TestCase): class ConstructionTest(testlib.RouterMixin, testlib.TestCase):
stream_class = mitogen.ssh.Stream stub_python_path = testlib.data_path('stubs/stub-python.py')
def test_stream_name(self): def test_stream_name(self):
context = self.router.local() context = self.router.local()
pid = context.call(os.getpid) pid = context.call(os.getpid)
self.assertEquals('local.%d' % (pid,), context.name) self.assertEquals('local.%d' % (pid,), context.name)
def test_python_path_inherited(self):
class PythonPathTest(testlib.RouterMixin, testlib.TestCase):
stream_class = mitogen.ssh.Stream
def test_inherited(self):
context = self.router.local() context = self.router.local()
self.assertEquals(sys.executable, context.call(get_sys_executable)) self.assertEquals(sys.executable, context.call(get_sys_executable))
def test_string(self): def test_python_path_string(self):
os.environ['PYTHON'] = sys.executable
context = self.router.local( context = self.router.local(
python_path=testlib.data_path('env_wrapper.sh'), python_path=self.stub_python_path,
) )
self.assertEquals(sys.executable, context.call(get_sys_executable))
env = context.call(get_os_environ) env = context.call(get_os_environ)
self.assertEquals('1', env['EXECUTED_VIA_ENV_WRAPPER']) self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])
def test_list(self): def test_python_path_list(self):
context = self.router.local( context = self.router.local(
python_path=[ python_path=[
testlib.data_path('env_wrapper.sh'), self.stub_python_path,
"magic_first_arg", "magic_first_arg",
sys.executable sys.executable
] ]
) )
self.assertEquals(sys.executable, context.call(get_sys_executable)) self.assertEquals(sys.executable, context.call(get_sys_executable))
env = context.call(get_os_environ) env = context.call(get_os_environ)
self.assertEquals('magic_first_arg', env['ENV_WRAPPER_FIRST_ARG']) self.assertEquals('magic_first_arg', env['STUB_PYTHON_FIRST_ARG'])
self.assertEquals('1', env['EXECUTED_VIA_ENV_WRAPPER']) self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save