-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_explorer.py
More file actions
123 lines (102 loc) · 3.98 KB
/
test_explorer.py
File metadata and controls
123 lines (102 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
"""
Test script to verify basic functionality of the Dataset Explorer
"""
import sys
import pandas as pd
import numpy as np
from dataset_explorer import DatasetExplorer
from PyQt5.QtWidgets import QApplication
from PyQt5.QtTest import QTest
from PyQt5.QtCore import Qt
def test_dataset_loading():
"""Test loading and basic operations"""
print("Testing dataset loading and basic operations...")
# Create a test application
app = QApplication(sys.argv)
explorer = DatasetExplorer()
# Load sample data directly
try:
explorer.dataset = pd.read_csv('sample_data.csv')
explorer.filtered_dataset = explorer.dataset.copy()
explorer.update_column_combos()
explorer.update_preview()
explorer.update_statistics()
print("✓ Dataset loaded successfully")
print(f" - Rows: {len(explorer.dataset)}")
print(f" - Columns: {len(explorer.dataset.columns)}")
except Exception as e:
print(f"✗ Failed to load dataset: {e}")
return False
# Test statistics calculation
try:
stats_text = explorer.stats_text.toPlainText()
assert len(stats_text) > 0, "Statistics text is empty"
print("✓ Statistics calculated successfully")
except Exception as e:
print(f"✗ Failed to calculate statistics: {e}")
return False
# Test filtering
try:
original_count = len(explorer.filtered_dataset)
explorer.column_combo.setCurrentText('Department')
explorer.operator_combo.setCurrentText('==')
explorer.filter_value.setText('Engineering')
explorer.apply_filter()
filtered_count = len(explorer.filtered_dataset)
assert filtered_count < original_count, "Filter did not reduce dataset size"
print(f"✓ Filtering works (reduced from {original_count} to {filtered_count} rows)")
# Reset filter
explorer.reset_filter()
assert len(explorer.filtered_dataset) == original_count, "Reset filter failed"
print("✓ Reset filter works")
except Exception as e:
print(f"✗ Failed filtering test: {e}")
return False
# Test column combo boxes
try:
assert explorer.column_combo.count() > 0, "Column combo is empty"
assert explorer.x_column_combo.count() > 0, "X column combo is empty"
assert explorer.y_column_combo.count() > 0, "Y column combo is empty"
print("✓ Column combo boxes populated")
except Exception as e:
print(f"✗ Failed column combo test: {e}")
return False
print("\n✓ All tests passed!")
app.quit()
return True
def test_data_types():
"""Test that the sample data has correct types"""
print("\nTesting data types in sample dataset...")
try:
df = pd.read_csv('sample_data.csv')
# Check for numeric columns
numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
print(f"✓ Numeric columns: {numeric_cols}")
# Check for categorical columns
cat_cols = df.select_dtypes(include=['object']).columns.tolist()
print(f"✓ Categorical columns: {cat_cols}")
# Verify expected columns exist
expected_cols = ['Name', 'Age', 'Gender', 'Salary', 'Department', 'Experience']
for col in expected_cols:
assert col in df.columns, f"Expected column {col} not found"
print(f"✓ All expected columns present")
return True
except Exception as e:
print(f"✗ Data type test failed: {e}")
return False
if __name__ == '__main__':
success = True
# Run tests
success = test_data_types() and success
success = test_dataset_loading() and success
if success:
print("\n" + "="*50)
print("ALL TESTS PASSED!")
print("="*50)
sys.exit(0)
else:
print("\n" + "="*50)
print("SOME TESTS FAILED!")
print("="*50)
sys.exit(1)