Created
June 23, 2013 16:50
-
-
Save harobed/5845674 to your computer and use it in GitHub Desktop.
python assert equal with ellipsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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