URL: https://github.com/freeipa/freeipa/pull/133 Author: pspacek Title: #133: Tests: print what was expected from exceptions and callables in xmlrpc_tests Action: opened
PR body: """ """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/133/head:pr133 git checkout pr133
From c00dd3e2ff614e9548de116d76b606fd828b8c4b Mon Sep 17 00:00:00 2001 From: root <r...@vm-058-218.abc.idm.lab.eng.brq.redhat.com> Date: Fri, 30 Sep 2016 09:48:14 +0200 Subject: [PATCH] Tests: print what was expected from callables in xmlrpc_tests --- ipatests/test_xmlrpc/xmlrpc_test.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py index 78d9638..0ce1245 100644 --- a/ipatests/test_xmlrpc/xmlrpc_test.py +++ b/ipatests/test_xmlrpc/xmlrpc_test.py @@ -23,6 +23,7 @@ from __future__ import print_function import datetime +import inspect import nose import contextlib @@ -237,7 +238,8 @@ def failsafe_del(cls, obj, pk): UNEXPECTED = """Expected %r to raise %s, but caught different. args = %r options = %r - %s: %s""" + expected = %s: %s + got = %s: %s""" KWARGS = """Command %r raised %s with wrong kwargs. @@ -329,19 +331,20 @@ def check(self, nice, desc, command, expected, extra_check=None): def check_exception(self, nice, cmd, args, options, expected): klass = expected.__class__ - name = klass.__name__ + expected_name = klass.__name__ try: output = api.Command[cmd](*args, **options) except Exception as e: - exception = e + got = e else: raise AssertionError( - EXPECTED % (cmd, name, args, options, output) + EXPECTED % (cmd, expected_name, args, options, output) ) - if not isinstance(exception, klass): + if not isinstance(got, klass): raise AssertionError( - UNEXPECTED % (cmd, name, args, options, - exception.__class__.__name__, exception) + UNEXPECTED % (cmd, expected_name, args, options, + expected_name, expected, + got.__class__.__name__, got) ) # FIXME: the XML-RPC transport doesn't allow us to return structured # information through the exception, so we can't test the kw on the @@ -349,21 +352,26 @@ def check_exception(self, nice, cmd, args, options, expected): # transport, the exception is a free-form data structure (dict). # For now just compare the strings # pylint: disable=no-member - assert_deepequal(expected.strerror, exception.strerror) + assert_deepequal(expected.strerror, got.strerror) # pylint: enable=no-member def check_callable(self, nice, cmd, args, options, expected): - name = expected.__class__.__name__ + expected_name = expected.__class__.__name__ + try: + expected_text = inspect.getsource(expected).strip() + except TypeError: + expected_text = str(expected) output = dict() - exception = None + got = None try: output = api.Command[cmd](*args, **options) except Exception as e: - exception = e - if not expected(exception, output): + got = e + if not expected(got, output): raise AssertionError( - UNEXPECTED % (cmd, name, args, options, - type(exception).__name__, exception) + UNEXPECTED % (cmd, expected_name, args, options, + expected_name, expected_text, + got.__class__.__name__, got) ) def check_output(self, nice, cmd, args, options, expected, extra_check):
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code