gpt4 book ai didi

python - 使用 Python 进行 BigQuery 单元测试

转载 作者:行者123 更新时间:2023-12-04 08:38:47 24 4
gpt4 key购买 nike

我正在尝试使用 Mock 对象测试 BigQuery 类来表示表。我的 BigQueryRequest 的实例类必须提供 BigQuery table uri .我可以直接从 Python 创建一个模拟 BigQuery 表吗?怎么可能?

class BigQueryRequest:
"""BigQueryRequest
Contains a BigQuery request with its parameter.
Receive a table uri ($project_id.$dataset.$table) to run query
Args:
uri (str): BigQuery table uri
Properties:
BigQueryRequest.project: return the project running BigQuery
BigQueryRequest.dataset: return the dataset
BigQueryRequest.table: return the table to query
BigQueryRequest.destination_project: same as project but for destination project
BigQueryRequest.destination_dataset: same as project but for destination dataset
BigQueryRequest.destination_table: same as project but for destination table
Methods:
from_uri(): (@classmethod) parse a BigQuery uri to its project, dataset, table
destination(): return a uri of the BigQuery request destination table
query(): run the given BigQuery query
Private methods:
__set_destination(): generate a destination uri following the nomenclature or reuse entry uri
"""

def __init__(self, uri="", step="", params={}):
self.project, self.dataset, self.table = self.from_uri(uri)
self.step = step
self.params = self.set_params(params)
self.overwrite = False
(
self.destination_project,
self.destination_dataset,
self.destination_table,
) = self.__set_destination()

最佳答案

您必须自己动手,Google Cloud 不为 GCP 产品或服务提供官方模拟库。
你也可以试试 https://github.com/Khan/tinyquery作为备选。

关于python - 使用 Python 进行 BigQuery 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64664074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com