Skip to content

Instantly share code, notes, and snippets.

@harobed
Created June 23, 2013 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harobed/5845674 to your computer and use it in GitHub Desktop.
Save harobed/5845674 to your computer and use it in GitHub Desktop.
python assert equal with ellipsis
import unittest
import re
class BaseTest(unittest.TestCase):
def assertEqualEllipsis(self, first, second, ellipsis_marker='...', msg=None):
"""
Example :
>>> self.assertEqualEllipsis('foo123bar', 'foo...bar')
"""
if ellipsis_marker not in second:
return first == second
if (
re.match(
re.escape(second).replace(re.escape(ellipsis_marker), '(.*?)'),
first,
re.M | re.S
) is None
):
self.assertMultiLineEqual(
first,
second,
msg
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment