From 137f5fa6c5cea5ca13524a34fefe10eb17b52ab5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 27 Jan 2019 00:37:13 +0000 Subject: [PATCH] issue #477: add basic su_test and Py2.4 polyfill. --- mitogen/su.py | 5 +++++ tests/su_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/su_test.py diff --git a/mitogen/su.py b/mitogen/su.py index 5f52e08b..b0bac28b 100644 --- a/mitogen/su.py +++ b/mitogen/su.py @@ -32,6 +32,11 @@ import mitogen.core import mitogen.parent from mitogen.core import b +try: + any +except NameError: + from mitogen.core import any + LOG = logging.getLogger(__name__) diff --git a/tests/su_test.py b/tests/su_test.py new file mode 100644 index 00000000..2af17c6e --- /dev/null +++ b/tests/su_test.py @@ -0,0 +1,32 @@ + +import os + +import mitogen +import mitogen.lxd +import mitogen.parent + +import unittest2 + +import testlib + + +class ConstructorTest(testlib.RouterMixin, testlib.TestCase): + su_path = testlib.data_path('stubs/stub-su.py') + + def run_su(self, **kwargs): + context = self.router.su( + su_path=self.su_path, + **kwargs + ) + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + return context, argv + + + def test_basic(self): + context, argv = self.run_su() + self.assertEquals(argv[1], 'root') + self.assertEquals(argv[2], '-c') + + +if __name__ == '__main__': + unittest2.main()