From 4be0b48e911fa4b58837ffcf372ff47de9322b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22Piranna=22?= Date: Tue, 7 Aug 2012 14:29:41 +0200 Subject: Added assertMultiLineEqual function like the one on unittest2 Found at http://stackoverflow.com/a/3943697/586382 --- tests/issues/issue_73.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/issues/issue_73.py b/tests/issues/issue_73.py index 7257ad1..59098e1 100644 --- a/tests/issues/issue_73.py +++ b/tests/issues/issue_73.py @@ -3,6 +3,7 @@ Created on 07/08/2012 @author: piranna ''' +from difflib import ndiff from unittest import main, TestCase from sqlparse import format @@ -34,6 +35,24 @@ class Issue_73(TestCase): "OVERTIMESTATUSNO=NULL, JOBROLENO=NULL, EMPEQUITYESTABLISHMENTNO=NULL " "where JOBINFORMATIONNO=16256;") + def assertMultiLineEqual(self, first, second, msg=None): + """Assert that two multi-line strings are equal. + + If they aren't, show a nice diff. + + """ + self.assertTrue(isinstance(first, basestring), + 'First argument is not a string') + self.assertTrue(isinstance(second, basestring), + 'Second argument is not a string') + + if first != second: + message = ''.join(ndiff(first.splitlines(True), + second.splitlines(True))) + if msg: + message += " : " + msg + self.fail("Multi-line strings are unequal:\n" + message) + def test_format(self): result = format(self.original_raw, reindent=True) -- cgit v1.2.1