diff --git a/bigquery/test/__init__.py b/bigquery/test/__init__.py deleted file mode 100644 index 6a70f3c2fc4..00000000000 --- a/bigquery/test/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2015, Google, Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os - -RESOURCE_PATH = os.path.join(os.path.dirname(__file__), - '..', - '..', - 'resources') diff --git a/bigquery/test/base_test.py b/bigquery/test/base_test.py deleted file mode 100644 index 175546d9d4e..00000000000 --- a/bigquery/test/base_test.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2015, Google, Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import os -import unittest - -from bigquery.test import RESOURCE_PATH - - -BUCKET_NAME_ENV = 'TEST_BUCKET_NAME' -PROJECT_ID_ENV = 'TEST_PROJECT_ID' - - -class BaseBigqueryTest(unittest.TestCase): - - def setUp(self): - # A hack to prevent get_application_default from going GAE route. - self._server_software_org = os.environ.get('SERVER_SOFTWARE') - os.environ['SERVER_SOFTWARE'] = '' - test_bucket_name = os.environ.get(BUCKET_NAME_ENV, '') - test_project_id = os.environ.get(PROJECT_ID_ENV, '') - if not test_project_id or not test_bucket_name: - raise Exception('You need to define an env var "%s" and "%s" to ' - 'run the test.' - % (PROJECT_ID_ENV, BUCKET_NAME_ENV)) - with open( - os.path.join(RESOURCE_PATH, 'constants.json'), - 'r') as constants_file: - - self.constants = json.load(constants_file) - self.constants['projectId'] = test_project_id - self.constants['cloudStorageInputURI'] = ( - self.constants['cloudStorageInputURI'] % test_bucket_name) - self.constants['cloudStorageOutputURI'] = ( - self.constants['cloudStorageOutputURI'] % test_bucket_name) - - def tearDown(self): - os.environ['SERVER_SOFTWARE'] = self._server_software_org diff --git a/bigquery/tests/__init__.py b/bigquery/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bigquery/test/test_async_query.py b/bigquery/tests/test_async_query.py similarity index 91% rename from bigquery/test/test_async_query.py rename to bigquery/tests/test_async_query.py index 3435542be54..d41c724da0f 100644 --- a/bigquery/test/test_async_query.py +++ b/bigquery/tests/test_async_query.py @@ -15,10 +15,10 @@ import unittest from bigquery.samples.async_query import run -from bigquery.test.base_test import BaseBigqueryTest +from tests import CloudBaseTest -class TestAsyncQuery(BaseBigqueryTest): +class TestAsyncQuery(CloudBaseTest): def test_async_query(self): for result in run(self.constants['projectId'], diff --git a/bigquery/test/test_export_data_to_cloud_storage.py b/bigquery/tests/test_export_data_to_cloud_storage.py similarity index 90% rename from bigquery/test/test_export_data_to_cloud_storage.py rename to bigquery/tests/test_export_data_to_cloud_storage.py index 8b5c77f5a87..7024e29143c 100644 --- a/bigquery/test/test_export_data_to_cloud_storage.py +++ b/bigquery/tests/test_export_data_to_cloud_storage.py @@ -17,10 +17,10 @@ import unittest from bigquery.samples.export_data_to_cloud_storage import run -from bigquery.test.base_test import BaseBigqueryTest +from tests import CloudBaseTest -class TestExportTableToGCS(BaseBigqueryTest): +class TestExportTableToGCS(CloudBaseTest): def test_export_table(self): run(self.constants['cloudStorageInputURI'], diff --git a/bigquery/test/test_load_data_from_csv.py b/bigquery/tests/test_load_data_from_csv.py similarity index 85% rename from bigquery/test/test_load_data_from_csv.py rename to bigquery/tests/test_load_data_from_csv.py index db9a3fc4dc9..53c8039b02c 100644 --- a/bigquery/test/test_load_data_from_csv.py +++ b/bigquery/tests/test_load_data_from_csv.py @@ -18,16 +18,15 @@ import unittest from bigquery.samples.load_data_from_csv import run -from bigquery.test import RESOURCE_PATH -from bigquery.test.base_test import BaseBigqueryTest +from tests import CloudBaseTest -class TestLoadDataFromCSV(BaseBigqueryTest): +class TestLoadDataFromCSV(CloudBaseTest): def setUp(self): super(TestLoadDataFromCSV, self).setUp() with open( - os.path.join(RESOURCE_PATH, 'schema.json'), + os.path.join(self.resource_path, 'schema.json'), 'r') as schema_file: self.schema = json.load(schema_file) diff --git a/bigquery/test/test_streaming.py b/bigquery/tests/test_streaming.py similarity index 85% rename from bigquery/test/test_streaming.py rename to bigquery/tests/test_streaming.py index 05dbe4a5865..791475881ac 100644 --- a/bigquery/test/test_streaming.py +++ b/bigquery/tests/test_streaming.py @@ -17,16 +17,15 @@ import unittest from bigquery.samples.streaming import run -from bigquery.test import RESOURCE_PATH -from bigquery.test.base_test import BaseBigqueryTest +from tests import CloudBaseTest -class TestStreaming(BaseBigqueryTest): +class TestStreaming(CloudBaseTest): def test_stream_row_to_bigquery(self): with open( - os.path.join(RESOURCE_PATH, 'streamrows.json'), + os.path.join(self.resource_path, 'streamrows.json'), 'r') as rows_file: rows = json.load(rows_file) diff --git a/bigquery/test/test_sync_query.py b/bigquery/tests/test_sync_query.py similarity index 91% rename from bigquery/test/test_sync_query.py rename to bigquery/tests/test_sync_query.py index 74ab0cabd06..e9f0637ac6b 100644 --- a/bigquery/test/test_sync_query.py +++ b/bigquery/tests/test_sync_query.py @@ -15,10 +15,10 @@ import unittest from bigquery.samples.sync_query import run -from bigquery.test.base_test import BaseBigqueryTest +from tests import CloudBaseTest -class TestSyncQuery(BaseBigqueryTest): +class TestSyncQuery(CloudBaseTest): def test_sync_query(self): for result in run(self.constants['projectId'], diff --git a/storage/tests/test_list_objects.py b/storage/tests/test_list_objects.py index e00e9e500ba..32f7d09424a 100644 --- a/storage/tests/test_list_objects.py +++ b/storage/tests/test_list_objects.py @@ -21,4 +21,4 @@ def test_main(self): 'ignored_command_name', self.constants['bucketName'] ] - self.assertNotRaises(main(args)) + main(args) diff --git a/tests/__init__.py b/tests/__init__.py index 56ef4acb9c4..9f87cf1d518 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,12 +22,15 @@ BUCKET_NAME_ENV = 'TEST_BUCKET_NAME' PROJECT_ID_ENV = 'TEST_PROJECT_ID' -RESOURCE_PATH = os.path.join(os.getcwd(), 'resources') +RESOURCE_PATH = os.path.join( + os.path.abspath(os.path.dirname(__file__)), 'resources') class CloudBaseTest(unittest.TestCase): def setUp(self): + self.resource_path = RESOURCE_PATH + # A hack to prevent get_application_default from going GAE route. self._server_software_org = os.environ.get('SERVER_SOFTWARE') os.environ['SERVER_SOFTWARE'] = '' diff --git a/resources/constants.json b/tests/resources/constants.json similarity index 100% rename from resources/constants.json rename to tests/resources/constants.json diff --git a/resources/data.csv b/tests/resources/data.csv similarity index 100% rename from resources/data.csv rename to tests/resources/data.csv diff --git a/resources/schema.json b/tests/resources/schema.json similarity index 100% rename from resources/schema.json rename to tests/resources/schema.json diff --git a/resources/streamrows.json b/tests/resources/streamrows.json similarity index 100% rename from resources/streamrows.json rename to tests/resources/streamrows.json diff --git a/tox.ini b/tox.ini index 49c4765ffdf..93bfdeea573 100644 --- a/tox.ini +++ b/tox.ini @@ -22,5 +22,5 @@ commands = cover: --cover-tests --cover-branches --cover-min-percentage=70 \ cover: --cover-inclusive --cover-erase cover: coveralls - nosetest: nosetests --with-gae + nosetest: nosetests --with-gae {posargs} pep8: flake8 --max-complexity=10 --import-order-style=google