mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
Ensure that the src file contents is converted to unicode in diff info (#45744)
* Ensure that the src file contents is converted to unicode in diff info. Fixes #45717
* Fix up and cleanup
* The diff functionality in the callback plugins should have the
to_text() calls removed since we're now doing it in ActionBase
* catching of UnicodeError and warnings in the callback diff
functionality from 61d01f549f
haven't been
needed since we switched to to_text so remove them.
* Add a note to ActionBase's diff function giving an example of when the
diff function will be inaccurate and how to fix it
* Fix callback get_diff() tests
I believe the unittests of callback's get_diff() were wrong. They were
sending in a list where strings were expected. Because previous code
was transforming the lists into strings via their repr, the previous
tests did not fail but they would have formatted the test cases output
in an odd way if we had looked at it.
This commit is contained in:
parent
24dd87bd0a
commit
95e77ac853
4 changed files with 94 additions and 88 deletions
|
@ -175,9 +175,6 @@ class TestCallbackDumpResults(unittest.TestCase):
|
|||
self.assertTrue('LEFTIN' in json_out)
|
||||
|
||||
|
||||
# TODO: triggr the 'except UnicodeError' around _get_diff
|
||||
# that try except orig appeared in 61d01f549f2143fd9adfa4ffae42f09d24649c26
|
||||
# in 2013 so maybe a < py2.6 issue
|
||||
class TestCallbackDiff(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -188,28 +185,28 @@ class TestCallbackDiff(unittest.TestCase):
|
|||
|
||||
def test_difflist(self):
|
||||
# TODO: split into smaller tests?
|
||||
difflist = [{'before': ['preface\nThe Before String\npostscript'],
|
||||
'after': ['preface\nThe After String\npostscript'],
|
||||
'before_header': 'just before',
|
||||
'after_header': 'just after'
|
||||
difflist = [{'before': u'preface\nThe Before String\npostscript',
|
||||
'after': u'preface\nThe After String\npostscript',
|
||||
'before_header': u'just before',
|
||||
'after_header': u'just after'
|
||||
},
|
||||
{'before': ['preface\nThe Before String\npostscript'],
|
||||
'after': ['preface\nThe After String\npostscript'],
|
||||
{'before': u'preface\nThe Before String\npostscript',
|
||||
'after': u'preface\nThe After String\npostscript',
|
||||
},
|
||||
{'src_binary': 'chicane'},
|
||||
{'dst_binary': 'chicanery'},
|
||||
{'dst_larger': 1},
|
||||
{'src_larger': 2},
|
||||
{'prepared': 'what does prepared do?'},
|
||||
{'before_header': 'just before'},
|
||||
{'after_header': 'just after'}]
|
||||
{'prepared': u'what does prepared do?'},
|
||||
{'before_header': u'just before'},
|
||||
{'after_header': u'just after'}]
|
||||
|
||||
res = self.cb._get_diff(difflist)
|
||||
|
||||
self.assertIn('Before String', res)
|
||||
self.assertIn('After String', res)
|
||||
self.assertIn('just before', res)
|
||||
self.assertIn('just after', res)
|
||||
self.assertIn(u'Before String', res)
|
||||
self.assertIn(u'After String', res)
|
||||
self.assertIn(u'just before', res)
|
||||
self.assertIn(u'just after', res)
|
||||
|
||||
def test_simple_diff(self):
|
||||
self.assertMultiLineEqual(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue