FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adds Regression Test By Mocking Input by waprin · Pull Request #32 · GoogleCloudPlatform/python-docs-samples · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 15 additions & 3 deletions bigquery/tests/test_async_query.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL