-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_noteerr.py
More file actions
167 lines (129 loc) · 4.66 KB
/
test_noteerr.py
File metadata and controls
167 lines (129 loc) · 4.66 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
Test script to verify Noteerr installation and functionality.
Run this after installing: python test_noteerr.py
"""
import os
import sys
import subprocess
def run_command(cmd):
"""Run a command and return success status."""
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
timeout=5
)
return result.returncode == 0, result.stdout, result.stderr
except Exception as e:
return False, "", str(e)
def test_installation():
"""Test if noteerr is installed."""
print("🔍 Testing Noteerr installation...")
success, stdout, stderr = run_command("noteerr --version")
if success:
print("✅ Noteerr is installed correctly!")
print(f" Version: {stdout.strip()}")
return True
else:
print("❌ Noteerr is not installed or not in PATH")
print(f" Error: {stderr}")
return False
def test_basic_commands():
"""Test basic Noteerr commands."""
print("\n🧪 Testing basic commands...\n")
tests = [
("noteerr list", "List command"),
("noteerr stats", "Stats command"),
("noteerr --help", "Help command"),
]
passed = 0
failed = 0
for cmd, description in tests:
print(f"Testing: {description}")
success, stdout, stderr = run_command(cmd)
if success or "No errors logged yet" in stdout or "No errors" in stdout:
print(f" ✅ {description} works!")
passed += 1
else:
print(f" ❌ {description} failed")
print(f" Error: {stderr}")
failed += 1
print(f"\n📊 Results: {passed} passed, {failed} failed")
return failed == 0
def test_save_and_retrieve():
"""Test saving and retrieving an error."""
print("\n🧪 Testing save and retrieve functionality...\n")
# Save a test error
print("1. Saving a test error...")
cmd = 'noteerr save "test error from installation script" --command "test-command" --error "test error message" --tags test,installation'
success, stdout, stderr = run_command(cmd)
if not success:
print(f" ❌ Failed to save error: {stderr}")
return False
print(" ✅ Error saved successfully!")
# List errors
print("2. Listing errors...")
success, stdout, stderr = run_command("noteerr list")
if success and "test-command" in stdout:
print(" ✅ Error appears in list!")
else:
print(" ❌ Error not found in list")
return False
# Search for error
print("3. Searching for error...")
success, stdout, stderr = run_command("noteerr search test")
if success and "test-command" in stdout:
print(" ✅ Error found via search!")
else:
print(" ❌ Search failed")
return False
print("\n✅ All save/retrieve tests passed!")
return True
def check_data_directory():
"""Check if data directory was created."""
print("\n📁 Checking data directory...")
home = os.path.expanduser("~")
data_dir = os.path.join(home, ".noteerr")
data_file = os.path.join(data_dir, "errors.json")
if os.path.exists(data_dir):
print(f" ✅ Data directory exists: {data_dir}")
else:
print(f" ℹ️ Data directory will be created on first use")
if os.path.exists(data_file):
print(f" ✅ Data file exists: {data_file}")
return True
else:
print(f" ℹ️ Data file will be created on first error save")
return True
def main():
"""Run all tests."""
print("=" * 60)
print("🚀 Noteerr Installation Test Script")
print("=" * 60)
# Test installation
if not test_installation():
print("\n❌ Installation test failed. Please install Noteerr first:")
print(" pip install -e .")
sys.exit(1)
# Test basic commands
if not test_basic_commands():
print("\n⚠️ Some basic commands failed")
# Check data directory
check_data_directory()
# Test save and retrieve
test_save_and_retrieve()
print("\n" + "=" * 60)
print("🎉 All tests completed!")
print("=" * 60)
print("\n📚 Next steps:")
print(" 1. Try: noteerr list")
print(" 2. Try: noteerr stats")
print(" 3. Try: noteerr search test")
print(" 4. Read EXAMPLES.md for more usage examples")
print(" 5. Set up shell integration (see README.md)")
print("\n💡 Tip: Run a failing command and immediately type:")
print(" noteerr save \"your note about the fix\"")
if __name__ == "__main__":
main()