Permalink
Browse files

some tests for the various context failure issues

  • Loading branch information...
1 parent b06aea9 commit 5b1cd5e9808c8f02d41d3bc0b399e14594f5624c @ctb committed Apr 17, 2010
Showing with 50 additions and 0 deletions.
  1. +50 −0 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']

0 comments on commit 5b1cd5e

Please sign in to comment.