Fix up a few more ssh_tests, stop sending 400 modules over network.

Defining functions in the current module was causing the entirety of
py.test and all dependencies to be sucked in.
wip-fakessh-exit-status
David Wilson 7 years ago
parent f04a503caa
commit 498f961488

@ -6,5 +6,14 @@ fiddlery.
import math import math
def get_sentinel_value():
# Some proof we're even talking to the mitogen-test Docker image
return file('/etc/sentinel').read()
def add(x, y):
return x + y
def pow(x, y): def pow(x, y):
return x ** y return x ** y

@ -2,31 +2,23 @@
import unittest import unittest
import mitogen import mitogen
import mitogen.master
import mitogen.ssh import mitogen.ssh
import mitogen.utils import mitogen.utils
import testlib import testlib
import plain_old_module
def add(x, y): class FakeSshTest(testlib.RouterMixin, unittest.TestCase):
return x + y def test_okay(self):
context = self.router.ssh(
def get_sentinel_value():
# Some proof we're even talking to the mitogen-test Docker image
return file('/etc/sentinel').read()
class FakeSshTest(testlib.RouterMixin):
def test_okay(router, self):
def test(broker):
context = mitogen.ssh.connect(broker,
hostname='hostname', hostname='hostname',
ssh_path=testlib.data_path('fakessh.py')) username='has-sudo',
context.call(mitogen.utils.log_to_file, '/tmp/log') ssh_path=testlib.data_path('fakessh.py'),
context.call(mitogen.utils.disable_site_packages) )
self.assertEquals(3, context.call(add, 1, 2)) #context.call(mitogen.utils.log_to_file, '/tmp/log')
#context.call(mitogen.utils.disable_site_packages)
self.assertEquals(3, context.call(plain_old_module.add, 1, 2))
class SshTest(testlib.DockerMixin, unittest.TestCase): class SshTest(testlib.DockerMixin, unittest.TestCase):
@ -71,7 +63,7 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
) )
sentinel = 'i-am-mitogen-test-docker-image\n' sentinel = 'i-am-mitogen-test-docker-image\n'
assert sentinel == context.call(get_sentinel_value) assert sentinel == context.call(plain_old_module.get_sentinel_value)
def test_pubkey_required(self): def test_pubkey_required(self):
try: try:
@ -88,7 +80,6 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
assert e[0] == self.stream_class.password_required_msg assert e[0] == self.stream_class.password_required_msg
def test_pubkey_specified(self): def test_pubkey_specified(self):
try:
context = self.router.ssh( context = self.router.ssh(
hostname=self.dockerized_ssh.host, hostname=self.dockerized_ssh.host,
port=self.dockerized_ssh.port, port=self.dockerized_ssh.port,
@ -96,8 +87,6 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
username='has-sudo-pubkey', username='has-sudo-pubkey',
identity_file=testlib.data_path('docker/has-sudo-pubkey.key'), identity_file=testlib.data_path('docker/has-sudo-pubkey.key'),
) )
assert 0, 'exception not thrown'
except mitogen.ssh.PasswordError, e:
pass
assert e[0] == self.stream_class.password_required_msg sentinel = 'i-am-mitogen-test-docker-image\n'
assert sentinel == context.call(plain_old_module.get_sentinel_value)

Loading…
Cancel
Save