Skip to content

Commit 8a580c5

Browse files
committed
use difflib
1 parent c84f16c commit 8a580c5

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

tests/integration/targets/callback/filter_plugins/helper.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from __future__ import (absolute_import, division, print_function)
66
__metaclass__ = type
77

8+
import difflib
9+
810
from ansible.module_utils.six import string_types
911

1012

@@ -14,33 +16,16 @@ def callback_results_extractor(outputs_results):
1416
differences = []
1517
expected_output = result['test']['expected_output']
1618
stdout_lines = result['stdout_lines']
17-
for i in range(max(len(expected_output), len(stdout_lines))):
18-
line = "line_%s" % (i + 1)
19-
test_line = stdout_lines[i] if i < len(stdout_lines) else None
20-
expected_lines = expected_output[i] if i < len(expected_output) else None
21-
if not isinstance(expected_lines, string_types) and expected_lines is not None:
22-
if test_line not in expected_lines:
23-
differences.append({
24-
'line': {
25-
'expected_one_of': expected_lines,
26-
'got': test_line,
27-
}
28-
})
29-
else:
30-
if test_line != expected_lines:
31-
differences.append({
32-
'line': {
33-
'expected': expected_lines,
34-
'got': test_line,
35-
}
36-
})
3719
results.append({
3820
'name': result['test']['name'],
39-
'output': {
40-
'differences': differences,
41-
'expected': expected_output,
42-
'got': stdout_lines,
43-
},
21+
'diff': list(
22+
difflib.unified_diff(
23+
expected_output,
24+
stdout_lines,
25+
fromfile="expected",
26+
tofile="found",
27+
)
28+
)
4429
})
4530
return results
4631

tests/integration/targets/callback/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
- name: Assert test output equals expected output
5151
assert:
52-
that: result.output.differences | length == 0
52+
that: result.diff | length == 0
5353
loop: "{{ outputs.results | callback_results_extractor }}"
5454
loop_control:
5555
loop_var: result

0 commit comments

Comments
 (0)