From c0ff6bb37560742b12278cc84d887dabf1c8fed6 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 21 Dec 2017 11:46:41 -0500 Subject: [PATCH] Python 3 port: use input() instead of raw_input() On Python 2, input() has a different behavior, including an evaluation of the obtained string. On Python 3, it just returns the stripped string. Let's hand off the difference handling to six. PS: we won't use use six.moves.input() on the failtest_ugly.py file, given that it's intended to be a bad example. Signed-off-by: Cleber Rosa --- avocado/utils/genio.py | 4 +++- examples/tests/failtest_ugly.py | 2 +- scripts/avocado-run-testplan | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/avocado/utils/genio.py b/avocado/utils/genio.py index 557e972f..298fe461 100644 --- a/avocado/utils/genio.py +++ b/avocado/utils/genio.py @@ -20,6 +20,8 @@ import logging import os import time +from six.moves import input + from . import path as utils_path log = logging.getLogger('avocado.test') @@ -99,7 +101,7 @@ def ask(question, auto=False): if auto: log.info("%s (y/n) y" % question) return "y" - return raw_input("%s (y/n) " % question) + return input("%s (y/n) " % question) def read_file(filename): diff --git a/examples/tests/failtest_ugly.py b/examples/tests/failtest_ugly.py index 048a735d..4cfb6026 100644 --- a/examples/tests/failtest_ugly.py +++ b/examples/tests/failtest_ugly.py @@ -6,7 +6,7 @@ import sys sys.stdout.write("Direct output to stdout\n") sys.stderr.write("Direct output to stderr\n") -raw_input("I really want some input on each import") +input("I really want some input on each import") sys.stdin = 'This is my __COOL__ stdin' sys.stdout = 'my stdout' sys.stderr = 'my stderr' diff --git a/scripts/avocado-run-testplan b/scripts/avocado-run-testplan index 301c7e4c..f252f9b1 100755 --- a/scripts/avocado-run-testplan +++ b/scripts/avocado-run-testplan @@ -23,6 +23,8 @@ import sys import argparse +from six.moves import input + class Parser(argparse.ArgumentParser): @@ -89,9 +91,9 @@ class App(object): result = None while True: - result = raw_input("Result ([P]ass, [F]ail, [S]kip): ") + result = input("Result ([P]ass, [F]ail, [S]kip): ") if result in RESULT_MAP.keys(): - notes = raw_input("Additional Notes: ") + notes = input("Additional Notes: ") break print("") @@ -99,7 +101,7 @@ class App(object): "result": RESULT_MAP.get(result), "notes": notes.strip()}) - user = raw_input("Your identification [%s]: " % getpass.getuser()) + user = input("Your identification [%s]: " % getpass.getuser()) if not user: user = getpass.getuser() self.user_identification = user -- GitLab