feat: add unit tests and integration tests
Context
This MR implements comprehensive unit and integration testing for the aidge_export_tensorrt
module. The test suite provides complete coverage of export functionality, file generation, and plugin registry operations to ensure code reliability and maintainability.
Modified files
-
test_export.py
(18 tests) - Unit tests for main export functionality -
test_file_generation.py
(9 tests) - Unit tests for file and plugin generation -
test_plugin_registry.py
(6 tests) - Unit tests for plugin registry operations -
test_integration.py
(8 tests) - Integration tests for end-to-end functionality
Total: 41 tests covering all module functionality
Detailed major modifications
Test Architecture & Coverage
Export Functionality (18 tests)
-
Input Validation: GraphView/string type detection, ONNX extension validation with
endswith
checks -
File Operations: Directory creation with
os.makedirs
, file copying viashutil.copy
, renaming tomodel.onnx
-
TensorRT Integration: Version-specific static file copying (default: 10.10) with
shutil.copytree
-
PyBind11 Integration: Git cloning with
subprocess.run
management and error handling -
Error Handling: Invalid inputs, missing files,
CalledProcessError
andFileNotFoundError
scenarios
File Generation (9 tests)
- Template Rendering: Jinja2 template processing with variable substitution and nested directory support
-
Directory Structure: Multi-level directory creation for plugins using
os.makedirs
-
Plugin Generation:
.hpp
and.cu
file creation inplugins/pluginname/
structure - Error Handling: Template validation and file system error simulation
Plugin Registry (6 tests)
-
Registration System: Single/multiple plugin decorators with
@plugin_registry.register
- Key Management: Multiple aliases for same plugin using list-based key registration
- Functionality Preservation: Decorated function callability maintained after registration
Integration Tests (8 tests)
- End-to-End Workflow: Complete export with ONNX files and GraphView objects
- Real-World Scenarios: Concurrent operations with thread safety, large file handling (1MB+)
- Error Integration: File not found, invalid inputs in full context with proper cleanup
- Version Handling: Different TensorRT version support (8.6, 10.10) with static file management
Test Environment & Mocking Strategy
Isolation & Cleanup
-
Temporary Directories:
tempfile.mkdtemp()
for isolated testing environment -
Automatic Cleanup:
shutil.rmtree()
intearDown()
methods - State Restoration: Original module state restored after each test
Mocking Architecture
Component | Mock Target | Purpose |
---|---|---|
External Dependencies |
aidge_core , aidge_onnx
|
Isolate unit under test from external modules |
File Operations |
shutil.copy , shutil.copytree , os.rename
|
Control file system behavior without actual I/O |
System Calls | subprocess.run |
Avoid actual git operations during testing |
Error Conditions | File not found scenarios | Test error handling paths and edge cases |
Merge request reports
Activity
Hey @cmoineau—could you review this MR and let me know if you have any suggestions?
Can you add a
.gitlab-ci.yml
file at the root fo the project that looks like:############################################################################### # Aidge Continuous Integration and Deployment # # # ############################################################################### stages: - static_analysis - build - test - coverage - release - deploy include: - project: 'eclipse/aidge/gitlab_shared_files' ref: 'main' file: - '.gitlab/ci/ubuntu_python.gitlab-ci.yml' - '.gitlab/ci/release/pip.gitlab-ci.yml'
I enabled the CI/CD for this repository
Once it is done let me know so that I can run the pipeline (you don't have the authorisations yet ;))The MR is ready for CI/CD pipeline @cmoineau
Nice all test pass and the code coverage looks good:
Name Stmts Miss Cover ---------------------------------------- __init__.py 38 0 100% generate_plugin.py 12 5 58% operators.py 12 0 100% ---------------------------------------- TOTAL 62 5 92%
I am going to approve and merge this MR :)
Edited by Cyril Moineau
assigned to @mmarchal
requested review from @cmoineau
added Unit-test 🧪 label