Skip to content

Commit 9a79389

Browse files
committed
fix tests
1 parent 577553f commit 9a79389

File tree

3 files changed

+59
-36
lines changed

3 files changed

+59
-36
lines changed

bigframes/bigquery/_operations/obj.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,9 @@
1313
# limitations under the License.
1414

1515

16-
"""This module integrates BigQuery built-in 'ObjectRef' functions for use with Series/DataFrame objects,
17-
such as OBJ.FETCH_METADATA:
18-
https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/objectref_functions
16+
"""This module exposes BigQuery ObjectRef functions.
1917
20-
21-
.. warning::
22-
23-
This product or feature is subject to the "Pre-GA Offerings Terms" in the
24-
General Service Terms section of the `Service Specific Terms
25-
<https://cloud.google.com/terms/service-terms>`_. Pre-GA products and
26-
features are available "as is" and might have limited support. For more
27-
information, see the `launch stage descriptions
28-
<https://cloud.google.com/products?hl=en#product-launch-stages>`_.
29-
30-
.. note::
31-
32-
To provide feedback or request support for this feature, send an email to
33-
bq-objectref-feedback@google.com.
18+
See bigframes.bigquery.obj for public docs.
3419
"""
3520

3621

@@ -120,6 +105,10 @@ def make_ref(
120105
uri_or_json = convert.to_bf_series(uri_or_json, default_index=None)
121106

122107
if authorizer is not None:
108+
# Avoid join problems encountered if we try to convert a literal into Series.
109+
if not isinstance(authorizer, str):
110+
authorizer = convert.to_bf_series(authorizer, default_index=None)
111+
123112
return uri_or_json._apply_binary_op(authorizer, ops.obj_make_ref_op)
124113

125114
# If authorizer is not provided, we assume uri_or_json is a JSON objectref

bigframes/bigquery/obj.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""This module exposes `BigQuery ObjectRef
16-
<https://cloud.google.com/bigquery/docs/object-table-object-ref-functions>`_ functions.
15+
"""This module integrates BigQuery built-in 'ObjectRef' functions for use with Series/DataFrame objects,
16+
such as OBJ.FETCH_METADATA:
17+
https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/objectref_functions
18+
19+
20+
.. warning::
21+
22+
This product or feature is subject to the "Pre-GA Offerings Terms" in the
23+
General Service Terms section of the `Service Specific Terms
24+
<https://cloud.google.com/terms/service-terms>`_. Pre-GA products and
25+
features are available "as is" and might have limited support. For more
26+
information, see the `launch stage descriptions
27+
<https://cloud.google.com/products?hl=en#product-launch-stages>`_.
28+
29+
.. note::
30+
31+
To provide feedback or request support for this feature, send an email to
32+
bq-objectref-feedback@google.com.
1733
"""
1834

1935
from bigframes.bigquery._operations.obj import fetch_metadata, get_access_url, make_ref

tests/unit/bigquery/test_obj.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
# limitations under the License.
1414

1515
import datetime
16-
from unittest.mock import MagicMock
16+
from unittest import mock
1717

1818
import bigframes.bigquery.obj as obj
1919
import bigframes.operations as ops
20-
import bigframes.series as series
20+
import bigframes.series
21+
22+
23+
def create_mock_series():
24+
result = mock.create_autospec(bigframes.series.Series, instance=True)
25+
result.copy.return_value = result
26+
return result
2127

2228

2329
def test_fetch_metadata_op_structure():
@@ -50,44 +56,56 @@ def test_make_ref_json_op_structure():
5056

5157

5258
def test_fetch_metadata_calls_apply_unary_op():
53-
s = MagicMock(spec=series.Series)
59+
series = create_mock_series()
5460

55-
obj.fetch_metadata(s)
61+
obj.fetch_metadata(series)
5662

57-
s._apply_unary_op.assert_called_once()
58-
args, _ = s._apply_unary_op.call_args
63+
series._apply_unary_op.assert_called_once()
64+
args, _ = series._apply_unary_op.call_args
5965
assert args[0] == ops.obj_fetch_metadata_op
6066

6167

6268
def test_get_access_url_calls_apply_unary_op_without_duration():
63-
s = MagicMock(spec=series.Series)
69+
series = create_mock_series()
6470

65-
obj.get_access_url(s, mode="r")
71+
obj.get_access_url(series, mode="r")
6672

67-
s._apply_unary_op.assert_called_once()
68-
args, _ = s._apply_unary_op.call_args
73+
series._apply_unary_op.assert_called_once()
74+
args, _ = series._apply_unary_op.call_args
6975
assert isinstance(args[0], ops.ObjGetAccessUrl)
7076
assert args[0].mode == "r"
7177
assert args[0].duration is None
7278

7379

7480
def test_get_access_url_calls_apply_unary_op_with_duration():
75-
s = MagicMock(spec=series.Series)
81+
series = create_mock_series()
7682
duration = datetime.timedelta(hours=1)
7783

78-
obj.get_access_url(s, mode="rw", duration=duration)
84+
obj.get_access_url(series, mode="rw", duration=duration)
7985

80-
s._apply_unary_op.assert_called_once()
81-
args, kwargs = s._apply_unary_op.call_args
86+
series._apply_unary_op.assert_called_once()
87+
args, _ = series._apply_unary_op.call_args
8288
assert isinstance(args[0], ops.ObjGetAccessUrl)
8389
assert args[0].mode == "rw"
8490
# 1 hour = 3600 seconds = 3600 * 1000 * 1000 microseconds
8591
assert args[0].duration == 3600000000
8692

8793

8894
def test_make_ref_calls_apply_binary_op_with_authorizer():
89-
uri = MagicMock(spec=series.Series)
90-
auth = MagicMock(spec=series.Series)
95+
uri = create_mock_series()
96+
auth = create_mock_series()
97+
98+
obj.make_ref(uri, authorizer=auth)
99+
100+
uri._apply_binary_op.assert_called_once()
101+
args, _ = uri._apply_binary_op.call_args
102+
assert args[0] == auth
103+
assert args[1] == ops.obj_make_ref_op
104+
105+
106+
def test_make_ref_calls_apply_binary_op_with_authorizer_string():
107+
uri = create_mock_series()
108+
auth = "us.bigframes-test-connection"
91109

92110
obj.make_ref(uri, authorizer=auth)
93111

@@ -98,7 +116,7 @@ def test_make_ref_calls_apply_binary_op_with_authorizer():
98116

99117

100118
def test_make_ref_calls_apply_unary_op_without_authorizer():
101-
json_val = MagicMock(spec=series.Series)
119+
json_val = create_mock_series()
102120

103121
obj.make_ref(json_val)
104122

0 commit comments

Comments
 (0)