Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: Remove client-side enum validation. #3735

Merged
merged 1 commit into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions bigquery/google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,9 @@ def _validate(self, value):
class _EnumProperty(_ConfigurationProperty):
"""Pseudo-enumeration class.

Subclasses must define ``ALLOWED`` as a class-level constant: it must
be a sequence of strings.

:type name: str
:param name: name of the property.
"""
def _validate(self, value):
"""Check that ``value`` is one of the allowed values.

:raises: ValueError if value is not allowed.
"""
if value not in self.ALLOWED:
raise ValueError('Pass one of: %s' % ', '.join(self.ALLOWED))


class UDFResource(object):
Expand Down
7 changes: 0 additions & 7 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,31 @@ class Compression(_EnumProperty):
"""Pseudo-enum for ``compression`` properties."""
GZIP = 'GZIP'
NONE = 'NONE'
ALLOWED = (GZIP, NONE)


class CreateDisposition(_EnumProperty):
"""Pseudo-enum for ``create_disposition`` properties."""
CREATE_IF_NEEDED = 'CREATE_IF_NEEDED'
CREATE_NEVER = 'CREATE_NEVER'
ALLOWED = (CREATE_IF_NEEDED, CREATE_NEVER)


class DestinationFormat(_EnumProperty):
"""Pseudo-enum for ``destination_format`` properties."""
CSV = 'CSV'
NEWLINE_DELIMITED_JSON = 'NEWLINE_DELIMITED_JSON'
AVRO = 'AVRO'
ALLOWED = (CSV, NEWLINE_DELIMITED_JSON, AVRO)


class Encoding(_EnumProperty):
"""Pseudo-enum for ``encoding`` properties."""
UTF_8 = 'UTF-8'
ISO_8559_1 = 'ISO-8559-1'
ALLOWED = (UTF_8, ISO_8559_1)


class QueryPriority(_EnumProperty):
"""Pseudo-enum for ``QueryJob.priority`` property."""
INTERACTIVE = 'INTERACTIVE'
BATCH = 'BATCH'
ALLOWED = (INTERACTIVE, BATCH)


class SourceFormat(_EnumProperty):
Expand All @@ -136,15 +131,13 @@ class SourceFormat(_EnumProperty):
DATASTORE_BACKUP = 'DATASTORE_BACKUP'
NEWLINE_DELIMITED_JSON = 'NEWLINE_DELIMITED_JSON'
AVRO = 'AVRO'
ALLOWED = (CSV, DATASTORE_BACKUP, NEWLINE_DELIMITED_JSON, AVRO)


class WriteDisposition(_EnumProperty):
"""Pseudo-enum for ``write_disposition`` properties."""
WRITE_APPEND = 'WRITE_APPEND'
WRITE_TRUNCATE = 'WRITE_TRUNCATE'
WRITE_EMPTY = 'WRITE_EMPTY'
ALLOWED = (WRITE_APPEND, WRITE_TRUNCATE, WRITE_EMPTY)


class _AsyncJob(google.cloud.future.polling.PollingFuture):
Expand Down
5 changes: 1 addition & 4 deletions bigquery/tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def _get_target_class():
def test_it(self):

class Sub(self._get_target_class()):
ALLOWED = ('FOO', 'BAR', 'BAZ')
pass

This comment was marked as spam.

This comment was marked as spam.


class Configuration(object):
_attr = None
Expand All @@ -777,9 +777,6 @@ def __init__(self):
self._configuration = Configuration()

wrapper = Wrapper()
with self.assertRaises(ValueError):
wrapper.attr = 'BOGUS'

wrapper.attr = 'FOO'
self.assertEqual(wrapper.attr, 'FOO')
self.assertEqual(wrapper._configuration._attr, 'FOO')
Expand Down