Skip to content

Commit

Permalink
BigQuery: Remove client-side enum validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sneeringer committed Aug 7, 2017
1 parent 6d7fae9 commit 5e83d14
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
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

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

0 comments on commit 5e83d14

Please sign in to comment.