Use six.moves.input rather than six.moves.builtin.input

six.moves.builtin.input is the builtin python input. This makes
the code fail in Python 2.7. six.moves.input links to raw_input
which is the correct behaviour in this case.

Fixes bug: 1555268

Change-Id: I87062c99dc17faedbd0705565cb7a46029b9fdf0
This commit is contained in:
Jonas Pfannschmidt
2016-03-09 17:59:01 +00:00
parent 541baee572
commit 9c06672ad4
2 changed files with 8 additions and 5 deletions

View File

@@ -21,8 +21,8 @@ import argparse
import json
import os
import re
from six.moves import builtins
from six.moves import configparser
from six.moves import input
import sys
import requests
@@ -200,7 +200,7 @@ class ElastichsearchEngine(object):
if assume_yes:
return True
while True:
selection = builtins.input(message)
selection = input(message)
if selection.upper() == 'Y':
return True
elif selection.upper() == 'N':

View File

@@ -16,7 +16,6 @@ limitations under the License.
"""
import os
from six.moves import builtins
import unittest
import json
from mock import Mock, patch
@@ -182,13 +181,17 @@ class TestElasticsearchEngine(unittest.TestCase):
self.assertRaises(Exception, self.es_manager.put_mapping, 'jobs', self.test_mappings['jobs'])
def test_proceed_returns_true_on_user_y(self):
with patch('six.moves.builtins.input', return_value='y') as _raw_input:
# This really mocks 'six.moves.input'. Because of the way mock and six
# replace function, we need to mock it at the source.
with patch('freezer_api.cmd.db_init.input', return_value='y') as _raw_input:
res = self.es_manager.proceed('fancy a drink ?')
self.assertTrue(res)
_raw_input.assert_called_once_with('fancy a drink ?')
def test_proceed_returns_false_on_user_n(self):
with patch('six.moves.builtins.input', return_value='n') as _raw_input:
# This really mocks 'six.moves.input'. Because of the way mock and six
# replace function, we need to mock it at the source.
with patch('freezer_api.cmd.db_init.input', return_value='n') as _raw_input:
res = self.es_manager.proceed('are you drunk ?')
self.assertFalse(res)
_raw_input.assert_called_once_with('are you drunk ?')