-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dialogs): move execution dialogs to separate files
- Loading branch information
Showing
11 changed files
with
266 additions
and
163 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import time | ||
import pandas as pd | ||
import streamlit as st | ||
|
||
import testgen.ui.services.test_suite_service as test_suite_service | ||
from testgen.commands.run_generate_tests import run_test_gen_queries | ||
from testgen.ui.components import widgets as testgen | ||
|
||
ALL_TYPES_LABEL = "All Test Types" | ||
|
||
|
||
@st.dialog(title="Generate Tests") | ||
def generate_tests_dialog(test_suite: pd.Series) -> None: | ||
test_suite_id = test_suite["id"] | ||
test_suite_name = test_suite["test_suite"] | ||
table_group_id = test_suite["table_groups_id"] | ||
|
||
selected_set = "" | ||
generation_sets = test_suite_service.get_generation_set_choices() | ||
|
||
if generation_sets: | ||
generation_sets.insert(0, ALL_TYPES_LABEL) | ||
|
||
with st.container(): | ||
selected_set = st.selectbox("Generation Set", generation_sets) | ||
if selected_set == ALL_TYPES_LABEL: | ||
selected_set = "" | ||
|
||
test_ct, unlocked_test_ct, unlocked_edits_ct = test_suite_service.get_test_suite_refresh_warning(test_suite_id) | ||
if test_ct: | ||
unlocked_message = "" | ||
if unlocked_edits_ct > 0: | ||
unlocked_message = "Manual changes have been made to auto-generated tests in this test suite that have not been locked. " | ||
elif unlocked_test_ct > 0: | ||
unlocked_message = "Auto-generated tests are present in this test suite that have not been locked. " | ||
|
||
warning_message = f""" | ||
{unlocked_message} | ||
Generating tests now will overwrite unlocked tests subject to auto-generation based on the latest profiling. | ||
\n\n_Auto-generated Tests: {test_ct}, Unlocked: {unlocked_test_ct}, Edited Unlocked: {unlocked_edits_ct}_ | ||
""" | ||
|
||
with st.container(): | ||
st.warning(warning_message, icon=":material/warning:") | ||
if unlocked_edits_ct > 0: | ||
if st.button("Lock Edited Tests"): | ||
if test_suite_service.lock_edited_tests(test_suite_id): | ||
st.info("Edited tests have been successfully locked.") | ||
|
||
with st.container(): | ||
st.markdown(f"Execute test generation for the test suite **{test_suite_name}**?") | ||
|
||
if testgen.expander_toggle(expand_label="Show CLI command", key="test_suite:keys:generate-tests-show-cli"): | ||
st.code( | ||
f"testgen run-test-generation --table-group-id {table_group_id} --test-suite-key {test_suite_name}", | ||
language="shellSession", | ||
) | ||
|
||
button_container = st.empty() | ||
status_container = st.empty() | ||
|
||
test_generation_button = None | ||
with button_container: | ||
_, button_column = st.columns([.75, .25]) | ||
with button_column: | ||
test_generation_button = st.button("Generate Tests", use_container_width=True) | ||
|
||
if test_generation_button: | ||
button_container.empty() | ||
status_container.info("Starting test generation ...") | ||
|
||
try: | ||
run_test_gen_queries(table_group_id, test_suite_name, selected_set) | ||
except Exception as e: | ||
status_container.error(f"Test generation encountered errors: {e!s}.") | ||
|
||
status_container.success(f"Test generation completed for test suite **{test_suite_name}**.") | ||
time.sleep(1) | ||
st.cache_data.clear() | ||
st.rerun() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import time | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
import testgen.ui.services.query_service as dq | ||
from testgen.commands.run_profiling_bridge import run_profiling_in_background | ||
from testgen.ui.components import widgets as testgen | ||
from testgen.ui.session import session | ||
|
||
LINK_KEY = "run_profiling_dialog:keys:go-to-runs" | ||
LINK_HREF = "profiling-runs" | ||
|
||
|
||
@st.dialog(title="Run Profiling") | ||
def run_profiling_dialog(project_code: str, table_group: pd.Series | None = None, default_table_group_id: str | None = None) -> None: | ||
if table_group is not None and not table_group.empty: | ||
table_group_id: str = table_group["id"] | ||
table_group_name: str = table_group["table_groups_name"] | ||
else: | ||
table_groups_df = get_table_group_options(project_code) | ||
table_group_id: str = testgen.select( | ||
label="Table Group", | ||
options=table_groups_df, | ||
value_column="id", | ||
display_column="table_groups_name", | ||
default_value=default_table_group_id, | ||
required=True, | ||
) | ||
table_group_name: str = table_groups_df.loc[table_groups_df["id"] == table_group_id, "table_groups_name"].iloc[0] | ||
testgen.whitespace(1) | ||
|
||
with st.container(): | ||
st.markdown(f"Execute profiling for the table group **{table_group_name}**?") | ||
st.markdown(":material/info: _Profiling will be performed in a background process._") | ||
|
||
if testgen.expander_toggle(expand_label="Show CLI command", key="test_suite:keys:run-tests-show-cli"): | ||
st.code(f"testgen run-profile --table-group-id {table_group_id}", language="shellSession") | ||
|
||
button_container = st.empty() | ||
status_container = st.empty() | ||
|
||
with button_container: | ||
_, button_column = st.columns([.85, .15]) | ||
with button_column: | ||
profile_button = st.button("Run Profiling", use_container_width=True, disabled=not table_group_id) | ||
|
||
if profile_button: | ||
button_container.empty() | ||
status_container.info("Starting profiling run ...") | ||
|
||
try: | ||
run_profiling_in_background(table_group_id) | ||
except Exception as e: | ||
status_container.error(f"Profiling run encountered errors: {e!s}.") | ||
|
||
# The second condition is needed for the link to work | ||
if profile_button or st.session_state.get(LINK_KEY): | ||
with status_container.container(): | ||
st.success( | ||
f"Profiling run started for table group **{table_group_name}**." | ||
) | ||
|
||
if session.current_page != LINK_HREF: | ||
testgen.link( | ||
label="Go to Profiling Runs", | ||
href=LINK_HREF, | ||
params={ "table_group": table_group_id }, | ||
right_icon="chevron_right", | ||
underline=False, | ||
height=40, | ||
key=LINK_KEY, | ||
style="margin-left: auto; border-radius: 4px; border: var(--button-stroked-border); padding: 8px 8px 8px 16px; color: var(--primary-color)", | ||
) | ||
else: | ||
time.sleep(1) | ||
st.cache_data.clear() | ||
st.rerun() | ||
|
||
|
||
@st.cache_data(show_spinner=False) | ||
def get_table_group_options(project_code: str) -> pd.DataFrame: | ||
schema: str = st.session_state["dbschema"] | ||
return dq.run_table_groups_lookup_query(schema, project_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import time | ||
import pandas as pd | ||
import streamlit as st | ||
|
||
import testgen.ui.services.database_service as db | ||
from testgen.commands.run_execute_tests import run_execution_steps_in_background | ||
from testgen.ui.components import widgets as testgen | ||
from testgen.ui.session import session | ||
|
||
LINK_KEY = "run_tests_dialog:keys:go-to-runs" | ||
LINK_HREF = "test-runs" | ||
|
||
|
||
@st.dialog(title="Run Tests") | ||
def run_tests_dialog(project_code: str, test_suite: pd.Series | None = None, default_test_suite_id: str | None = None) -> None: | ||
if test_suite is not None and not test_suite.empty: | ||
test_suite_id: str = test_suite["id"] | ||
test_suite_name: str = test_suite["test_suite"] | ||
else: | ||
test_suites_df = get_test_suite_options(project_code) | ||
test_suite_id: str = testgen.select( | ||
label="Test Suite", | ||
options=test_suites_df, | ||
value_column="id", | ||
display_column="test_suite", | ||
default_value=default_test_suite_id, | ||
required=True, | ||
) | ||
test_suite_name: str = test_suites_df.loc[test_suites_df["id"] == test_suite_id, "test_suite"].iloc[0] | ||
testgen.whitespace(1) | ||
|
||
with st.container(): | ||
st.markdown(f"Run tests for the test suite **{test_suite_name}**?") | ||
st.markdown(":material/info: _Test execution will be performed in a background process._") | ||
|
||
if testgen.expander_toggle(expand_label="Show CLI command", key="run_tests_dialog:keys:show-cli"): | ||
st.code( | ||
f"testgen run-tests --project-key {project_code} --test-suite-key {test_suite['test_suite']}", | ||
language="shellSession" | ||
) | ||
|
||
button_container = st.empty() | ||
status_container = st.empty() | ||
|
||
run_test_button = None | ||
with button_container: | ||
_, button_column = st.columns([.8, .2]) | ||
with button_column: | ||
run_test_button = st.button("Run Tests", use_container_width=True) | ||
|
||
if run_test_button: | ||
button_container.empty() | ||
status_container.info("Starting test run ...") | ||
|
||
try: | ||
run_execution_steps_in_background(project_code, test_suite_name) | ||
except Exception as e: | ||
status_container.error(f"Test run encountered errors: {e!s}.") | ||
|
||
# The second condition is needed for the link to work | ||
if run_test_button or st.session_state.get(LINK_KEY): | ||
with status_container.container(): | ||
st.success( | ||
f"Test run started for test suite **{test_suite_name}**." | ||
) | ||
|
||
if session.current_page != LINK_HREF: | ||
testgen.link( | ||
label="Go to Test Runs", | ||
href=LINK_HREF, | ||
params={ "test_suite": test_suite_id }, | ||
right_icon="chevron_right", | ||
underline=False, | ||
height=40, | ||
key=LINK_KEY, | ||
style="margin-left: auto; border-radius: 4px; border: var(--button-stroked-border); padding: 8px 8px 8px 16px; color: var(--primary-color)", | ||
) | ||
else: | ||
time.sleep(1) | ||
st.cache_data.clear() | ||
st.rerun() | ||
|
||
|
||
@st.cache_data(show_spinner=False) | ||
def get_test_suite_options(project_code: str) -> pd.DataFrame: | ||
schema: str = st.session_state["dbschema"] | ||
sql = f""" | ||
SELECT test_suites.id::VARCHAR(50), | ||
test_suites.test_suite | ||
FROM {schema}.test_suites | ||
WHERE test_suites.project_code = '{project_code}' | ||
ORDER BY test_suites.test_suite | ||
""" | ||
return db.retrieve_data(sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.