diff options
author | Simon Chabot <simon.chabot@logilab.fr> | 2019-11-28 18:57:56 +0100 |
---|---|---|
committer | Simon Chabot <simon.chabot@logilab.fr> | 2019-11-28 18:57:56 +0100 |
commit | e57d20105ecf9a17552eaddd74368a84ba839457 (patch) | |
tree | aaeda39b24e0aa49b40418a08b1780335a82baf4 /test | |
parent | 181715113d104f59d31d93fe0bd246fa815e6d4c (diff) | |
download | logilab-common-e57d20105ecf9a17552eaddd74368a84ba839457.tar.gz |
[shellutils, fix] Deprecate 'input' as argument of RawInput in favor of 'input_function'
When no parameter was given to the class, None was used as the `input`.
It used to work because when `input` (the argument) was None `raw_input` of six
was used instead. (-> self._input = input or raw_input).
Now that six has been dropped, we cannot have `input=None` in the arguments list
anymore and use the builtin `input` at the same time.
This patch suggests to deprecate this argument in favor of a new one called
`input_function`. If no `input_function`, let's use the `input` builtin.
For backward compatibility, if `input` should be given, it's caught in the
`kwargs` and used as `input_function`, and a deprecation warning is shown.
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_shellutils.py | 7 |
1 files changed, 7 insertions, 0 deletions
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') |