Skip to content

Commit

Permalink
Made a test compatible with Python 2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jun 7, 2014
1 parent 11284a6 commit d98cc41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions django/utils/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,12 @@ def wrapper(cls):
### Additional customizations for Django ###

if PY3:
_assertCountEqual = "assertCountEqual"
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
memoryview = memoryview
else:
_assertCountEqual = "assertItemsEqual"
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
# memoryview and buffer are not strictly equivalent, but should be fine for
Expand All @@ -678,6 +680,10 @@ def wrapper(cls):
memoryview = buffer


def assertCountEqual(self, *args, **kwargs):
return getattr(self, _assertCountEqual)(*args, **kwargs)


def assertRaisesRegex(self, *args, **kwargs):
return getattr(self, _assertRaisesRegex)(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion tests/backends/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def test_queries(self):

self.assertIsInstance(connection.queries, list)
self.assertIsInstance(connection.queries[0], dict)
self.assertItemsEqual(connection.queries[0].keys(), ['sql', 'time'])
six.assertCountEqual(self, connection.queries[0].keys(), ['sql', 'time'])

reset_queries()
self.assertEqual(0, len(connection.queries))
Expand Down

0 comments on commit d98cc41

Please sign in to comment.