1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

hacking/test-module: fix for python3 (#26194)

* make hacking/test-module compatible with python3
This commit is contained in:
Sloane Hertel 2017-07-11 16:21:51 -04:00 committed by Toshio Kuratomi
parent 292f109ad6
commit 113f92548a

View file

@ -42,6 +42,7 @@ from ansible.parsing.utils.jsonify import jsonify
from ansible.parsing.splitter import parse_kv
import ansible.executor.module_common as module_common
import ansible.constants as C
from ansible.module_utils._text import to_text
try:
import json
@ -159,7 +160,7 @@ def boilerplate_module(modfile, args, interpreters, check, destfile):
print("* including generated source, if any, saving to: %s" % modfile2_path)
if module_style not in ('ansiballz', 'old'):
print("* this may offset any line numbers in tracebacks/debuggers!")
modfile2 = open(modfile2_path, 'w')
modfile2 = open(modfile2_path, 'wb')
modfile2.write(module_data)
modfile2.close()
modfile = modfile2_path
@ -178,6 +179,7 @@ def ansiballz_setup(modfile, modname, interpreters):
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
out, err = to_text(out, errors='surrogate_or_strict'), to_text(err)
lines = out.splitlines()
if len(lines) != 2 or 'Module expanded into' not in lines[0]:
print("*" * 35)
@ -209,6 +211,7 @@ def runtest(modfile, argspath, modname, module_style, interpreters):
cmd = subprocess.Popen(invoke, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate()
out, err = to_text(out), to_text(err)
try:
print("*" * 35)