Skip to content

Commit 4999faa

Browse files
committed
add reasonable tests
1 parent aae033c commit 4999faa

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

duckdb/query_graph/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ def translate_json_to_html(input_file: str = None, input_text: str = None, outpu
495495
else:
496496
print("please provide either input file or input text")
497497
exit(1)
498-
499498
html_output = generate_style_html(text, True)
500499
highlight_metric_grid = generate_metric_grid_html(text)
501500
timing_table = generate_timing_html(text, query_timings)

tests/fast/test_profiler.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import pytest
2+
import json
23
import duckdb
4+
from duckdb.query_graph import translate_json_to_html
5+
6+
@pytest.fixture(scope="session")
7+
def profiling_connection():
8+
con = duckdb.connect()
9+
con.enable_profiling()
10+
con.execute("SELECT 42;").fetchall()
11+
yield con
12+
con.close()
313

414
class TestProfiler:
5-
def test_profiler_matches_expected_format(self):
6-
con = duckdb.connect()
7-
con.enable_profiling()
8-
con.execute("from range(100_000);")
9-
10-
# Test JSON format
11-
profiling_info_json = con.get_profiling_information(format="json")
15+
def test_profiler_matches_expected_format(self, profiling_connection, tmp_path_factory):
16+
# Test String returned
17+
profiling_info_json = profiling_connection.get_profiling_information(format="json")
1218
assert isinstance(profiling_info_json, str)
13-
print(profiling_info_json)
1419

15-
# Test Text format
16-
profiling_info_text = con.get_profiling_information(format="query_tree_optimizer")
17-
assert isinstance(profiling_info_text, str)
18-
print(profiling_info_text) # Print to visually inspect the text format
20+
# Test expected metrics are there and profiling is json loadable
21+
profiling_dict = json.loads(profiling_info_json)
22+
expected_keys = {'query_name', 'total_bytes_written', 'total_bytes_read', 'system_peak_temp_dir_size', 'system_peak_buffer_memory', 'rows_returned', 'result_set_size', 'latency', 'cumulative_rows_scanned', 'cumulative_cardinality', 'cpu_time', 'extra_info', 'blocked_thread_time', 'children'}
23+
assert profiling_dict.keys() == expected_keys
24+
25+
def test_profiler_html_output(self, profiling_connection, tmp_path_factory):
26+
tmp_dir = tmp_path_factory.mktemp("profiler", numbered=True)
27+
profiling_info_json = profiling_connection.get_profiling_information(format="json")
28+
# Test HTML execution works, nothing to assert!
29+
translate_json_to_html(input_text = profiling_info_json, output_file = f"{tmp_dir}/profiler_output.html")

0 commit comments

Comments
 (0)