Skip to content

Commit 6a719d5

Browse files
authored
Merge pull request #24 from VaitaR/module-logic-separation
Fix UI test timeout issues and event_statistics calculation
2 parents 71985bf + 28c6465 commit 6a719d5

6 files changed

Lines changed: 646 additions & 282 deletions

run_tests.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -961,31 +961,31 @@ def run_fallback_report() -> TestResult:
961961
"file_upload",
962962
["tests/test_file_upload_comprehensive.py"],
963963
"Running comprehensive file upload testing suite",
964-
"file_upload"
964+
"file_upload",
965965
)
966966

967967
NEW_SUITES.add_test(
968-
"error_boundary",
968+
"error_boundary",
969969
["tests/test_error_boundary_comprehensive.py"],
970970
"Running comprehensive error boundary testing suite",
971-
"error_boundary"
971+
"error_boundary",
972972
)
973973

974974
NEW_SUITES.add_test(
975975
"visualization",
976-
["tests/test_visualization_pipeline_comprehensive.py"],
976+
["tests/test_visualization_pipeline_comprehensive.py"],
977977
"Running comprehensive visualization pipeline testing suite",
978-
"visualization"
978+
"visualization",
979979
)
980980

981981
NEW_SUITES.add_test(
982982
"all_new_suites",
983983
[
984984
"tests/test_file_upload_comprehensive.py",
985-
"tests/test_error_boundary_comprehensive.py",
986-
"tests/test_visualization_pipeline_comprehensive.py"
985+
"tests/test_error_boundary_comprehensive.py",
986+
"tests/test_visualization_pipeline_comprehensive.py",
987987
],
988-
"Running all new comprehensive testing suites"
988+
"Running all new comprehensive testing suites",
989989
)
990990

991991
# Update the TEST_CATEGORIES to include process mining, UI tests, and new suites
@@ -1286,7 +1286,9 @@ def main():
12861286
"--process-mining-all", action="store_true", help="Run all process mining tests"
12871287
)
12881288
parser.add_argument("--ui-all", action="store_true", help="Run all UI tests")
1289-
parser.add_argument("--new-suites-all", action="store_true", help="Run all new comprehensive test suites")
1289+
parser.add_argument(
1290+
"--new-suites-all", action="store_true", help="Run all new comprehensive test suites"
1291+
)
12901292

12911293
# Category specific test options
12921294
parser.add_argument(

tests/test_app_ui.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,26 @@ def load_sample_data(self) -> None:
3737
This helper abstracts the data loading flow, making tests immune to
3838
changes in the data loading implementation.
3939
"""
40+
import time
41+
4042
try:
4143
# Click the Load Sample Data button using its stable key with increased timeout
42-
self.at.button(key="load_sample_data_button").click().run(timeout=10)
44+
self.at.button(key="load_sample_data_button").click().run(timeout=15)
45+
46+
# Wait for data loading to complete by checking session state
47+
max_retries = 5
48+
for attempt in range(max_retries):
49+
if (
50+
hasattr(self.at.session_state, "events_data")
51+
and self.at.session_state.events_data is not None
52+
and len(self.at.session_state.events_data) > 0
53+
):
54+
# Data loaded successfully, now wait for event_statistics
55+
break
56+
time.sleep(0.5) # Wait 500ms between retries
57+
if attempt < max_retries - 1: # Don't run on last attempt
58+
self.at.run(timeout=10) # Re-run to refresh state
59+
4360
except Exception as e:
4461
# If button interaction fails, manually load sample data for testing
4562
from datetime import datetime, timedelta
@@ -67,10 +84,52 @@ def load_sample_data(self) -> None:
6784

6885
self.at.session_state.events_data = pd.DataFrame(data)
6986

87+
# CRITICAL FIX: Calculate event_statistics manually when using fallback
88+
# Import the function from app.py
89+
import os
90+
import sys
91+
92+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
93+
from app import get_event_statistics
94+
95+
self.at.session_state.event_statistics = get_event_statistics(
96+
self.at.session_state.events_data
97+
)
98+
7099
# Verify data was loaded by checking session state
71100
assert self.at.session_state.events_data is not None, "Sample data should be loaded"
72101
assert len(self.at.session_state.events_data) > 0, "Sample data should not be empty"
73102

103+
# Wait for event_statistics to be calculated (give it more time)
104+
max_retries = 10
105+
for attempt in range(max_retries):
106+
if (
107+
hasattr(self.at.session_state, "event_statistics")
108+
and len(self.at.session_state.event_statistics) > 0
109+
):
110+
break
111+
time.sleep(0.3) # Wait 300ms between retries
112+
if attempt < max_retries - 1: # Don't run on last attempt
113+
self.at.run(
114+
timeout=10
115+
) # Re-run to refresh state and trigger statistics calculation
116+
117+
# Final verification that event_statistics was calculated
118+
if (
119+
not hasattr(self.at.session_state, "event_statistics")
120+
or len(self.at.session_state.event_statistics) == 0
121+
):
122+
# Last resort: manually calculate if still not present
123+
import os
124+
import sys
125+
126+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
127+
from app import get_event_statistics
128+
129+
self.at.session_state.event_statistics = get_event_statistics(
130+
self.at.session_state.events_data
131+
)
132+
74133
def build_funnel(self, steps: List[str]) -> None:
75134
"""
76135
Build a funnel by selecting the specified steps.

0 commit comments

Comments
 (0)