Skip to content

Commit 4ac00ca

Browse files
committed
updates allowed arg types to include str, and assoc. tests
1 parent a1eddb5 commit 4ac00ca

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

google/cloud/bigquery/external_config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,17 @@ def source_column_match(self) -> Optional[SourceColumnMatch]:
496496
"""
497497

498498
value = self._properties.get("sourceColumnMatch")
499-
# if value is not None:
500499
return SourceColumnMatch(value) if value is not None else None
501-
# return None
502500

503501
@source_column_match.setter
504-
def source_column_match(self, value: Optional[SourceColumnMatch]):
505-
if value is not None and not isinstance(value, SourceColumnMatch):
502+
def source_column_match(self, value: Union[SourceColumnMatch, str, None]):
503+
if value is not None and not isinstance(value, (SourceColumnMatch, str)):
506504
raise TypeError(
507-
"value must be a google.cloud.bigquery.enums.SourceColumnMatch or None"
505+
"value must be a google.cloud.bigquery.enums.SourceColumnMatch, str, or None"
508506
)
509-
self._properties["sourceColumnMatch"] = value.value if value else None
507+
if isinstance(value, SourceColumnMatch):
508+
value = value.value
509+
self._properties["sourceColumnMatch"] = value if value else None
510510

511511
@property
512512
def null_markers(self) -> Optional[Iterable[str]]:

google/cloud/bigquery/job/load.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Classes for load jobs."""
1616

1717
import typing
18-
from typing import FrozenSet, List, Iterable, Optional
18+
from typing import FrozenSet, List, Iterable, Optional, Union
1919

2020
from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
2121
from google.cloud.bigquery.enums import SourceColumnMatch
@@ -591,17 +591,17 @@ def source_column_match(self) -> Optional[SourceColumnMatch]:
591591
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match
592592
"""
593593
value = self._get_sub_prop("sourceColumnMatch")
594-
if value is not None:
595-
return SourceColumnMatch(value)
596-
return None
594+
return SourceColumnMatch(value) if value is not None else None
597595

598596
@source_column_match.setter
599-
def source_column_match(self, value: Optional[SourceColumnMatch]):
600-
if value is not None and not isinstance(value, SourceColumnMatch):
597+
def source_column_match(self, value: Union[SourceColumnMatch, str, None]):
598+
if value is not None and not isinstance(value, (SourceColumnMatch, str)):
601599
raise TypeError(
602-
"value must be a google.cloud.bigquery.enums.SourceColumnMatch or None"
600+
"value must be a google.cloud.bigquery.enums.SourceColumnMatch, str, or None"
603601
)
604-
self._set_sub_prop("sourceColumnMatch", value.value if value else None)
602+
if isinstance(value, SourceColumnMatch):
603+
value = value.value
604+
self._set_sub_prop("sourceColumnMatch", value if value else None)
605605

606606
@property
607607
def date_format(self) -> Optional[str]:
@@ -1018,7 +1018,7 @@ def clustering_fields(self):
10181018
return self.configuration.clustering_fields
10191019

10201020
@property
1021-
def source_column_match(self):
1021+
def source_column_match(self) -> Optional[SourceColumnMatch]:
10221022
"""See
10231023
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_column_match`.
10241024
"""

tests/unit/job/test_load_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,14 @@ def test_source_column_match_setter(self):
867867
self.assertEqual(
868868
config._properties["load"]["sourceColumnMatch"], option_enum.value
869869
)
870+
option_str = "NAME"
871+
config.source_column_match = option_str
872+
self.assertEqual(config._properties["load"]["sourceColumnMatch"], option_str)
870873

871874
def test_source_column_match_setter_invalid_type(self):
872875
config = self._get_target_class()()
873876
with self.assertRaises(TypeError):
874-
config.source_column_match = "INVALID_STRING_TYPE"
877+
config.source_column_match = 3.14
875878

876879
def test_date_format_missing(self):
877880
config = self._get_target_class()()

tests/unit/test_external_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,9 @@ def test_source_column_match_invalid_input(self):
939939
ec = external_config.CSVOptions()
940940
with self.assertRaisesRegex(
941941
TypeError,
942-
"value must be a google.cloud.bigquery.enums.SourceColumnMatch or None",
942+
"value must be a google.cloud.bigquery.enums.SourceColumnMatch, str, or None",
943943
):
944-
ec.source_column_match = "neither None or enum value"
944+
ec.source_column_match = 3.14
945945

946946

947947
class TestGoogleSheetsOptions(unittest.TestCase):

0 commit comments

Comments
 (0)