Skip to content

Commit 8b24b0b

Browse files
author
Bill Prin
committed
Change it to list
1 parent 032a4c0 commit 8b24b0b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

bigquery/tests/test_async_query.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import unittest
1717

1818
from bigquery.samples.async_query import run, main
19-
from tests import CloudBaseTest, mock_raw_input, BUCKET_NAME_ENV, PROJECT_ID_ENV
19+
from tests import CloudBaseTest, mock_raw_input_list, BUCKET_NAME_ENV, \
20+
PROJECT_ID_ENV
2021

2122
class TestAsyncQuery(CloudBaseTest):
2223

@@ -29,22 +30,14 @@ def test_async_query(self):
2930
self.assertIsNotNone(json.loads(result))
3031

3132

32-
def mock_get_input(input):
33-
test_bucket_name = os.environ.get(BUCKET_NAME_ENV)
34-
test_project_id = os.environ.get(PROJECT_ID_ENV)
35-
answers = [test_bucket_name, test_project_id, 'n',
36-
'1', '1']
37-
ret = answers[TestAsyncRunner.i]
38-
TestAsyncRunner.i += 1
39-
return ret
40-
41-
4233
class TestAsyncRunner(CloudBaseTest):
4334

44-
i = 0
45-
4635
def test_async_query_runner(self):
47-
with mock_raw_input(mock_get_input):
36+
test_bucket_name = os.environ.get(BUCKET_NAME_ENV)
37+
test_project_id = os.environ.get(PROJECT_ID_ENV)
38+
answers = [test_bucket_name, test_project_id, 'n',
39+
'1', '1']
40+
with mock_raw_input_list(answers):
4841
main()
4942

5043

tests/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
os.path.abspath(os.path.dirname(__file__)), 'resources')
2828

2929

30+
class mock_raw_input_list(object):
31+
32+
def __init__(self, list_):
33+
self.i = 0
34+
self.list_ = list_
35+
36+
def get_next_value(self, question):
37+
ret = self.list_[self.i]
38+
self.i += 1
39+
return ret
40+
41+
def __enter__(self):
42+
self.raw_input_cache = __builtin__.raw_input
43+
__builtin__.raw_input = self.get_next_value
44+
45+
def __exit__(self, exc_type, exc_value, traceback):
46+
__builtin__.raw_input = self.raw_input_cache
47+
48+
3049
@contextmanager
3150
def mock_raw_input(mock):
3251
original_raw_input = __builtin__.raw_input

0 commit comments

Comments
 (0)