Skip to content

Commit

Permalink
- refactor assertEqualMultiline into common.py for reuse
Browse files Browse the repository at this point in the history
This will be reused by the tests for the imminent prdiff subcommand.
  • Loading branch information
aspiers committed Jan 18, 2013
1 parent 33f3ab4 commit 9b1c6f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 10 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@ def _check_digests(self, fname, *skipfiles):
continue
self.assertTrue(os.path.exists(os.path.join('.osc', i.get('name'))))
self.assertEqual(osc.core.dgst(os.path.join('.osc', i.get('name'))), i.get('md5'))

def assertEqualMultiline(self, got, exp):
if (got + exp).find('\n') == -1:
self.assertEqual(got, exp)
else:
start_delim = "\n" + (" 8< ".join(["-----"] * 8)) + "\n"
end_delim = "\n" + (" >8 ".join(["-----"] * 8)) + "\n\n"
self.assertEqual(got, exp,
"got:" + start_delim + got + end_delim +
"expected:" + start_delim + exp + end_delim)
10 changes: 1 addition & 9 deletions tests/test_difffiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,7 @@ def __canonise_diff(diff):

got = __canonise_diff(got)
exp = __canonise_diff(exp)

if (got + exp).find('\n') == -1:
self.assertEqual(got, exp)
else:
start_delim = "\n" + (" 8< ".join(["-----"] * 8)) + "\n"
end_delim = "\n" + (" >8 ".join(["-----"] * 8)) + "\n\n"
self.assertEqual(got, exp,
"got:" + start_delim + got + end_delim +
"expected:" + start_delim + exp + end_delim)
self.assertEqualMultiline(got, exp)

if __name__ == '__main__':
import unittest
Expand Down

0 comments on commit 9b1c6f0

Please sign in to comment.