URL: https://github.com/freeipa/freeipa/pull/129 Author: stlaz Title: #129: Fix test_util.test_assert_deepequal test Action: opened
PR body: """ The test would be failing because recent pretty-print changes that caused the inner members of a dictionary to be printed in a different order. https://fedorahosted.org/freeipa/ticket/6373 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/129/head:pr129 git checkout pr129
From 81f1c897881f43ccceafd228801bcf88fc0fc2dd Mon Sep 17 00:00:00 2001 From: Stanislav Laznicka <slazn...@redhat.com> Date: Mon, 3 Oct 2016 09:04:24 +0200 Subject: [PATCH] Fix test_util.test_assert_deepequal test The test would be failing because recent pretty-print changes that caused the inner members of a dictionary to be printed in a different order. https://fedorahosted.org/freeipa/ticket/6373 --- ipatests/test_util.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ipatests/test_util.py b/ipatests/test_util.py index 85b2843..bed5a19 100644 --- a/ipatests/test_util.py +++ b/ipatests/test_util.py @@ -141,6 +141,15 @@ def test_eq(self): def test_assert_deepequal(): f = util.assert_deepequal + # LEN and KEYS formats special function to pretty print structures + # depending on a pytest environment settings + if pytest.config.getoption("pretty_print"): + got_str = lambda s: util.struct_to_string(s, util.GOT_LEN) + exp_str = lambda s: util.struct_to_string(s, util.EXPECTED_LEN) + else: + got_str = lambda s: str(s) + exp_str = lambda s: str(s) + # Test with good scalar values: f(u'hello', u'hello') f(util.Fuzzy(), u'hello') @@ -221,7 +230,7 @@ def test_assert_deepequal(): ] e = raises(AssertionError, f, a, b, 'foo') assert str(e) == LEN % ( - 'foo', 3, 4, a, b, tuple() + 'foo', 3, 4, exp_str(a), got_str(b), tuple() ) b = [ @@ -230,7 +239,7 @@ def test_assert_deepequal(): ] e = raises(AssertionError, f, a, b, 'foo') assert str(e) == LEN % ( - 'foo', 3, 2, a, b, tuple() + 'foo', 3, 2, exp_str(a), got_str(b), tuple() ) # Dict keys mismatch: @@ -244,7 +253,7 @@ def test_assert_deepequal(): e = raises(AssertionError, f, a, b, 'foo') assert str(e) == KEYS % ('foo', ['naughty'], [], - dict(naughty=u'nurse'), dict(), + exp_str(dict(naughty=u'nurse')), got_str(dict()), (1,) ) @@ -257,7 +266,8 @@ def test_assert_deepequal(): e = raises(AssertionError, f, a, b, 'foo') assert str(e) == KEYS % ('foo', [], ['barely'], - dict(naughty=u'nurse'), dict(naughty=u'nurse', barely=u'legal'), + exp_str(dict(naughty=u'nurse')), + got_str(dict(naughty=u'nurse', barely=u'legal')), (1,) ) @@ -270,7 +280,7 @@ def test_assert_deepequal(): e = raises(AssertionError, f, a, b, 'foo') assert str(e) == KEYS % ('foo', ['naughty'], ['barely'], - dict(naughty=u'nurse'), dict(barely=u'legal'), + exp_str(dict(naughty=u'nurse')), got_str(dict(barely=u'legal')), (1,) )
-- 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