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