File tree Expand file tree Collapse file tree
packages/bigframes/scripts/generate_bigframes_bigquery Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ class BQFunc:
7373class BQModule :
7474 yaml_file : pathlib .Path
7575 functions : list [BQFunc ]
76+ is_global : bool
7677
7778 @property
7879 def module_path (self ):
Original file line number Diff line number Diff line change @@ -75,13 +75,20 @@ def _generate_accesor():
7575
7676
7777def _generate_tests (bq_module : data_models .BQModule ):
78- pass
78+ content = template_renderer .render_tests (bq_module )
79+
80+ output_file = constants .TEST_OUTPUT_DIR .joinpath (
81+ bq_module .module_path .with_name (f"test_{ bq_module .module_path .name } " )
82+ ).with_suffix (".py" )
83+
84+ _write_file (content , output_file , constants .TEST_OUTPUT_DIR .parent )
7985
8086
8187def generate (bq_modules : list [data_models .BQModule ]):
8288
8389 for bq_module in bq_modules :
8490 _generate_op_defs (bq_module )
91+ _generate_tests (bq_module )
8592
8693 # Ruff format
8794 _run_ruff ()
Original file line number Diff line number Diff line change @@ -230,4 +230,18 @@ def render_operation(
230230
231231def render_tests (bq_module : data_models .BQModule ) -> str :
232232
233- pass
233+ import_path = "bigframes.operations.googlesql." + "." .join (
234+ bq_module .module_path .parts
235+ )
236+ functions = []
237+ for bq_func in bq_module .functions :
238+ functions .append (_to_bigframes_func (bq_func ))
239+
240+ return constants .TEMPLATES ["test_operation" ].render (
241+ yaml_path = bq_module .yaml_file .relative_to (constants .PACKAGE_ROOT ),
242+ script_path = constants .SCRIPT_PATH_RELATIVE ,
243+ import_path = import_path ,
244+ short_name = bq_module .module_path .name ,
245+ is_global = bq_module .is_global ,
246+ functions = functions ,
247+ )
Original file line number Diff line number Diff line change @@ -48,11 +48,11 @@ def _parse_func_impl(impl_data: Any) -> data_models.BQFuncImpl:
4848 )
4949
5050
51- def _parse_bq_func (func_data : Any , module_path : pathlib .Path ) -> data_models .BQFunc :
51+ def _parse_bq_func (
52+ func_data : Any , module_name : str , is_global : bool
53+ ) -> data_models .BQFunc :
5254 op_base_name = _to_snake_case (func_data ["name" ])
5355
54- module_name = module_path .name
55- is_global = "global_namespace" in module_path .parts
5656 if not is_global and op_base_name .startswith (module_name + "_" ):
5757 op_base_name = op_base_name [len (module_name ) + 1 :]
5858
@@ -72,13 +72,15 @@ def parse_yaml(yaml_file: pathlib.Path) -> data_models.BQModule:
7272
7373 functions = []
7474 module_path = yaml_file .relative_to (constants .DATA_DIR ).with_suffix ("" )
75+ is_global = "global_namespace" in module_path .parts
7576 if isinstance (data , dict ) and "scalar_functions" in data :
7677 functions = [
77- _parse_bq_func (func_data , module_path )
78+ _parse_bq_func (func_data , module_path . name , is_global )
7879 for func_data in data ["scalar_functions" ]
7980 ]
8081
8182 return data_models .BQModule (
8283 yaml_file = yaml_file ,
8384 functions = functions ,
85+ is_global = is_global ,
8486 )
You can’t perform that action at this time.
0 commit comments