From 64f04877684e052a72bf2738137ba8e62137e78e Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 22 May 2015 15:30:22 -0700 Subject: [PATCH] Fixing coverage, fixing pep8 issues --- .coveragerc | 4 +++- README.md | 6 ++++++ bigquery/samples/utils.py | 5 +++-- bigquery/tests/test_async_query.py | 17 +++++++++-------- .../tests/test_structured_property_models.py | 2 +- discoverydoccaching/discovery_doc.py | 1 + tests/__init__.py | 3 ++- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.coveragerc b/.coveragerc index 8a533f7e4e55..debd4e071b6e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,8 +1,10 @@ [run] include = + appengine/* + bigquery/* datastore/* localtesting/* - bigquery/* + storage/* [report] exclude_lines = pragma: NO COVER diff --git a/README.md b/README.md index 266846a0d035..a5c2ad08e103 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ Google Cloud SDK installation path. $ export TEST_BUCKET_NAME={YOUR_BUCKET_NAME} $ tox +## Adding new tests + +Common testing utilities are located under ``tests``. + +When adding a new directory, be sure to edit ``.coveragerc`` to include it in coveralls. + ## Licensing * See [LICENSE](LICENSE) diff --git a/bigquery/samples/utils.py b/bigquery/samples/utils.py index a9d70e93a5b4..dd7a3900cbcd 100644 --- a/bigquery/samples/utils.py +++ b/bigquery/samples/utils.py @@ -19,8 +19,9 @@ def get_service(): from oauth2client.client import GoogleCredentials credentials = GoogleCredentials.get_application_default() if credentials.create_scoped_required(): - credentials = credentials.create_scoped('https://www.googleapis.com/auth/bigquery') - return build('bigquery','v2', credentials=GoogleCredentials.get_application_default()) + credentials = credentials.create_scoped( + 'https://www.googleapis.com/auth/bigquery') + return build('bigquery', 'v2', credentials=credentials) # [END get_service] diff --git a/bigquery/tests/test_async_query.py b/bigquery/tests/test_async_query.py index 52498d34544a..412f13af5d60 100644 --- a/bigquery/tests/test_async_query.py +++ b/bigquery/tests/test_async_query.py @@ -15,11 +15,12 @@ import os import unittest -from bigquery.samples.async_query import run, main -from tests import CloudBaseTest, mock_raw_input, BUCKET_NAME_ENV, \ - PROJECT_ID_ENV +from bigquery.samples.async_query import main, run -class TestAsyncQuery(CloudBaseTest): +import tests + + +class TestAsyncQuery(tests.CloudBaseTest): def test_async_query(self): for result in run(self.constants['projectId'], @@ -30,14 +31,14 @@ def test_async_query(self): self.assertIsNotNone(json.loads(result)) -class TestAsyncRunner(CloudBaseTest): +class TestAsyncRunner(tests.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) + test_bucket_name = os.environ.get(tests.BUCKET_NAME_ENV) + test_project_id = os.environ.get(tests.PROJECT_ID_ENV) answers = [test_bucket_name, test_project_id, 'n', '1', '1'] - with mock_raw_input(answers): + with tests.mock_raw_input(answers): main() diff --git a/datastore/ndb/modeling/tests/test_structured_property_models.py b/datastore/ndb/modeling/tests/test_structured_property_models.py index d894cb185d0d..92c6706cf4e5 100644 --- a/datastore/ndb/modeling/tests/test_structured_property_models.py +++ b/datastore/ndb/modeling/tests/test_structured_property_models.py @@ -16,7 +16,7 @@ from datastore.ndb.modeling import structured_property_models as models -from tests import DatastoreTestbedCase +from tests import DatastoreTestbedCase class ContactTestCase(DatastoreTestbedCase): diff --git a/discoverydoccaching/discovery_doc.py b/discoverydoccaching/discovery_doc.py index 2b3c1509e564..210848358e73 100644 --- a/discoverydoccaching/discovery_doc.py +++ b/discoverydoccaching/discovery_doc.py @@ -27,6 +27,7 @@ RESOURCE_PATH = '..' # look for discovery docs in the parent folder MAX_AGE = 86400 # update discovery docs older than a day + def build_and_update(api, version, scopes=None): from oauth2client.client import GoogleCredentials from googleapiclient.discovery import build_from_document diff --git a/tests/__init__.py b/tests/__init__.py index 6e173362057a..b706ae802f62 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,10 +15,10 @@ Common testing utilities between samples """ +import __builtin__ import json import os import unittest -import __builtin__ from google.appengine.datastore import datastore_stub_util from google.appengine.ext import testbed @@ -81,6 +81,7 @@ def setUp(self): def tearDown(self): os.environ['SERVER_SOFTWARE'] = self._server_software_org + class DatastoreTestbedCase(unittest.TestCase): """A base test case for common setup/teardown tasks for test.""" def setUp(self):