Skip to content

Commit ca748cc

Browse files
committed
Increase preview results to 10 in NeuronsPartHere query and add comprehensive test suite for query functionality
1 parent 25d81a9 commit ca748cc

3 files changed

Lines changed: 205 additions & 85 deletions

File tree

src/test/test_neurons_part_here.py

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import unittest
2+
import sys
3+
import os
4+
5+
# Add src to path for imports
6+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
7+
8+
from vfbquery.vfb_queries import get_neurons_with_part_in, get_term_info
9+
10+
11+
class NeuronsPartHereTest(unittest.TestCase):
12+
"""Test suite for NeuronsPartHere query implementation"""
13+
14+
def setUp(self):
15+
"""Set up test fixtures"""
16+
self.medulla_id = 'FBbt_00003748'
17+
# Expected count based on VFB data (as of test creation)
18+
# Allowing tolerance for data updates
19+
self.expected_count = 471
20+
self.count_tolerance = 5 # Allow ±5 for data updates
21+
22+
def test_neurons_part_here_returns_results(self):
23+
"""Test that NeuronsPartHere query returns results for medulla"""
24+
print("\n" + "=" * 80)
25+
print("Testing NeuronsPartHere query - Basic functionality")
26+
print("=" * 80)
27+
28+
results_df = get_neurons_with_part_in(
29+
self.medulla_id,
30+
return_dataframe=True,
31+
limit=-1
32+
)
33+
34+
self.assertIsNotNone(results_df, "Results should not be None")
35+
self.assertGreater(len(results_df), 0, "Should return at least one result")
36+
37+
print(f"✓ Query returned {len(results_df)} neuron classes")
38+
39+
def test_neurons_part_here_result_count(self):
40+
"""Test that NeuronsPartHere returns expected number of results for medulla"""
41+
print("\n" + "=" * 80)
42+
print(f"Testing NeuronsPartHere result count (expected ~{self.expected_count})")
43+
print("=" * 80)
44+
45+
results_df = get_neurons_with_part_in(
46+
self.medulla_id,
47+
return_dataframe=True,
48+
limit=-1
49+
)
50+
51+
actual_count = len(results_df)
52+
count_diff = abs(actual_count - self.expected_count)
53+
54+
print(f"Expected: {self.expected_count} results")
55+
print(f"Actual: {actual_count} results")
56+
print(f"Difference: {count_diff}")
57+
58+
# Allow some tolerance for data updates
59+
self.assertLessEqual(
60+
count_diff,
61+
self.count_tolerance,
62+
f"Result count {actual_count} differs from expected {self.expected_count} by more than {self.count_tolerance}"
63+
)
64+
65+
if count_diff > 0:
66+
print(f"⚠ Count differs by {count_diff} (within tolerance of {self.count_tolerance})")
67+
else:
68+
print(f"✓ Exact count match: {actual_count}")
69+
70+
def test_neurons_part_here_result_structure(self):
71+
"""Test that results have the expected structure with required columns"""
72+
print("\n" + "=" * 80)
73+
print("Testing NeuronsPartHere result structure")
74+
print("=" * 80)
75+
76+
results_df = get_neurons_with_part_in(
77+
self.medulla_id,
78+
return_dataframe=True,
79+
limit=5
80+
)
81+
82+
# Check required columns
83+
required_columns = ['id', 'label', 'tags', 'thumbnail']
84+
for col in required_columns:
85+
self.assertIn(col, results_df.columns, f"Column '{col}' should be present")
86+
87+
print(f"✓ All required columns present: {', '.join(required_columns)}")
88+
89+
# Check that we have data in the columns
90+
first_row = results_df.iloc[0]
91+
self.assertIsNotNone(first_row['id'], "ID should not be None")
92+
self.assertIsNotNone(first_row['label'], "Label should not be None")
93+
94+
print(f"✓ Sample result: {first_row['label']}")
95+
96+
def test_neurons_part_here_has_examples(self):
97+
"""Test that neuron class results include example images (thumbnails)"""
98+
print("\n" + "=" * 80)
99+
print("Testing NeuronsPartHere includes example images")
100+
print("=" * 80)
101+
102+
results_df = get_neurons_with_part_in(
103+
self.medulla_id,
104+
return_dataframe=True,
105+
limit=10
106+
)
107+
108+
# Count how many results have thumbnails
109+
has_thumbnails = results_df['thumbnail'].notna().sum()
110+
total_results = len(results_df)
111+
112+
print(f"Results with thumbnails: {has_thumbnails}/{total_results}")
113+
114+
# At least some results should have thumbnails (example instances)
115+
self.assertGreater(
116+
has_thumbnails,
117+
0,
118+
"At least some neuron classes should have example images"
119+
)
120+
121+
# Show example thumbnails
122+
sample_with_thumbnail = results_df[results_df['thumbnail'].notna()].iloc[0]
123+
print(f"\n✓ Example with thumbnail:")
124+
print(f" {sample_with_thumbnail['label']}")
125+
print(f" Thumbnail: {sample_with_thumbnail['thumbnail'][:100]}...")
126+
127+
def test_neurons_part_here_preview_in_term_info(self):
128+
"""Test that NeuronsPartHere query appears with preview results in term_info"""
129+
print("\n" + "=" * 80)
130+
print("Testing NeuronsPartHere preview results in term_info")
131+
print("=" * 80)
132+
133+
term_info = get_term_info(self.medulla_id, preview=True)
134+
135+
self.assertIsNotNone(term_info, "term_info should not be None")
136+
self.assertIn('Queries', term_info, "term_info should have Queries")
137+
138+
# Find NeuronsPartHere query
139+
neurons_part_here_query = None
140+
for query in term_info.get('Queries', []):
141+
if query.get('query') == 'NeuronsPartHere':
142+
neurons_part_here_query = query
143+
break
144+
145+
self.assertIsNotNone(
146+
neurons_part_here_query,
147+
"NeuronsPartHere query should be present in term_info"
148+
)
149+
150+
print(f"✓ NeuronsPartHere query found")
151+
print(f" Label: {neurons_part_here_query.get('label', 'Unknown')}")
152+
print(f" Preview limit: {neurons_part_here_query.get('preview', 0)}")
153+
154+
# Check preview results
155+
preview_results = neurons_part_here_query.get('preview_results', {})
156+
preview_rows = preview_results.get('rows', [])
157+
158+
self.assertGreater(
159+
len(preview_rows),
160+
0,
161+
"Preview results should be populated"
162+
)
163+
164+
print(f" Preview results: {len(preview_rows)} items")
165+
166+
# Check that preview results include thumbnails
167+
with_thumbnails = sum(1 for row in preview_rows if row.get('thumbnail', ''))
168+
print(f" Results with example images: {with_thumbnails}/{len(preview_rows)}")
169+
170+
self.assertGreater(
171+
with_thumbnails,
172+
0,
173+
"At least some preview results should have example images"
174+
)
175+
176+
print(f"\n✓ Preview includes example images")
177+
178+
def test_neurons_part_here_limit_parameter(self):
179+
"""Test that the limit parameter works correctly"""
180+
print("\n" + "=" * 80)
181+
print("Testing NeuronsPartHere limit parameter")
182+
print("=" * 80)
183+
184+
limit = 10
185+
results_df = get_neurons_with_part_in(
186+
self.medulla_id,
187+
return_dataframe=True,
188+
limit=limit
189+
)
190+
191+
actual_count = len(results_df)
192+
193+
self.assertLessEqual(
194+
actual_count,
195+
limit,
196+
f"Result count {actual_count} should not exceed limit {limit}"
197+
)
198+
199+
print(f"✓ Limit parameter working: requested {limit}, got {actual_count}")
200+
201+
202+
if __name__ == '__main__':
203+
# Run tests with verbose output
204+
unittest.main(verbosity=2)

src/vfbquery/vfb_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def NeuronsPartHere_to_schema(name, take_default):
852852
"short_form": {"$and": ["Class", "Anatomy"]},
853853
"default": take_default,
854854
}
855-
preview = 5
855+
preview = 10 # Show 10 preview results with example images
856856
preview_columns = ["id", "label", "tags", "thumbnail"]
857857

858858
return Query(query=query, label=label, function=function, takes=takes, preview=preview, preview_columns=preview_columns)

test_neurons_part_here.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)