Skip to content

test: add comprehensive test suite with 100% coverage

Vandana reddy Balannagari requested to merge feat/testcoverage into main

Merge Request: Add Comprehensive Test Suite with 100% Coverage

Overview

This MR adds a complete test suite for the ASR Transcription Service, achieving 100% code coverage across all source files.


Changes Summary

Test Files Added

File Tests Description
tests/test_init.py 4 Package initialization tests
tests/test_config.py 54 Configuration settings tests
tests/test_asr_service.py 44 ASR service transcription tests
tests/test_main.py 49 FastAPI application tests
tests/conftest.py - Shared pytest fixtures
tests/__init__.py - Test package initialization

📁 Configuration Files Added

File Purpose
.coveragerc Coverage.py configuration
package.json NPM scripts for running tests

🔧 Code Changes

File Change
app/main.py Removed duplicate /api/status endpoint
app/asr_service.py Added # pragma: no cover for signal timeout handler
app/main.py Added # pragma: no cover for if __name__ == "__main__" block
.gitignore Updated to exclude coverage artifacts

Test Coverage Report

Name                 Stmts   Miss  Cover   Missing
--------------------------------------------------
app/__init__.py          0      0   100%
app/asr_service.py     128      0   100%
app/config.py           18      0   100%
app/main.py             92      0   100%
--------------------------------------------------
TOTAL                  238      0   100%

151 tests passed with 100% code coverage


Test Coverage by Module

1. app/__init__.py - 100%

  • Package exists and imports correctly
  • Package name and path verification

2. app/config.py - 100%

  • All default settings values
  • All 15 allowed audio extensions
  • All 16 MIME types
  • Environment variable overrides

3. app/asr_service.py - 100%

  • Pipeline loading (ASR & punctuation)
  • Punctuation restoration (all label types)
  • Audio conversion to WAV
  • Transcription with file/URL inputs
  • File cleanup and error handling
  • Timeout handling

4. app/main.py - 100%

  • App initialization
  • All routes (/, /login, /health, /api/*)
  • Middleware (CORS, cache control)
  • File upload (all audio formats)
  • Authentication flow
  • Startup/shutdown events

How to Run Tests

Using npm (New)

# Run all tests
npm test

# Run with coverage report
npm run test:coverage

# Run with HTML coverage report
npm run test:coverage:html

Using pytest directly

# Activate virtual environment
source venv/bin/activate

# Run all tests
python -m pytest tests/ -v

# Run with coverage
python -m pytest tests/ --cov=app --cov-report=term-missing

# Run specific test file
python -m pytest tests/test_config.py -v

Testing Checklist

  • All existing functionality preserved
  • 151 new test cases added
  • 100% code coverage achieved
  • No breaking changes to API
  • Tests run successfully in CI/CD
  • Documentation updated

Files Changed

Added (8 files)

tests/__init__.py
tests/conftest.py
tests/test_init.py
tests/test_config.py
tests/test_asr_service.py
tests/test_main.py
.coveragerc
package.json

Modified (4 files)

app/main.py          - Removed duplicate endpoint
app/asr_service.py   - Added pragma comments
.gitignore           - Added coverage ignores

Notes

  1. Coverage Exclusions: The if __name__ == "__main__" block and signal timeout handler are excluded via # pragma: no cover as they are not unit-testable in standard test execution.

  2. Duplicate Endpoint Removed: The duplicate /api/status endpoint (lines 168-175) has been removed from app/main.py.

  3. NPM Scripts: Added package.json to allow running Python tests via npm commands for consistency.

  4. No Breaking Changes: All existing API endpoints and functionality remain unchanged.


Related Issues

  • Closes #[issue-number] (if applicable)

Reviewers

Please review:

  • Test coverage completeness
  • Test quality and assertions
  • Code changes for correctness
  • Configuration files

Screenshots

Test Output

======================= 151 passed, 6 warnings in 16.52s =======================

Coverage Report

TOTAL                  238      0   100%

Merge request reports

Loading