22
33Starts a local BQ server using the targeted configuration.
44"""
5+
56from pathlib import Path
67from typing import List , Optional
78
@@ -17,15 +18,20 @@ def __init__(
1718 project_id : str ,
1819 port : int ,
1920 grpc_port : int ,
21+ database_file_path : Path ,
2022 data_from_yaml : Optional [str ] = None ,
2123 loglevel : Optional [str ] = None ,
2224 ) -> None :
2325 """Start up local BQ.
2426
2527 Args:
2628 executable: executable to call.
27- host: host address fixture will be started on.
28- port: port fixture will listen on.
29+ project_id: google project ID to start local emulator with
30+ port: api port fixture will listen on.
31+ grpc_port: port storage api fixture will listen on.
32+
33+ Kwargs:
34+ database_file_path: bigquery-emulator config file path.
2935 loglevel: log level passed to `fake-BQ-server` binary.
3036
3137 Returns:
@@ -39,6 +45,8 @@ def __init__(
3945 str (port ),
4046 "--grpc-port" ,
4147 str (grpc_port ),
48+ "--database" ,
49+ str (database_file_path ),
4250 ]
4351
4452 if loglevel :
@@ -49,12 +57,17 @@ def __init__(
4957 command .extend (["--data-from-yaml" , data_from_yaml ])
5058
5159 self ._project_id = project_id
60+ self ._port = port
61+ self ._grpc_port = grpc_port
5262 self ._starting_command = command
5363 self .executable = executable
5464
5565 super ().__init__ (
5666 # TODO: Figure out why this returns a 500?
57- command , url = f"http://localhost:{ port } /bigquery/v2/projects" , timeout = 5 , status = "500"
67+ command ,
68+ url = f"http://localhost:{ port } /bigquery/v2/projects" ,
69+ timeout = 5 ,
70+ status = "500" ,
5871 )
5972
6073 def start (self ) -> "BQExecutor" :
@@ -64,5 +77,15 @@ def start(self) -> "BQExecutor":
6477
6578 @property
6679 def project_id (self ) -> str :
67- """Return the configured project_id the emulator is running under."""
80+ """Configured project_id the emulator is running under."""
6881 return self ._project_id
82+
83+ @property
84+ def bq_api_port (self ) -> int :
85+ """Configured port the bigquery api emulator is running on."""
86+ return self ._port
87+
88+ @property
89+ def storage_api_port (self ) -> int :
90+ """Configured port the storage api is running under."""
91+ return self ._grpc_port
0 commit comments