From 5b1cd5e9808c8f02d41d3bc0b399e14594f5624c Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 17 Apr 2010 15:04:13 -0400 Subject: [PATCH] some tests for the various context failure issues --- client/test_client/test_context.py | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client/test_client/test_context.py diff --git a/client/test_client/test_context.py b/client/test_client/test_context.py new file mode 100644 index 0000000..f0a5387 --- /dev/null +++ b/client/test_client/test_context.py @@ -0,0 +1,50 @@ +from pony_client import Context, BaseCommand, do +import pony_client + +class StubCommand(BaseCommand): + command_name = 'test command' + def __init__(self): + BaseCommand.__init__(self, []) + + def run(self, context): + self.output = 'some output' + self.errout = 'some errout' + self.duration = 0. + +class SuccessfulCommand(StubCommand): + command_type = 'forced_success' + def run(self, context): + self.status = 0 + +class FailedCommand(StubCommand): + command_type = 'forced_failure' + def run(self, context): + self.status = -1 + +class ExceptedCommand(StubCommand): + command_type = 'forced_exception' + def run(self, context): + raise Exception("I suck") + +class FailedContextInit(Context): + def __init__(self, *args, **kwargs): + Context.__init__(self, *args, **kwargs) + pony_client.error_state = True + +def test_context_failure(): + c = FailedContextInit() + + (client_info, _, _) = do('foo', [ SuccessfulCommand() ], context=c) + assert not client_info['success'] + +def test_failed_command(): + c = Context() + + (client_info, _, _) = do('foo', [ FailedCommand() ], context=c) + assert not client_info['success'] + +def test_exception_command(): + c = Context() + + (client_info, _, _) = do('foo', [ ExceptedCommand() ], context=c) + assert not client_info['success']