You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.0 KiB
Python
128 lines
3.0 KiB
Python
11 years ago
|
#!/usr/bin/env python2.5
|
||
|
|
||
|
"""
|
||
|
def DoStuff():
|
||
11 years ago
|
import time
|
||
|
file('/tmp/foobar', 'w').write(time.ctime())
|
||
11 years ago
|
|
||
|
|
||
|
localhost = pyrpc.SSHConnection('localhost')
|
||
|
localhost.Connect()
|
||
|
try:
|
||
11 years ago
|
ret = localhost.Evaluate(DoStuff)
|
||
11 years ago
|
except OSError, e:
|
||
11 years ago
|
|
||
11 years ago
|
|
||
|
|
||
|
Tests
|
||
11 years ago
|
- Test Channel objects to destruction.
|
||
|
- External contexts sometimes don't appear to die during a crash. This needs
|
||
|
tested to destruction.
|
||
|
- Test reconnecting to previously idle-killed contexts.
|
||
|
- Test remote context longevity to destruction. They should never stay
|
||
|
around after parent dies or disconnects.
|
||
11 years ago
|
|
||
11 years ago
|
"""
|
||
|
|
||
|
import sys
|
||
|
import unittest
|
||
|
import econtext
|
||
|
|
||
|
|
||
|
|
||
|
#
|
||
|
# Helper functions.
|
||
|
#
|
||
|
|
||
|
class GetModuleImportsTestCase(unittest.TestCase):
|
||
11 years ago
|
# This must be kept in sync with our actual imports.
|
||
|
IMPORTS = [
|
||
|
('econtext', 'econtext'),
|
||
|
('sys', 'PythonSystemModule'),
|
||
|
('sys', 'sys'),
|
||
|
('unittest', 'unittest')
|
||
|
]
|
||
11 years ago
|
|
||
11 years ago
|
def setUp(self):
|
||
|
global PythonSystemModule
|
||
|
import sys as PythonSystemModule
|
||
11 years ago
|
|
||
11 years ago
|
def tearDown(Self):
|
||
|
global PythonSystemModule
|
||
|
del PythonSystemModule
|
||
11 years ago
|
|
||
11 years ago
|
def testImports(self):
|
||
|
self.assertEqual(set(self.IMPORTS),
|
||
|
set(econtext.GetModuleImports(sys.modules[__name__])))
|
||
11 years ago
|
|
||
|
|
||
|
class BuildPartialModuleTestCase(unittest.TestCase):
|
||
11 years ago
|
def testNullModule(self):
|
||
|
"""Pass empty sequences; result should contain nothing but a hash bang line
|
||
|
and whitespace."""
|
||
11 years ago
|
|
||
11 years ago
|
lines = econtext.BuildPartialModule([], []).strip().split('\n')
|
||
11 years ago
|
|
||
11 years ago
|
self.assert_(lines[0].startswith('#!'))
|
||
|
self.assert_('import' not in lines[1:])
|
||
11 years ago
|
|
||
11 years ago
|
def testPassingMethodTypeFails(self):
|
||
|
"""Pass an instance method and ensure we refuse it."""
|
||
11 years ago
|
|
||
11 years ago
|
self.assertRaises(TypeError, econtext.BuildPartialModule,
|
||
|
[self.testPassingMethodTypeFails], [])
|
||
11 years ago
|
|
||
11 years ago
|
@staticmethod
|
||
|
def exampleStaticMethod():
|
||
|
pass
|
||
11 years ago
|
|
||
11 years ago
|
def testStaticMethodGetsUnwrapped(self):
|
||
|
"Ensure that @staticmethod decorators are stripped."
|
||
11 years ago
|
|
||
11 years ago
|
dct = {}
|
||
|
exec econtext.BuildPartialModule([self.exampleStaticMethod], []) in dct
|
||
|
self.assertFalse(isinstance(dct['exampleStaticMethod'], staticmethod))
|
||
11 years ago
|
|
||
|
|
||
|
|
||
|
#
|
||
|
# Streams
|
||
|
#
|
||
|
|
||
|
class StreamTestBase:
|
||
11 years ago
|
"""This defines rules that should remain true for all Stream subclasses. We
|
||
|
test in this manner to guard against a subclass breaking Stream's
|
||
|
polymorphism (e.g. overriding a method with the wrong prototype).
|
||
11 years ago
|
|
||
11 years ago
|
def testCommandLine(self):
|
||
|
print self.driver.command_line
|
||
|
"""
|
||
11 years ago
|
|
||
|
|
||
|
class SSHStreamTestCase(unittest.TestCase, StreamTestBase):
|
||
11 years ago
|
DRIVER_CLASS = econtext.SSHStream
|
||
11 years ago
|
|
||
11 years ago
|
def setUp(self):
|
||
|
# Stubs.
|
||
11 years ago
|
|
||
11 years ago
|
# Instance initialization.
|
||
|
self.stream = econtext.SSHStream('localhost', 'test-agent')
|
||
11 years ago
|
|
||
11 years ago
|
def tearDown(self):
|
||
|
pass
|
||
11 years ago
|
|
||
11 years ago
|
def testConstructor(self):
|
||
|
pass
|
||
11 years ago
|
|
||
|
|
||
|
class TCPStreamTestCase(unittest.TestCase, StreamTestBase):
|
||
11 years ago
|
pass
|
||
11 years ago
|
|
||
|
|
||
|
#
|
||
|
# Run the tests.
|
||
|
#
|
||
|
|
||
|
if __name__ == '__main__':
|
||
11 years ago
|
unittest.main()
|