-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fixes.py
executable file
·148 lines (119 loc) · 5.02 KB
/
test_fixes.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Simple test script to verify our fixes to semantic_linker.py and genai_linker.py
"""
import os
import sys
import semantic_linker
import genai_linker
def test_semantic_linker():
"""Test the semantic_linker.py fixes with a small dataset."""
print("\n===== Testing semantic_linker.py =====")
# Create a small test dataset in different formats
test_notes = {
"note1.md": {
"content": "# Test Note 1\nThis is a test note about artificial intelligence and machine learning.",
"content_for_embedding": "This is a test note about artificial intelligence and machine learning.",
"metadata": {"tags": ["AI", "ML"]}
},
"note2.md": {
"content": "# Test Note 2\nThis note discusses Python programming and data structures.",
"content_for_embedding": "This note discusses Python programming and data structures.",
"metadata": {"tags": ["Python", "Programming"]}
},
"note3.md": "# Test Note 3\nObsidian is a great note-taking tool with many plugins available."
}
print("Created test notes in different formats")
print("Generating embeddings...")
# Test the get_embeddings function with mixed format input
embeddings = semantic_linker.get_embeddings(test_notes)
if embeddings is None:
print("Error: Failed to generate embeddings")
return False
print(f"Successfully generated embeddings with shape: {embeddings.shape}")
# Test cosine similarity matrix calculation
print("Calculating similarity matrix...")
similarity_matrix = semantic_linker.cosine_similarity_matrix(embeddings)
if similarity_matrix is None:
print("Error: Failed to calculate similarity matrix")
return False
print(f"Successfully calculated similarity matrix with shape: {similarity_matrix.shape}")
# Test another scenario - passing list of values instead of dictionary
print("\nTesting with list of values...")
test_contents = list(test_notes.values())
embeddings2 = semantic_linker.get_embeddings(test_contents)
if embeddings2 is None:
print("Error: Failed to generate embeddings from list input")
return False
print(f"Successfully generated embeddings from list input with shape: {embeddings2.shape}")
print("Semantic linker tests passed successfully!")
return True
def test_genai_linker():
"""Test the genai_linker.py fixes with a small dataset."""
print("\n===== Testing genai_linker.py =====")
# Create a small test dataset in different formats
test_notes = {
"note1.md": {
"filename": "note1.md",
"content": "# Test Note 1\nThis is a test note about artificial intelligence and machine learning."
},
"note2.md": {
"filename": "note2.md",
"content": "# Test Note 2\nThis note discusses Python programming and data structures."
},
"note3.md": "# Test Note 3\nObsidian is a great note-taking tool with many plugins available."
}
print("Created test notes in different formats")
print("Extracting titles and summaries...")
# Test the extract_titles_and_summaries function
summaries = genai_linker.extract_titles_and_summaries(test_notes)
if len(summaries) != len(test_notes):
print(f"Error: Expected {len(test_notes)} summaries, got {len(summaries)}")
return False
print(f"Successfully extracted titles and summaries for {len(summaries)} notes")
# Check if titles were extracted correctly
for path, summary in summaries.items():
print(f"Note: {path}, Title: {summary['title']}")
print("GenAI linker tests passed successfully!")
return True
def main():
"""Run all tests."""
successes = 0
failures = 0
# Test semantic_linker.py
try:
if test_semantic_linker():
successes += 1
else:
failures += 1
except Exception as e:
print(f"Error testing semantic_linker.py: {str(e)}")
failures += 1
# Test genai_linker.py
try:
if test_genai_linker():
successes += 1
else:
failures += 1
except Exception as e:
print(f"Error testing genai_linker.py: {str(e)}")
failures += 1
print(f"\nTest summary: {successes} passed, {failures} failed")
if failures == 0:
print("\nAll tests passed! The fixes appear to be working correctly.")
return 0
else:
print("\nSome tests failed. Please check the output for details.")
return 1
if __name__ == "__main__":
# Redirect stdout to a file for easier review
original_stdout = sys.stdout
with open('test_results.txt', 'w') as f:
sys.stdout = f
result = main()
# Reset stdout
sys.stdout = original_stdout
# Print a message to the console
print("Test completed! Results saved to test_results.txt")
sys.exit(result)