16
16
# See the License for the specific language governing permissions and
17
17
# limitations under the License.
18
18
19
+ import json
19
20
import os
21
+ import re
20
22
21
23
import pytest
22
24
from ai .chronon .repo .compile import extract_and_convert
@@ -53,6 +55,17 @@ def _assert_file_exists(full_file_path, message):
53
55
assert os .path .isfile (full_file_path ), message
54
56
55
57
58
+ def _extract_display_output_json_block (output , block_name ):
59
+ """Extract a JSON block from the output of a CLI command."""
60
+
61
+ field_index = output .find (block_name )
62
+ subset = output [field_index :]
63
+ start_index = subset .find ("json.start" )
64
+ end_index = subset .find ("json.end" )
65
+ s = re .sub (r"\x1b\[[0-9;]*m" , "" , subset [start_index + 10 : end_index ].strip ())
66
+ return json .loads (s )
67
+
68
+
56
69
@pytest .fixture
57
70
def specific_setup ():
58
71
# This setup code will only run for tests that request this fixture
@@ -281,6 +294,18 @@ def test_compile_table_display():
281
294
result = _invoke_cli_with_params (runner , input_path , ["--table-display" ])
282
295
283
296
assert "Output Join Tables" in result .output
297
+ output_json_dict = _extract_display_output_json_block (result .output , "Output Join Tables" )
298
+ expected_json_dict = {
299
+ "backfill" : ["chronon_db.sample_team_sample_join_with_derivations_on_external_parts_v1" ],
300
+ "stats-summary" : ["chronon_db.sample_team_sample_join_with_derivations_on_external_parts_v1_daily_stats" ],
301
+ "log-flattener" : ["chronon_db.sample_team_sample_join_with_derivations_on_external_parts_v1_logged" ],
302
+ "bootstrap" : ["chronon_db.sample_team_sample_join_with_derivations_on_external_parts_v1_bootstrap" ],
303
+ "join_parts" : [
304
+ "sample_team_sample_join_with_derivations_on_external_parts_v1_sample_team_event_sample_group_by_v1" ,
305
+ "sample_team_sample_join_with_derivations_on_external_parts_v1_sample_team_entity_sample_group_by_from_module_v1" ,
306
+ ],
307
+ }
308
+ assert json .dumps (output_json_dict , sort_keys = True ) == json .dumps (expected_json_dict , sort_keys = True )
284
309
assert result .exit_code == 0
285
310
286
311
@@ -307,6 +332,28 @@ def test_compile_feature_display():
307
332
assert result .exit_code == 0
308
333
309
334
335
+ def test_table_display_staging_query ():
336
+ """
337
+ Test a staging query compile produces related table
338
+ """
339
+ runner = CliRunner ()
340
+ input_path = f"staging_queries/sample_team/sample_staging_query.py"
341
+ result = runner .invoke (
342
+ extract_and_convert ,
343
+ [
344
+ "--chronon_root=test/sample" ,
345
+ f"--input_path={ input_path } " ,
346
+ "--table-display" ,
347
+ ],
348
+ )
349
+
350
+ assert "Output StagingQuery Tables" in result .output
351
+ output_json_dict = _extract_display_output_json_block (result .output , "Output StagingQuery Tables" )
352
+ expected_json_dict = {"backfill" : ["sample_namespace.sample_team_sample_staging_query_v1" ]}
353
+ assert json .dumps (output_json_dict , sort_keys = True ) == json .dumps (expected_json_dict , sort_keys = True )
354
+ assert result .exit_code == 0
355
+
356
+
310
357
def test_compile_dependency_staging_query ():
311
358
"""
312
359
Test that compiling a staging query does not error out
0 commit comments