diff --git a/tests/call_function_test.py b/tests/call_function_test.py index dc9a2298..ce434b31 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -119,7 +119,7 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): lambda: recv.get().unpickle()) -class ChainTest(testlib.RouterMixin, testlib.TestCase): +class CallChainTest(testlib.RouterMixin, testlib.TestCase): # Verify mitogen_chain functionality. klass = mitogen.parent.CallChain diff --git a/tests/data/stubs/README.md b/tests/data/stubs/README.md new file mode 100644 index 00000000..3f9af3c8 --- /dev/null +++ b/tests/data/stubs/README.md @@ -0,0 +1,5 @@ + +# stubs/ + +Dummy implementations of various third party tools that just spawn local Python +interpreters. Used to roughly test the tools' associated Mitogen classes. diff --git a/tests/data/stubs/docker.py b/tests/data/stubs/docker.py new file mode 100755 index 00000000..341cc818 --- /dev/null +++ b/tests/data/stubs/docker.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import sys +import os + +os.environ['ORIGINAL_ARGV'] = repr(sys.argv) +os.execv(sys.executable, sys.argv[sys.argv.index('-c') - 1:]) diff --git a/tests/data/fake_lxc.py b/tests/data/stubs/lxc-attach.py similarity index 100% rename from tests/data/fake_lxc.py rename to tests/data/stubs/lxc-attach.py diff --git a/tests/data/fake_lxc_attach.py b/tests/data/stubs/lxc.py similarity index 100% rename from tests/data/fake_lxc_attach.py rename to tests/data/stubs/lxc.py diff --git a/tests/data/fakessh.py b/tests/data/stubs/ssh.py similarity index 100% rename from tests/data/fakessh.py rename to tests/data/stubs/ssh.py diff --git a/tests/docker_test.py b/tests/docker_test.py new file mode 100644 index 00000000..33ead10c --- /dev/null +++ b/tests/docker_test.py @@ -0,0 +1,28 @@ +import os + +import mitogen + +import unittest2 + +import testlib + + +class ConstructorTest(testlib.RouterMixin, unittest2.TestCase): + def test_okay(self): + docker_path = testlib.data_path('stubs/docker.py') + context = self.router.docker( + container='container_name', + docker_path=docker_path, + ) + stream = self.router.stream_by_id(context.context_id) + + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + self.assertEquals(argv[0], docker_path) + self.assertEquals(argv[1], 'exec') + self.assertEquals(argv[2], '--interactive') + self.assertEquals(argv[3], 'container_name') + self.assertEquals(argv[4], stream.python_path) + + +if __name__ == '__main__': + unittest2.main() diff --git a/tests/lxc_test.py b/tests/lxc_test.py index a30cd186..3168aad2 100644 --- a/tests/lxc_test.py +++ b/tests/lxc_test.py @@ -11,9 +11,9 @@ def has_subseq(seq, subseq): return any(seq[x:x+len(subseq)] == subseq for x in range(0, len(seq))) -class FakeLxcAttachTest(testlib.RouterMixin, unittest2.TestCase): +class ConstructorTest(testlib.RouterMixin, unittest2.TestCase): def test_okay(self): - lxc_attach_path = testlib.data_path('fake_lxc_attach.py') + lxc_attach_path = testlib.data_path('stubs/lxc-attach.py') context = self.router.lxc( container='container_name', lxc_attach_path=lxc_attach_path, diff --git a/tests/lxd_test.py b/tests/lxd_test.py index 9c2397a2..41e9df15 100644 --- a/tests/lxd_test.py +++ b/tests/lxd_test.py @@ -7,9 +7,9 @@ import unittest2 import testlib -class FakeLxcTest(testlib.RouterMixin, unittest2.TestCase): +class ConstructorTest(testlib.RouterMixin, unittest2.TestCase): def test_okay(self): - lxc_path = testlib.data_path('fake_lxc.py') + lxc_path = testlib.data_path('stubs/lxc.py') context = self.router.lxd( container='container_name', lxc_path=lxc_path, diff --git a/tests/ssh_test.py b/tests/ssh_test.py index efca057d..edfe45dc 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -11,12 +11,12 @@ import testlib import plain_old_module -class FakeSshTest(testlib.RouterMixin, unittest2.TestCase): +class ConstructorTest(testlib.RouterMixin, unittest2.TestCase): def test_okay(self): context = self.router.ssh( hostname='hostname', username='mitogen__has_sudo', - ssh_path=testlib.data_path('fakessh.py'), + ssh_path=testlib.data_path('stubs/ssh.py'), ) #context.call(mitogen.utils.log_to_file, '/tmp/log') #context.call(mitogen.utils.disable_site_packages)