Skip to content

Commit 18cb333

Browse files
authored
[IBVS]Adding unit test for ibvs featurematching (#812)
1 parent b9df457 commit 18cb333

File tree

7 files changed

+2117
-4
lines changed

7 files changed

+2117
-4
lines changed

metro-ai-suite/image-based-video-search/src/feature-matching/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from PIL import Image
2020
from pymilvus import Collection, CollectionSchema, DataType, FieldSchema
2121

22-
from encoder import Base64ImageProcessor
23-
from milvus_utils import (
22+
from .encoder import Base64ImageProcessor
23+
from .milvus_utils import (
2424
CollectionExists,
2525
create_collection,
2626
get_milvus_client,
2727
get_search_results,
2828
)
29-
from schemas import PayloadSchema, TensorSchema
29+
from .schemas import PayloadSchema, TensorSchema
3030

3131
load_dotenv()
3232

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Quick Test Reference Guide
2+
3+
## 🚀 Running Tests
4+
5+
### Setup (First Time Only)
6+
```bash
7+
# Navigate to project directory
8+
cd /edge-ai-suites/metro-ai-suite/image-based-video-search
9+
10+
# Create and activate virtual environment
11+
python3 -m venv ./test-venv
12+
13+
source test-venv/bin/activate
14+
```
15+
### Install Requirements
16+
```bash
17+
pip install -r ./test/requirements.txt
18+
```
19+
20+
### Run All Tests with Coverage
21+
```bash
22+
# Note: You must temporarily modify server.py imports before running tests
23+
# See "Important Notes" section below
24+
25+
# Run all tests with coverage
26+
pytest test/ --cov=src/feature-matching --cov-report=term-missing
27+
28+
# Run all tests with HTML coverage report
29+
pytest test/ --cov=src/feature-matching --cov-report=html
30+
```
31+
32+
### Run Individual Test Files
33+
```bash
34+
pytest test/test_encoder.py -v
35+
pytest test/test_milvus_utils.py -v
36+
pytest test/test_schemas.py -v
37+
pytest test/test_server.py -v
38+
```
39+
40+
### Run Specific Test
41+
```bash
42+
pytest test/test_encoder.py::TestBase64ImageProcessor::test_processor_initialization_default_size -v
43+
```
44+
45+
## 📊 Current Test Results
46+
47+
- **Total Tests:** 92
48+
- **Passing:** 88 (95.7%)
49+
- **Failing:** 4 (4.3%)
50+
- **Overall Coverage:** 95%
51+
52+
### Coverage by Module
53+
- encoder.py: 100%
54+
- milvus_utils.py: 100%
55+
- schemas.py: 100%
56+
- server.py: 92%
57+
58+
## ⚠️ Important Notes
59+
60+
### Temporary Import Modification Required
61+
62+
Before running tests, you need to temporarily modify `src/feature-matching/server.py`:
63+
64+
**Change FROM (relative imports):**
65+
```python
66+
from .encoder import Base64ImageProcessor
67+
from .milvus_utils import (...)
68+
from .schemas import PayloadSchema, TensorSchema
69+
```
70+
71+
**TO (absolute imports):**
72+
```python
73+
from encoder import Base64ImageProcessor
74+
from milvus_utils import (...)
75+
from schemas import PayloadSchema, TensorSchema
76+
```
77+
78+
**Quick command to make this change:**
79+
```bash
80+
cd src/feature-matching
81+
cp server.py server.py.bak # Backup original
82+
sed -i 's/from \.encoder import/from encoder import/g' server.py
83+
sed -i 's/from \.milvus_utils import/from milvus_utils import/g' server.py
84+
sed -i 's/from \.schemas import/from schemas import/g' server.py
85+
```
86+
87+
**Restore after testing:**
88+
```bash
89+
cd src/feature-matching
90+
mv server.py.bak server.py # Restore original
91+
```
92+
93+
### Why This Is Needed
94+
The `src/feature-matching` directory uses hyphens (not valid in Python module names), so the tests add it to `sys.path` and import directly. The relative imports in `server.py` won't work in this configuration, so we temporarily convert them to absolute imports.
95+
96+
## 📁 Generated Reports
97+
98+
1. **htmlcov/index.html** - Interactive HTML coverage report
99+
100+
### View HTML Report
101+
```bash
102+
# Open in default browser
103+
xdg-open htmlcov/index.html
104+
105+
# Or specify browser
106+
firefox htmlcov/index.html
107+
google-chrome htmlcov/index.html
108+
```
109+
110+
## 🔧 Environment
111+
112+
- Python: 3.12.3
113+
- Pytest: 8.4.2
114+
- Virtual Env: test-venv
115+
- Working Directory: `/edge-ai-suites/metro-ai-suite/image-based-video-search`
116+
117+
## 📚 Additional Resources
118+
119+
- **test/requirements.txt** - All test dependencies
120+
- **test/conftest.py** - Pytest configuration
121+
122+
123+
---
124+
125+
**Last Updated:** November 11, 2025
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
selenium
2-
python-dotenv
2+
python-dotenv
3+
pytest>=7.4.0,<9.0.0
4+
pytest-cov>=4.1.0,<6.0.0
5+
pytest-asyncio>=0.21.0,<1.0.0
6+
pytest-mock>=3.11.0,<4.0.0
7+
fastapi>=0.104.0,<1.0.0
8+
httpx>=0.25.0,<1.0.0
9+
python-multipart>=0.0.6,<1.0.0
10+
uvicorn>=0.24.0,<1.0.0
11+
marshmallow>=3.20.0,<4.0.0
12+
pydantic>=2.0.0,<3.0.0
13+
Pillow>=10.0.0,<12.0.0
14+
pymilvus>=2.3.0,<3.0.0
15+
paho-mqtt>=1.6.0,<3.0.0
16+
python-dotenv>=1.0.0,<2.0.0
17+
numpy>=1.24.0,<3.0.0

0 commit comments

Comments
 (0)