Skip to content

Commit 200b75a

Browse files
committed
migrate more tests
1 parent 20691ac commit 200b75a

File tree

4 files changed

+290
-259
lines changed

4 files changed

+290
-259
lines changed

tests/unit/job/test_query.py

Lines changed: 0 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
import types
2121
from unittest import mock
2222

23-
import freezegun
24-
from google.api_core import exceptions
25-
import google.api_core.retry
2623
import requests
2724

2825
from google.cloud.bigquery.client import _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS
2926
import google.cloud.bigquery._job_helpers
3027
import google.cloud.bigquery.query
31-
import google.cloud.bigquery.retry
3228
from google.cloud.bigquery.retry import DEFAULT_GET_JOB_TIMEOUT
3329
from google.cloud.bigquery.table import _EmptyRowIterator
3430

@@ -1335,102 +1331,6 @@ def test_result_with_max_results(self):
13351331
[jobs_get_call, query_page_waiting_call, query_page_2_call]
13361332
)
13371333

1338-
def test_result_w_custom_retry(self, global_time_lock):
1339-
from google.cloud.bigquery.table import RowIterator
1340-
1341-
query_resource = {
1342-
"jobComplete": False,
1343-
"jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID},
1344-
}
1345-
query_resource_done = {
1346-
"jobComplete": True,
1347-
"jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID},
1348-
"schema": {"fields": [{"name": "col1", "type": "STRING"}]},
1349-
"totalRows": "2",
1350-
}
1351-
job_resource = self._make_resource(started=True, location="asia-northeast1")
1352-
job_resource_done = self._make_resource(
1353-
started=True, ended=True, location="asia-northeast1"
1354-
)
1355-
job_resource_done["configuration"]["query"]["destinationTable"] = {
1356-
"projectId": "dest-project",
1357-
"datasetId": "dest_dataset",
1358-
"tableId": "dest_table",
1359-
}
1360-
1361-
connection = make_connection(
1362-
# Also, for each API request, raise an exception that we know can
1363-
# be retried. Because of this, for each iteration we do:
1364-
# jobs.get (x2) & jobs.getQueryResults (x2)
1365-
exceptions.NotFound("not normally retriable"),
1366-
job_resource,
1367-
exceptions.NotFound("not normally retriable"),
1368-
query_resource,
1369-
# Query still not done, repeat both.
1370-
exceptions.NotFound("not normally retriable"),
1371-
job_resource,
1372-
exceptions.NotFound("not normally retriable"),
1373-
query_resource,
1374-
exceptions.NotFound("not normally retriable"),
1375-
# Query still not done, repeat both.
1376-
job_resource_done,
1377-
exceptions.NotFound("not normally retriable"),
1378-
query_resource_done,
1379-
# Query finished!
1380-
)
1381-
client = _make_client(self.PROJECT, connection=connection)
1382-
job = self._get_target_class().from_api_repr(job_resource, client)
1383-
1384-
custom_predicate = mock.Mock()
1385-
custom_predicate.return_value = True
1386-
custom_retry = google.api_core.retry.Retry(
1387-
initial=0.001,
1388-
maximum=0.001,
1389-
multiplier=1.0,
1390-
deadline=0.1,
1391-
predicate=custom_predicate,
1392-
)
1393-
1394-
self.assertIsInstance(job.result(retry=custom_retry), RowIterator)
1395-
query_results_call = mock.call(
1396-
method="GET",
1397-
path=f"/projects/{self.PROJECT}/queries/{self.JOB_ID}",
1398-
query_params={"maxResults": 0, "location": "asia-northeast1"},
1399-
# TODO(tswast): Why do we end up setting timeout to
1400-
# google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT in
1401-
# some cases but not others?
1402-
timeout=mock.ANY,
1403-
)
1404-
reload_call = mock.call(
1405-
method="GET",
1406-
path=f"/projects/{self.PROJECT}/jobs/{self.JOB_ID}",
1407-
query_params={"projection": "full", "location": "asia-northeast1"},
1408-
timeout=DEFAULT_GET_JOB_TIMEOUT,
1409-
)
1410-
1411-
connection.api_request.assert_has_calls(
1412-
[
1413-
# See make_connection() call above for explanation of the
1414-
# expected API calls.
1415-
#
1416-
# Query not done.
1417-
reload_call,
1418-
reload_call,
1419-
query_results_call,
1420-
query_results_call,
1421-
# Query still not done.
1422-
reload_call,
1423-
reload_call,
1424-
query_results_call,
1425-
query_results_call,
1426-
# Query done!
1427-
reload_call,
1428-
reload_call,
1429-
query_results_call,
1430-
query_results_call,
1431-
]
1432-
)
1433-
14341334
def test_result_w_empty_schema(self):
14351335
from google.cloud.bigquery.table import _EmptyRowIterator
14361336

@@ -1455,102 +1355,6 @@ def test_result_w_empty_schema(self):
14551355
self.assertEqual(result.location, "asia-northeast1")
14561356
self.assertEqual(result.query_id, "xyz-abc")
14571357

1458-
def test_result_w_timeout_doesnt_raise(self, global_time_lock):
1459-
import google.cloud.bigquery.client
1460-
1461-
begun_resource = self._make_resource()
1462-
query_resource = {
1463-
"jobComplete": True,
1464-
"jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID},
1465-
"schema": {"fields": [{"name": "col1", "type": "STRING"}]},
1466-
}
1467-
done_resource = copy.deepcopy(begun_resource)
1468-
done_resource["status"] = {"state": "DONE"}
1469-
connection = make_connection(begun_resource, query_resource, done_resource)
1470-
client = _make_client(project=self.PROJECT, connection=connection)
1471-
job = self._make_one(self.JOB_ID, self.QUERY, client)
1472-
job._properties["jobReference"]["location"] = "US"
1473-
job._properties["status"] = {"state": "RUNNING"}
1474-
1475-
with freezegun.freeze_time("1970-01-01 00:00:00", tick=False):
1476-
job.result(
1477-
# Test that fractional seconds are supported, but use a timeout
1478-
# that is representable as a floating point without rounding
1479-
# errors since it can be represented exactly in base 2. In this
1480-
# case 1.125 is 9 / 8, which is a fraction with a power of 2 in
1481-
# the denominator.
1482-
timeout=1.125,
1483-
)
1484-
1485-
reload_call = mock.call(
1486-
method="GET",
1487-
path=f"/projects/{self.PROJECT}/jobs/{self.JOB_ID}",
1488-
query_params={"projection": "full", "location": "US"},
1489-
timeout=1.125,
1490-
)
1491-
get_query_results_call = mock.call(
1492-
method="GET",
1493-
path=f"/projects/{self.PROJECT}/queries/{self.JOB_ID}",
1494-
query_params={
1495-
"maxResults": 0,
1496-
"location": "US",
1497-
},
1498-
timeout=google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT,
1499-
)
1500-
connection.api_request.assert_has_calls(
1501-
[
1502-
reload_call,
1503-
get_query_results_call,
1504-
reload_call,
1505-
]
1506-
)
1507-
1508-
def test_result_w_timeout_raises_concurrent_futures_timeout(self, global_time_lock):
1509-
import google.cloud.bigquery.client
1510-
1511-
begun_resource = self._make_resource()
1512-
begun_resource["jobReference"]["location"] = "US"
1513-
query_resource = {
1514-
"jobComplete": True,
1515-
"jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID},
1516-
"schema": {"fields": [{"name": "col1", "type": "STRING"}]},
1517-
}
1518-
done_resource = copy.deepcopy(begun_resource)
1519-
done_resource["status"] = {"state": "DONE"}
1520-
connection = make_connection(begun_resource, query_resource, done_resource)
1521-
client = _make_client(project=self.PROJECT, connection=connection)
1522-
job = self._make_one(self.JOB_ID, self.QUERY, client)
1523-
job._properties["jobReference"]["location"] = "US"
1524-
job._properties["status"] = {"state": "RUNNING"}
1525-
1526-
with freezegun.freeze_time(
1527-
"1970-01-01 00:00:00", auto_tick_seconds=1.0
1528-
), self.assertRaises(concurrent.futures.TimeoutError):
1529-
job.result(timeout=1.125)
1530-
1531-
reload_call = mock.call(
1532-
method="GET",
1533-
path=f"/projects/{self.PROJECT}/jobs/{self.JOB_ID}",
1534-
query_params={"projection": "full", "location": "US"},
1535-
timeout=1.125,
1536-
)
1537-
get_query_results_call = mock.call(
1538-
method="GET",
1539-
path=f"/projects/{self.PROJECT}/queries/{self.JOB_ID}",
1540-
query_params={
1541-
"maxResults": 0,
1542-
"location": "US",
1543-
},
1544-
timeout=google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT,
1545-
)
1546-
connection.api_request.assert_has_calls(
1547-
[
1548-
reload_call,
1549-
get_query_results_call,
1550-
# Timeout before we can reload with the final job state.
1551-
]
1552-
)
1553-
15541358
def test_result_w_page_size(self):
15551359
# Arrange
15561360
query_results_resource = {

0 commit comments

Comments
 (0)