Skip to content

Commit

Permalink
Merge pull request #32 from GoogleCloudPlatform/regression
Browse files Browse the repository at this point in the history
Adds Regression Test By Mocking Input
  • Loading branch information
waprin committed May 22, 2015
2 parents 78079cd + 09961a7 commit a2cd34b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
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

0 comments on commit a2cd34b

Please sign in to comment.