summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--logilab/common/shellutils.py12
-rw-r--r--test/unittest_shellutils.py7
2 files changed, 17 insertions, 2 deletions
diff --git a/logilab/common/shellutils.py b/logilab/common/shellutils.py
index 44f34ef..792ae45 100644
--- a/logilab/common/shellutils.py
+++ b/logilab/common/shellutils.py
@@ -35,6 +35,7 @@ import errno
import string
import random
import subprocess
+import warnings
from os.path import exists, isdir, islink, basename, join
from logilab.common import STD_BLACKLIST, _handle_blacklist
@@ -338,8 +339,15 @@ class progress(object):
class RawInput(object):
- def __init__(self, input=None, printer=None):
- self._input = input
+ def __init__(self, input_function=None, printer=None, **kwargs):
+ if 'input' in kwargs:
+ input_function = kwargs.pop('input')
+ warnings.warn(
+ "'input' argument is deprecated,"
+ "use 'input_function' instead",
+ DeprecationWarning,
+ )
+ self._input = input_function or input
self._print = printer
def ask(self, question, options, default):
diff --git a/test/unittest_shellutils.py b/test/unittest_shellutils.py
index 4ae76c7..49b06c7 100644
--- a/test/unittest_shellutils.py
+++ b/test/unittest_shellutils.py
@@ -20,6 +20,7 @@
import sys, os, tempfile, shutil
from os.path import join, dirname, abspath
import datetime, time
+from unittest.mock import patch
from logilab.common.testlib import TestCase, unittest_main
@@ -178,6 +179,12 @@ class RawInputTC(TestCase):
null_printer = lambda x: None
self.qa = RawInput(self.auto_input, null_printer)
+ def test_ask_using_builtin_input(self):
+ with patch('builtins.input', return_value='no'):
+ qa = RawInput()
+ answer = qa.ask('text', ('yes', 'no'), 'yes')
+ self.assertEqual(answer, 'no')
+
def test_ask_default(self):
self.input_answer = ''
answer = self.qa.ask('text', ('yes', 'no'), 'yes')