86 lines
1.9 KiB
Markdown
86 lines
1.9 KiB
Markdown
# Quick Start - Running Tests
|
|
|
|
## 1. Install Test Dependencies
|
|
|
|
```bash
|
|
# Add pytest and related tools
|
|
uv add --dev pytest pytest-cov pytest-mock
|
|
```
|
|
|
|
## 2. Run the Tests
|
|
|
|
```bash
|
|
# Run all unit tests (fast, no API calls)
|
|
uv run pytest
|
|
|
|
# Run with more detail
|
|
uv run pytest -v
|
|
|
|
# Run just the COSING tests
|
|
uv run pytest tests/test_cosing_service.py
|
|
|
|
# Run integration tests (will hit real COSING API)
|
|
uv run pytest -m integration
|
|
```
|
|
|
|
## 3. See Coverage
|
|
|
|
```bash
|
|
# Generate HTML coverage report
|
|
uv run pytest --cov=src/pif_compiler --cov-report=html
|
|
|
|
# Open htmlcov/index.html in your browser
|
|
```
|
|
|
|
## What the Tests Cover
|
|
|
|
### ✅ `parse_cas_numbers()`
|
|
- Parses single CAS: `["7732-18-5"]` → `["7732-18-5"]`
|
|
- Parses multiple: `["7732-18-5/56-81-5"]` → `["7732-18-5", "56-81-5"]`
|
|
- Handles separators: `/`, `;`, `,`, `--`
|
|
- Removes parentheses: `["7732-18-5 (hydrate)"]` → `["7732-18-5"]`
|
|
- Cleans whitespace and invalid dashes
|
|
|
|
### ✅ `cosing_search()`
|
|
- Mocks API calls (no internet needed for unit tests)
|
|
- Tests search by name, CAS, EC, ID
|
|
- Tests error handling
|
|
- Integration tests hit real API
|
|
|
|
### ✅ `clean_cosing()`
|
|
- Cleans COSING JSON responses
|
|
- Removes empty tags
|
|
- Parses CAS numbers
|
|
- Creates COSING URLs
|
|
- Renames fields
|
|
|
|
## Test Results Example
|
|
|
|
```
|
|
tests/test_cosing_service.py::TestParseCasNumbers::test_single_cas_number PASSED
|
|
tests/test_cosing_service.py::TestParseCasNumbers::test_multiple_cas_with_slash PASSED
|
|
tests/test_cosing_service.py::TestCosingSearch::test_search_by_name_success PASSED
|
|
...
|
|
================================ 25 passed in 0.5s ================================
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Import errors
|
|
Make sure you're in the project root:
|
|
```bash
|
|
cd c:\Users\adish\Projects\pif_compiler
|
|
uv run pytest
|
|
```
|
|
|
|
### Mock not found
|
|
Install pytest-mock:
|
|
```bash
|
|
uv add --dev pytest-mock
|
|
```
|
|
|
|
### Integration tests failing
|
|
These hit the real API and need internet. Skip them:
|
|
```bash
|
|
uv run pytest -m "not integration"
|
|
```
|