Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change it to list
  • Loading branch information
Bill Prin
Bill Prin committed May 22, 2015
commit 8b24b0b6479305c34e939385df5f0aad5767908c
21 changes: 7 additions & 14 deletions bigquery/tests/test_async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import unittest

from bigquery.samples.async_query import run, main
from tests import CloudBaseTest, mock_raw_input, BUCKET_NAME_ENV, PROJECT_ID_ENV
from tests import CloudBaseTest, mock_raw_input_list, BUCKET_NAME_ENV, \
PROJECT_ID_ENV

class TestAsyncQuery(CloudBaseTest):

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


def mock_get_input(input):
test_bucket_name = os.environ.get(BUCKET_NAME_ENV)
test_project_id = os.environ.get(PROJECT_ID_ENV)
answers = [test_bucket_name, test_project_id, 'n',
'1', '1']
ret = answers[TestAsyncRunner.i]
TestAsyncRunner.i += 1
return ret


class TestAsyncRunner(CloudBaseTest):

i = 0

def test_async_query_runner(self):
with mock_raw_input(mock_get_input):
test_bucket_name = os.environ.get(BUCKET_NAME_ENV)
test_project_id = os.environ.get(PROJECT_ID_ENV)
answers = [test_bucket_name, test_project_id, 'n',
'1', '1']
with mock_raw_input_list(answers):
main()


Expand Down
19 changes: 19 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@
os.path.abspath(os.path.dirname(__file__)), 'resources')


class mock_raw_input_list(object):

def __init__(self, list_):
self.i = 0
self.list_ = list_

def get_next_value(self, question):
ret = self.list_[self.i]
self.i += 1
return ret

def __enter__(self):
self.raw_input_cache = __builtin__.raw_input
__builtin__.raw_input = self.get_next_value

def __exit__(self, exc_type, exc_value, traceback):
__builtin__.raw_input = self.raw_input_cache


@contextmanager
def mock_raw_input(mock):
original_raw_input = __builtin__.raw_input
Expand Down