From 113f92548af549cae71f9820539ab241cfdc2d80 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 11 Jul 2017 16:21:51 -0400 Subject: [PATCH] hacking/test-module: fix for python3 (#26194) * make hacking/test-module compatible with python3 --- hacking/test-module | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hacking/test-module b/hacking/test-module index bc184201837..89413c8b4b8 100755 --- a/hacking/test-module +++ b/hacking/test-module @@ -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)