Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Sep 2, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the DNN decompiler project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with Poetry configuration
  • Dependencies: Configured core dependencies (numpy, onnx, capstone)
  • Dev Dependencies: Added pytest, pytest-cov, and pytest-mock for testing
  • Note: angr and patcherex2 dependencies may require system-level installation due to compilation dependencies

Testing Framework

  • Directory Structure: Created tests/ with unit/ and integration/ subdirectories
  • Configuration: Comprehensive pytest configuration in pyproject.toml including:
    • Test discovery patterns
    • Coverage reporting (80% threshold)
    • HTML and XML coverage output
    • Custom markers: unit, integration, slow

Shared Testing Resources

  • Fixtures: Added conftest.py with reusable fixtures:
    • Temporary directories and file handling
    • Mock objects for angr projects and capstone
    • Sample numpy arrays and ONNX models
    • Test configuration dictionaries
    • Memory record mocks and lifted AST samples

Validation & Quality Assurance

  • Validation Tests: Created test_infrastructure_validation.py to verify:
    • Basic pytest functionality
    • Custom markers and fixtures
    • Project structure integrity
    • Coverage reporting functionality
    • Module import capabilities

Development Environment

  • Updated .gitignore: Added comprehensive exclusions for:
    • Python cache files and bytecode
    • Testing artifacts (.pytest_cache, coverage reports)
    • Virtual environments and build artifacts
    • Claude Code settings (.claude/*)
    • IDE and OS generated files

Instructions for Running Tests

Basic Testing

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=src

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m "not slow"    # Exclude slow tests

Coverage Reporting

# Generate HTML coverage report
poetry run pytest --cov=src --cov-report=html

# View coverage report
open htmlcov/index.html

Development Workflow

# Install dependencies
poetry install

# Run validation tests
poetry run pytest tests/test_infrastructure_validation.py -v

Configuration Notes

  • Coverage Threshold: Set to 80% (configurable in pyproject.toml)
  • Test Discovery: Automatically finds test_*.py and *_test.py files
  • Markers: Use @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow
  • Fixtures: Available across all tests via conftest.py

Dependencies

The setup includes essential dependencies for the project:

  • numpy: Numerical computing
  • onnx: ONNX model handling
  • capstone: Disassembly engine
  • pytest ecosystem: Testing framework and plugins

Note: Some dependencies like angr and patcherex2 may need to be installed separately due to system-level compilation requirements.

Testing Infrastructure Features

Package Management: Poetry with proper dependency management
Test Framework: pytest with coverage reporting
Directory Structure: Organized test hierarchy
Shared Fixtures: Reusable test components
Custom Markers: Categorized test execution
Coverage Reports: HTML and XML output formats
Validation Suite: Infrastructure verification tests
Development Tools: Comprehensive gitignore and tooling setup

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Create tests/ directory structure with unit/ and integration/ subdirectories
- Add comprehensive conftest.py with shared fixtures for testing
- Configure coverage reporting with 80% threshold and HTML/XML output
- Add custom pytest markers (unit, integration, slow)
- Update .gitignore with testing and development files
- Create validation tests to verify infrastructure setup
- Support for temp directories, mock objects, and numpy test data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant