File: compare_output_test.py

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (62 lines) | stat: -rwxr-xr-x 1,648 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python

import difflib
import logging
import re
import subprocess
import tempfile

LOG = logging.getLogger(__name__)

suffixes = [
    '-m custom_bash_old_style_module',
    '-m custom_bash_want_json_module',
    '-m custom_binary_producing_json',
    '-m custom_binary_producing_junk',
    '-m custom_binary_single_null',
    '-m custom_python_json_args_module',
    '-m custom_python_new_style_module',
    '-m custom_python_want_json_module',
    '-m setup',
]

fixups = [
    ('Shared connection to localhost closed\\.(\r\n)?', ''),  # TODO
]


def fixup(s):
    for regex, to in fixups:
        s = re.sub(regex, to, s, re.DOTALL|re.M)
    return s


def run(s):
    LOG.debug('running: %r', s)
    with tempfile.NamedTemporaryFile() as fp:
        # https://www.systutorials.com/docs/linux/man/1-ansible-playbook/#lbAG
        returncode = subprocess.call(s, stdout=fp, stderr=fp, shell=True)
        fp.write('\nReturn code: %s\n' % (returncode,))
        fp.seek(0)
        return fp.read()


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    for suffix in suffixes:
        ansible = run('ansible localhost %s' % (suffix,))
        mitogen = run('ANSIBLE_STRATEGY=mitogen ansible localhost %s' % (suffix,))

        diff = list(difflib.unified_diff(
            a=fixup(ansible).splitlines(),
            b=fixup(mitogen).splitlines(),
            fromfile='ansible-output.txt',
            tofile='mitogen-output.txt',
        ))
        if diff:
            print('++ differ! suffix: %r' % (suffix,))
            for line in diff:
                print(line)
            print
            print