diff --git a/bigquery/google/cloud/bigquery/dbapi/__init__.py b/bigquery/google/cloud/bigquery/dbapi/__init__.py index 0f6b4cf9e9dc9..cbc90ea7be5f1 100644 --- a/bigquery/google/cloud/bigquery/dbapi/__init__.py +++ b/bigquery/google/cloud/bigquery/dbapi/__init__.py @@ -26,31 +26,31 @@ or deprecation policy. """ -from google.cloud.bigquery.dbapi.connection import connect # noqa -from google.cloud.bigquery.dbapi.connection import Connection # noqa -from google.cloud.bigquery.dbapi.cursor import Cursor # noqa -from google.cloud.bigquery.dbapi.exceptions import Warning # noqa -from google.cloud.bigquery.dbapi.exceptions import Error # noqa -from google.cloud.bigquery.dbapi.exceptions import InterfaceError # noqa -from google.cloud.bigquery.dbapi.exceptions import DatabaseError # noqa -from google.cloud.bigquery.dbapi.exceptions import DataError # noqa -from google.cloud.bigquery.dbapi.exceptions import OperationalError # noqa -from google.cloud.bigquery.dbapi.exceptions import IntegrityError # noqa -from google.cloud.bigquery.dbapi.exceptions import InternalError # noqa -from google.cloud.bigquery.dbapi.exceptions import ProgrammingError # noqa -from google.cloud.bigquery.dbapi.exceptions import NotSupportedError # noqa -from google.cloud.bigquery.dbapi.types import Binary # noqa -from google.cloud.bigquery.dbapi.types import Date # noqa -from google.cloud.bigquery.dbapi.types import DateFromTicks # noqa -from google.cloud.bigquery.dbapi.types import Time # noqa -from google.cloud.bigquery.dbapi.types import TimeFromTicks # noqa -from google.cloud.bigquery.dbapi.types import Timestamp # noqa -from google.cloud.bigquery.dbapi.types import TimestampFromTicks # noqa -from google.cloud.bigquery.dbapi.types import BINARY # noqa -from google.cloud.bigquery.dbapi.types import DATETIME # noqa -from google.cloud.bigquery.dbapi.types import NUMBER # noqa -from google.cloud.bigquery.dbapi.types import ROWID # noqa -from google.cloud.bigquery.dbapi.types import STRING # noqa +from google.cloud.bigquery.dbapi.connection import connect +from google.cloud.bigquery.dbapi.connection import Connection +from google.cloud.bigquery.dbapi.cursor import Cursor +from google.cloud.bigquery.dbapi.exceptions import Warning +from google.cloud.bigquery.dbapi.exceptions import Error +from google.cloud.bigquery.dbapi.exceptions import InterfaceError +from google.cloud.bigquery.dbapi.exceptions import DatabaseError +from google.cloud.bigquery.dbapi.exceptions import DataError +from google.cloud.bigquery.dbapi.exceptions import OperationalError +from google.cloud.bigquery.dbapi.exceptions import IntegrityError +from google.cloud.bigquery.dbapi.exceptions import InternalError +from google.cloud.bigquery.dbapi.exceptions import ProgrammingError +from google.cloud.bigquery.dbapi.exceptions import NotSupportedError +from google.cloud.bigquery.dbapi.types import Binary +from google.cloud.bigquery.dbapi.types import Date +from google.cloud.bigquery.dbapi.types import DateFromTicks +from google.cloud.bigquery.dbapi.types import Time +from google.cloud.bigquery.dbapi.types import TimeFromTicks +from google.cloud.bigquery.dbapi.types import Timestamp +from google.cloud.bigquery.dbapi.types import TimestampFromTicks +from google.cloud.bigquery.dbapi.types import BINARY +from google.cloud.bigquery.dbapi.types import DATETIME +from google.cloud.bigquery.dbapi.types import NUMBER +from google.cloud.bigquery.dbapi.types import ROWID +from google.cloud.bigquery.dbapi.types import STRING apilevel = "2.0" @@ -59,3 +59,12 @@ threadsafety = 1 paramstyle = "pyformat" + +__all__ = [ + 'apilevel', 'threadsafety', 'paramstyle', 'connect', 'Connection', + 'Cursor', 'Warning', 'Error', 'InterfaceError', 'DatabaseError', + 'DataError', 'OperationalError', 'IntegrityError', 'InternalError', + 'ProgrammingError', 'NotSupportedError', 'Binary', 'Date', 'DateFromTicks', + 'Time', 'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'BINARY', + 'DATETIME', 'NUMBER', 'ROWID', 'STRING', +] diff --git a/bigquery/google/cloud/bigquery/dbapi/_helpers.py b/bigquery/google/cloud/bigquery/dbapi/_helpers.py index 8bd2c02438046..86946d83512ac 100644 --- a/bigquery/google/cloud/bigquery/dbapi/_helpers.py +++ b/bigquery/google/cloud/bigquery/dbapi/_helpers.py @@ -34,17 +34,15 @@ def wait_for_job(job): job.reload() if job.state == 'DONE': if job.error_result: - # TODO: raise a more specific exception, based on the error. - # See: https://cloud.google.com/bigquery/troubleshooting-errors raise exceptions.DatabaseError(job.errors) return time.sleep(1) -def scalar_to_query_parameter(name=None, value=None): +def scalar_to_query_parameter(value, name=None): """Convert a scalar value into a query parameter. - Note: the bytes type cannot be distinguished from a string in Python 2. + Note: You must use the unicode type for string parameters in Python 2. Raises a :class:`~ google.cloud.bigquery.dbapi.exceptions.ProgrammingError` if the type cannot be determined. @@ -52,12 +50,12 @@ def scalar_to_query_parameter(name=None, value=None): For more information about BigQuery data types, see: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types - :type: str - :param name: Optional name of the query parameter. - :type: any :param value: A scalar value to convert into a query parameter. + :type: str + :param name: Optional name of the query parameter. + :rtype: :class:`~google.cloud.bigquery.ScalarQueryParameter` """ parameter_type = None @@ -68,9 +66,9 @@ def scalar_to_query_parameter(name=None, value=None): parameter_type = 'INT64' elif isinstance(value, numbers.Real): parameter_type = 'FLOAT64' - elif isinstance(value, six.string_types): + elif isinstance(value, six.text_type): parameter_type = 'STRING' - elif isinstance(value, bytes): + elif isinstance(value, six.binary_type): parameter_type = 'BYTES' elif isinstance(value, datetime.datetime): parameter_type = 'TIMESTAMP' if value.tzinfo else 'DATETIME' @@ -88,43 +86,38 @@ def scalar_to_query_parameter(name=None, value=None): def to_query_parameters_list(parameters): """Converts a list of parameter values into query parameters. - :type: list - :param parameters: List of query parameter values. + :type: Sequence[Any] + :param parameters: Sequence of query parameter values. :rtype: list of :class:`~google.cloud.bigquery._helpers.AbstractQueryParameter` """ - query_parameters = [] - - for value in parameters: - query_parameters.append(scalar_to_query_parameter(value=value)) - - return query_parameters + return [scalar_to_query_parameter(value) for value in parameters] def to_query_parameters_dict(parameters): """Converts a dictionary of parameter values into query parameters. - :type: dict + :type: Mapping[str, Any] :param parameters: Dictionary of query parameter values. :rtype: list of :class:`~google.cloud.bigquery._helpers.AbstractQueryParameter` """ - query_parameters = [] - - for name in parameters: - value = parameters[name] - query_parameters.append(scalar_to_query_parameter(name, value)) - - return query_parameters + return [ + scalar_to_query_parameter(value, name=name) + for name, value + in six.iteritems(parameters)] def to_query_parameters(parameters): """Converts DB-API parameter values into query parameters. - :type: dict or list - :param parameters: Optional dictionary or list of query parameter values. + STRUCT/RECORD and REPEATED type parameters are not yet supported. + https://github.com/GoogleCloudPlatform/google-cloud-python/issues/3524 + + :type: Mapping[str, Any] or Sequence[Any] + :param parameters: A dictionary or sequence of query parameter values. :rtype: list of :class:`~google.cloud.bigquery._helpers.AbstractQueryParameter` diff --git a/bigquery/google/cloud/bigquery/dbapi/cursor.py b/bigquery/google/cloud/bigquery/dbapi/cursor.py index e27125c3338f9..dc60133fa2f2b 100644 --- a/bigquery/google/cloud/bigquery/dbapi/cursor.py +++ b/bigquery/google/cloud/bigquery/dbapi/cursor.py @@ -23,7 +23,16 @@ from google.cloud.bigquery.dbapi import exceptions -_ARRAYSIZE_DEFAULT = 20 +# Per PEP 249: A 7-item sequence containing information describing one result +# column. The first two items (name and type_code) are mandatory, the other +# five are optional and are set to None if no meaningful values can be +# provided. +Column = collections.namedtuple( + 'Column', + [ + 'name', 'type_code', 'display_size', 'internal_size', 'precision', + 'scale', 'null_ok', + ]) class Cursor(object): @@ -35,8 +44,13 @@ class Cursor(object): def __init__(self, connection): self.connection = connection self.description = None + # Per PEP 249: The attribute is -1 in case no .execute*() has been + # performed on the cursor or the rowcount of the last operation + # cannot be determined by the interface. self.rowcount = -1 - self.arraysize = None + # Per PEP 249: The arraysize attribute defaults to 1, meaning to fetch + # a single row at a time. + self.arraysize = 1 self._query_data = None self._page_token = None self._has_fetched_all_rows = True @@ -47,23 +61,23 @@ def close(self): def _set_description(self, schema): """Set description from schema. - :type: list of :class:`~google.cloud.bigquery.schema.SchemaField` + :type: Sequence[:class:`~google.cloud.bigquery.schema.SchemaField`] + :param schema: A description of fields in the schema. """ if schema is None: self.description = None return - desc = [] - for field in schema: - desc.append(tuple([ + self.description = tuple([ + Column( field.name, field.field_type, None, None, None, None, - field.mode == 'NULLABLE'])) - self.description = tuple(desc) + field.mode == 'NULLABLE') + for field in schema]) def _set_rowcount(self, query_results): """Set the rowcount from query results. @@ -86,13 +100,16 @@ def _set_rowcount(self, query_results): self.rowcount = total_rows def _format_operation_list(self, operation, parameters): - """Formats parameters in operation in way BigQuery expects. + """Formats parameters in operation in the way BigQuery expects. + + The input operation will be a query like ``SELECT %s`` and the output + will be a query like ``SELECT ?``. :type: str :param operation: A Google BigQuery query string. - :type: list - :param parameters: List parameter values. + :type: Sequence[Any] + :param parameters: Sequence of parameter values. """ formatted_params = ['?' for _ in parameters] @@ -102,12 +119,15 @@ def _format_operation_list(self, operation, parameters): raise exceptions.ProgrammingError(ex) def _format_operation_dict(self, operation, parameters): - """Formats parameters in operation in way BigQuery expects. + """Formats parameters in operation in the way BigQuery expects. + + The input operation will be a query like ``SELECT %(namedparam)s`` and + the output will be a query like ``SELECT @namedparam``. :type: str :param operation: A Google BigQuery query string. - :type: dict + :type: Mapping[str, Any] :param parameters: Dictionary of parameter values. """ formatted_params = {} @@ -128,7 +148,7 @@ def _format_operation(self, operation, parameters=None): :type: str :param operation: A Google BigQuery query string. - :type: dict or list + :type: Mapping[str, Any] or Sequence[Any] :param parameters: Optional parameter values. """ if parameters is None: @@ -145,7 +165,7 @@ def execute(self, operation, parameters=None): :type: str :param operation: A Google BigQuery query string. - :type: dict or list + :type: Mapping[str, Any] or Sequence[Any] :param parameters: Optional dictionary or sequence of parameter values. """ self._query_results = None @@ -191,7 +211,7 @@ def executemany(self, operation, seq_of_parameters): :type: str :param operation: A Google BigQuery query string. - :type: list + :type: Sequence[Mapping[str, Any] or Sequence[Any]] :param parameters: Sequence of many sets of parameter values. """ for parameters in seq_of_parameters: @@ -218,14 +238,15 @@ def fetchmany(self, size=None): """Fetch multiple results from the last ``execute*()`` call. Note that the size parameter is not used for the request/response size. - Use ``arraysize()`` before calling ``execute()`` to set the batch size. + Set the ``arraysize`` attribute before calling ``execute()`` to set the + batch size. :type: int :param size: - Optional maximum number of rows to return. Defaults to the - arraysize attribute. + (Optional) Maximum number of rows to return. Defaults to the + ``arraysize`` property value. - :rtype: tuple + :rtype: Sequence[tuple] :returns: A list of rows. """ if self._query_data is None: @@ -233,8 +254,6 @@ def fetchmany(self, size=None): 'No query results: execute() must be called before fetch.') if size is None: size = self.arraysize - if size is None: - size = _ARRAYSIZE_DEFAULT rows = [] for row in self._query_data: @@ -246,7 +265,7 @@ def fetchmany(self, size=None): def fetchall(self): """Fetch all remaining results from the last ``execute*()`` call. - :rtype: list of tuples + :rtype: Sequence[tuple] :returns: A list of all the rows in the results. """ if self._query_data is None: diff --git a/bigquery/google/cloud/bigquery/dbapi/types.py b/bigquery/google/cloud/bigquery/dbapi/types.py index 23c371e75fe3a..12980a4d5daf1 100644 --- a/bigquery/google/cloud/bigquery/dbapi/types.py +++ b/bigquery/google/cloud/bigquery/dbapi/types.py @@ -22,13 +22,15 @@ import datetime +import six + Date = datetime.date Time = datetime.time Timestamp = datetime.datetime DateFromTicks = datetime.date.fromtimestamp TimestampFromTicks = datetime.datetime.fromtimestamp -Binary = bytes +Binary = six.binary_type def TimeFromTicks(ticks, tz=None): diff --git a/bigquery/tests/system.py b/bigquery/tests/system.py index 01e5e7d680570..e2d3be3485a8c 100644 --- a/bigquery/tests/system.py +++ b/bigquery/tests/system.py @@ -170,9 +170,9 @@ def test_list_datasets(self): 'newest' + unique_resource_id(), ] for dataset_name in datasets_to_create: - dataset = Config.CLIENT.dataset(dataset_name) - retry_403(dataset.create)() - self.to_delete.append(dataset) + created_dataset = Config.CLIENT.dataset(dataset_name) + retry_403(created_dataset.create)() + self.to_delete.append(created_dataset) # Retrieve the datasets. iterator = Config.CLIENT.list_datasets() @@ -225,9 +225,9 @@ def test_list_tables(self): mode='REQUIRED') age = bigquery.SchemaField('age', 'INTEGER', mode='REQUIRED') for table_name in tables_to_create: - table = dataset.table(table_name, schema=[full_name, age]) - table.create() - self.to_delete.insert(0, table) + created_table = dataset.table(table_name, schema=[full_name, age]) + created_table.create() + self.to_delete.insert(0, created_table) # Retrieve the tables. iterator = dataset.list_tables() @@ -547,7 +547,7 @@ def test_sync_query_w_legacy_sql_types(self): naive = datetime.datetime(2016, 12, 5, 12, 41, 9) stamp = '%s %s' % (naive.date().isoformat(), naive.time().isoformat()) zoned = naive.replace(tzinfo=UTC) - EXAMPLES = [ + examples = [ { 'sql': 'SELECT 1', 'expected': 1, @@ -573,7 +573,7 @@ def test_sync_query_w_legacy_sql_types(self): 'expected': zoned, }, ] - for example in EXAMPLES: + for example in examples: query = Config.CLIENT.run_sync_query(example['sql']) query.use_legacy_sql = True query.run() @@ -664,8 +664,8 @@ def _generate_standard_sql_types_examples(self): ] def test_sync_query_w_standard_sql_types(self): - EXAMPLES = self._generate_standard_sql_types_examples() - for example in EXAMPLES: + examples = self._generate_standard_sql_types_examples() + for example in examples: query = Config.CLIENT.run_sync_query(example['sql']) query.use_legacy_sql = False query.run() @@ -674,8 +674,8 @@ def test_sync_query_w_standard_sql_types(self): self.assertEqual(query.rows[0][0], example['expected']) def test_dbapi_w_standard_sql_types(self): - EXAMPLES = self._generate_standard_sql_types_examples() - for example in EXAMPLES: + examples = self._generate_standard_sql_types_examples() + for example in examples: Config.CURSOR.execute(example['sql']) self.assertEqual(Config.CURSOR.rowcount, 1) row = Config.CURSOR.fetchone() @@ -724,7 +724,7 @@ def _job_done(instance): def test_sync_query_w_dml(self): dataset_name = _make_dataset_name('dml_tests') table_name = 'test_table' - self._load_table_for_dml([('Hello World',),], dataset_name, table_name) + self._load_table_for_dml([('Hello World',)], dataset_name, table_name) query = Config.CLIENT.run_sync_query( 'UPDATE {}.{} ' @@ -739,7 +739,7 @@ def test_sync_query_w_dml(self): def test_dbapi_w_dml(self): dataset_name = _make_dataset_name('dml_tests') table_name = 'test_table' - self._load_table_for_dml([('Hello World',),], dataset_name, table_name) + self._load_table_for_dml([('Hello World',)], dataset_name, table_name) Config.CURSOR.execute( 'UPDATE {}.{} ' @@ -811,7 +811,7 @@ def test_sync_query_w_query_params(self): name='friends', array_type='STRING', values=[phred_name, bharney_name]) with_friends_param = StructQueryParameter(None, friends_param) - EXAMPLES = [ + examples = [ { 'sql': 'SELECT @question', 'expected': question, @@ -891,7 +891,7 @@ def test_sync_query_w_query_params(self): 'query_parameters': [with_friends_param], }, ] - for example in EXAMPLES: + for example in examples: query = Config.CLIENT.run_sync_query( example['sql'], query_parameters=example['query_parameters']) @@ -902,7 +902,7 @@ def test_sync_query_w_query_params(self): self.assertEqual(query.rows[0][0], example['expected']) def test_dbapi_w_query_parameters(self): - EXAMPLES = [ + examples = [ { 'sql': 'SELECT %(boolval)s', 'expected': True, @@ -967,17 +967,19 @@ def test_dbapi_w_query_parameters(self): { 'sql': 'SELECT TIMESTAMP_TRUNC(%(zoned)s, MINUTE)', 'query_parameters': { - 'zoned': datetime.datetime(2012, 3, 4, 5, 6, 7, tzinfo=UTC), + 'zoned': datetime.datetime( + 2012, 3, 4, 5, 6, 7, tzinfo=UTC), }, 'expected': datetime.datetime(2012, 3, 4, 5, 6, 0, tzinfo=UTC), }, ] - for example in EXAMPLES: + for example in examples: msg = 'sql: {} query_parameters: {}'.format( example['sql'], example['query_parameters']) try: - Config.CURSOR.execute(example['sql'], example['query_parameters']) + Config.CURSOR.execute( + example['sql'], example['query_parameters']) except dbapi.DatabaseError as ex: raise dbapi.DatabaseError('{} {}'.format(ex, msg)) @@ -1007,7 +1009,6 @@ def test_large_query_w_public_data(self): SQL = 'SELECT * from `{}.{}.{}` LIMIT {}'.format( PUBLIC, DATASET_NAME, TABLE_NAME, LIMIT) - dataset = Config.CLIENT.dataset(DATASET_NAME, project=PUBLIC) query = Config.CLIENT.run_sync_query(SQL) query.use_legacy_sql = False query.run() diff --git a/bigquery/tests/unit/test_dbapi__helpers.py b/bigquery/tests/unit/test_dbapi__helpers.py index 4219fdfef2790..8a16548c6cb4c 100644 --- a/bigquery/tests/unit/test_dbapi__helpers.py +++ b/bigquery/tests/unit/test_dbapi__helpers.py @@ -17,7 +17,6 @@ import unittest import mock -import six import google.cloud._helpers from google.cloud.bigquery.dbapi import _helpers @@ -42,7 +41,8 @@ def mock_reload(): def _call_fut(self, job): from google.cloud.bigquery.dbapi._helpers import wait_for_job - wait_for_job(job) + with mock.patch('time.sleep'): + wait_for_job(job) def test_wo_error(self): mock_job = self._mock_job() @@ -53,12 +53,12 @@ def test_wo_error(self): def test_w_error(self): from google.cloud.bigquery.dbapi import exceptions mock_job = self._mock_job() - mock_job.error_result ={'reason': 'invalidQuery'} + mock_job.error_result = {'reason': 'invalidQuery'} self.assertRaises(exceptions.DatabaseError, self._call_fut, mock_job) self.assertEqual('DONE', mock_job.state) -class TestHelpers(unittest.TestCase): +class TestQueryParameters(unittest.TestCase): def test_scalar_to_query_parameter(self): expected_types = [ @@ -67,8 +67,8 @@ def test_scalar_to_query_parameter(self): (123, 'INT64'), (-123456789, 'INT64'), (1.25, 'FLOAT64'), - ('I am a plain old string', 'STRING'), - (u'I am a unicode string', 'STRING'), + (b'I am some bytes', 'BYTES'), + (u'I am a string', 'STRING'), (datetime.date(2017, 4, 1), 'DATE'), (datetime.time(12, 34, 56), 'TIME'), (datetime.datetime(2012, 3, 4, 5, 6, 7), 'DATETIME'), @@ -80,44 +80,32 @@ def test_scalar_to_query_parameter(self): ] for value, expected_type in expected_types: msg = 'value: {} expected_type: {}'.format(value, expected_type) - parameter = _helpers.scalar_to_query_parameter(None, value) + parameter = _helpers.scalar_to_query_parameter(value) self.assertIsNone(parameter.name, msg=msg) self.assertEqual(parameter.type_, expected_type, msg=msg) self.assertEqual(parameter.value, value, msg=msg) - named_parameter = _helpers.scalar_to_query_parameter('myvar', value) + named_parameter = _helpers.scalar_to_query_parameter( + value, name='myvar') self.assertEqual(named_parameter.name, 'myvar', msg=msg) self.assertEqual(named_parameter.type_, expected_type, msg=msg) self.assertEqual(named_parameter.value, value, msg=msg) - @unittest.skipIf(six.PY2, 'Bytes cannot be distinguished from string.') - def test_scalar_to_query_parameter_w_bytes(self): - parameter = _helpers.scalar_to_query_parameter( - None, b'some-bytes-literal') - self.assertIsNone(parameter.name) - self.assertEqual(parameter.type_, 'BYTES') - self.assertEqual(parameter.value, b'some-bytes-literal') - named_parameter = _helpers.scalar_to_query_parameter( - 'myvar', b'some-bytes-literal') - self.assertEqual(named_parameter.name, 'myvar') - self.assertEqual(named_parameter.type_, 'BYTES') - self.assertEqual(named_parameter.value, b'some-bytes-literal') - def test_scalar_to_query_parameter_w_unexpected_type(self): with self.assertRaises(exceptions.ProgrammingError): _helpers.scalar_to_query_parameter(value={'a': 'dictionary'}) def test_scalar_to_query_parameter_w_special_floats(self): - nan_parameter = _helpers.scalar_to_query_parameter(None, float('nan')) + nan_parameter = _helpers.scalar_to_query_parameter(float('nan')) self.assertTrue(math.isnan(nan_parameter.value)) self.assertEqual(nan_parameter.type_, 'FLOAT64') - inf_parameter = _helpers.scalar_to_query_parameter(None, float('inf')) + inf_parameter = _helpers.scalar_to_query_parameter(float('inf')) self.assertTrue(math.isinf(inf_parameter.value)) self.assertEqual(inf_parameter.type_, 'FLOAT64') def test_to_query_parameters_w_dict(self): parameters = { 'somebool': True, - 'somestring': 'a-string-value', + 'somestring': u'a-string-value', } query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] @@ -128,11 +116,11 @@ def test_to_query_parameters_w_dict(self): sorted(query_parameter_tuples), sorted([ ('somebool', 'BOOL', True), - ('somestring', 'STRING', 'a-string-value'), + ('somestring', 'STRING', u'a-string-value'), ])) def test_to_query_parameters_w_list(self): - parameters = [True, 'a-string-value'] + parameters = [True, u'a-string-value'] query_parameters = _helpers.to_query_parameters(parameters) query_parameter_tuples = [] for param in query_parameters: @@ -142,5 +130,5 @@ def test_to_query_parameters_w_list(self): sorted(query_parameter_tuples), sorted([ (None, 'BOOL', True), - (None, 'STRING', 'a-string-value'), + (None, 'STRING', u'a-string-value'), ])) diff --git a/bigquery/tests/unit/test_dbapi_cursor.py b/bigquery/tests/unit/test_dbapi_cursor.py index 451bee1a67920..73d74f0f559ae 100644 --- a/bigquery/tests/unit/test_dbapi_cursor.py +++ b/bigquery/tests/unit/test_dbapi_cursor.py @@ -28,7 +28,7 @@ def _make_one(self, *args, **kw): return self._get_target_class()(*args, **kw) def _mock_client( - self, rows=None, schema=None, num_dml_affected_rows=None): + self, rows=None, schema=None, num_dml_affected_rows=None): from google.cloud.bigquery import client mock_client = mock.create_autospec(client.Client) mock_client.run_async_query.return_value = self._mock_job( @@ -37,7 +37,7 @@ def _mock_client( return mock_client def _mock_job( - self, rows=None, schema=None, num_dml_affected_rows=None): + self, rows=None, schema=None, num_dml_affected_rows=None): from google.cloud.bigquery import job mock_job = mock.create_autospec(job.QueryJob) mock_job.error_result = None @@ -48,7 +48,7 @@ def _mock_job( return mock_job def _mock_results( - self, rows=None, schema=None, num_dml_affected_rows=None): + self, rows=None, schema=None, num_dml_affected_rows=None): from google.cloud.bigquery import query mock_results = mock.create_autospec(query.QueryResults) mock_results.schema = schema @@ -72,7 +72,6 @@ def test_ctor(self): def test_close(self): from google.cloud.bigquery.dbapi import connect - from google.cloud.bigquery.dbapi import Cursor connection = connect(self._mock_client()) cursor = connection.cursor() # close() is a no-op, there is nothing to test. @@ -173,7 +172,6 @@ def test_fetchall_w_row(self): def test_execute_w_dml(self): from google.cloud.bigquery.dbapi import connect - from google.cloud.bigquery.dbapi import Cursor connection = connect( self._mock_client(rows=[], num_dml_affected_rows=12)) cursor = connection.cursor() @@ -223,7 +221,6 @@ def test_execute_w_query(self): def test_executemany_w_dml(self): from google.cloud.bigquery.dbapi import connect - from google.cloud.bigquery.dbapi import Cursor connection = connect( self._mock_client(rows=[], num_dml_affected_rows=12)) cursor = connection.cursor() diff --git a/bigquery/tests/unit/test_table.py b/bigquery/tests/unit/test_table.py index c940706c6b860..5a3c70112564b 100644 --- a/bigquery/tests/unit/test_table.py +++ b/bigquery/tests/unit/test_table.py @@ -403,7 +403,7 @@ def test_create_new_day_partitioned_table(self): dataset = _Dataset(client) table = self._make_one(self.TABLE_NAME, dataset) table.partitioning_type = 'DAY' - table.create() + table.create() self.assertEqual(len(conn._requested), 1) req = conn._requested[0] @@ -1049,12 +1049,6 @@ def test_fetch_data_wo_schema(self): client = _Client(project=self.PROJECT) dataset = _Dataset(client) table = self._make_one(self.TABLE_NAME, dataset=dataset) - ROWS = [ - ('Phred Phlyntstone', 32), - ('Bharney Rhubble', 33), - ('Wylma Phlyntstone', 29), - ('Bhettye Rhubble', 27), - ] with self.assertRaises(ValueError) as exc: table.fetch_data()