Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Regression Test By Mocking Input #32

Merged
merged 6 commits into from
May 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 15 additions & 3 deletions bigquery/tests/test_async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# limitations under the License.
#
import json
import os
import unittest

from bigquery.samples.async_query import run
from tests import CloudBaseTest

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

class TestAsyncQuery(CloudBaseTest):

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


class TestAsyncRunner(CloudBaseTest):

def test_async_query_runner(self):
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(answers):
main()


if __name__ == '__main__':
unittest.main()
21 changes: 20 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@
import json
import os
import unittest

import __builtin__

BUCKET_NAME_ENV = 'TEST_BUCKET_NAME'
PROJECT_ID_ENV = 'TEST_PROJECT_ID'
RESOURCE_PATH = os.path.join(
os.path.abspath(os.path.dirname(__file__)), 'resources')


class mock_raw_input(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


class CloudBaseTest(unittest.TestCase):

def setUp(self):
Expand Down