Skip to content

Commit bc3039a

Browse files
author
Dean Troyer
committed
Fix py26 tests: assertDictEqual
assertDictEqual is not present in py26 so shim it in here stolen from python-keystoneclient/tests/test_auth_token_middleware.py Change-Id: Ifd5990a8c03d11ee93cddc2f61653255970d974c
1 parent 7183a11 commit bc3039a

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎tests/utils.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
import os
1717

1818
import fixtures
19+
import sys
1920
import testtools
2021

2122

2223
class TestCase(testtools.TestCase):
2324
def setUp(self):
24-
super(TestCase, self).setUp()
25+
testtools.TestCase.setUp(self)
2526

2627
if (os.environ.get("OS_STDOUT_NOCAPTURE") == "True" and
2728
os.environ.get("OS_STDOUT_NOCAPTURE") == "1"):
@@ -32,3 +33,27 @@ def setUp(self):
3233
os.environ.get("OS_STDERR_NOCAPTURE") == "1"):
3334
stderr = self.useFixture(fixtures.StringStream("stderr")).stream
3435
self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr))
36+
37+
# 2.6 doesn't have the assert dict equals so make sure that it exists
38+
if tuple(sys.version_info)[0:2] < (2, 7):
39+
40+
def assertIsInstance(self, obj, cls, msg=None):
41+
"""Same as self.assertTrue(isinstance(obj, cls)), with a nicer
42+
default message
43+
"""
44+
if not isinstance(obj, cls):
45+
standardMsg = '%s is not an instance of %r' % (obj, cls)
46+
self.fail(self._formatMessage(msg, standardMsg))
47+
48+
def assertDictEqual(self, d1, d2, msg=None):
49+
# Simple version taken from 2.7
50+
self.assertIsInstance(d1, dict,
51+
'First argument is not a dictionary')
52+
self.assertIsInstance(d2, dict,
53+
'Second argument is not a dictionary')
54+
if d1 != d2:
55+
if msg:
56+
self.fail(msg)
57+
else:
58+
standardMsg = '%r != %r' % (d1, d2)
59+
self.fail(standardMsg)

0 commit comments

Comments
 (0)