|
| 1 | +# PyCompiler-ARK Tests Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This directory contains comprehensive test suites for the PyCompiler-ARK project. The tests cover compilation functionality, engine management, dependency analysis, and more. |
| 6 | + |
| 7 | +## Test Files |
| 8 | + |
| 9 | +### `test_suite.py` |
| 10 | +Basic pytest suite covering core components without launching the GUI loop. |
| 11 | + |
| 12 | +**Coverage:** |
| 13 | +- Core version and API imports |
| 14 | +- Lazy cache clearing |
| 15 | +- Engine registry registration and creation |
| 16 | +- Base engine functionality |
| 17 | +- Dependency analyzer stdlib detection |
| 18 | +- Main module imports |
| 19 | + |
| 20 | +### `test_compilation.py` |
| 21 | +Comprehensive tests for compilation functionality. |
| 22 | + |
| 23 | +**Coverage:** |
| 24 | +- ARK configuration loading |
| 25 | +- File detection and filtering |
| 26 | +- Compiler command building (PyInstaller and Nuitka) |
| 27 | +- Process management |
| 28 | +- Error handling |
| 29 | +- Compilation workflow integration |
| 30 | +- Configuration options |
| 31 | + |
| 32 | +**Key Test Classes:** |
| 33 | +- `TestArkConfigLoader` - Configuration file handling |
| 34 | +- `TestFileDetection` - Python file detection and filtering |
| 35 | +- `TestCompilerCommandBuilding` - Command generation for compilers |
| 36 | +- `TestProcessManagement` - Process lifecycle management |
| 37 | +- `TestErrorHandling` - Error scenarios and recovery |
| 38 | +- `TestCompilationIntegration` - End-to-end workflows |
| 39 | + |
| 40 | +### `test_engines.py` |
| 41 | +Tests for compilation engines (PyInstaller, Nuitka, cx_Freeze). |
| 42 | + |
| 43 | +**Coverage:** |
| 44 | +- Engine registry and instantiation |
| 45 | +- Command building for each engine |
| 46 | +- Engine-specific options |
| 47 | +- Plugin detection and loading |
| 48 | +- Engine configuration |
| 49 | +- Engine integration and switching |
| 50 | +- Error handling |
| 51 | + |
| 52 | +**Key Test Classes:** |
| 53 | +- `TestEngineRegistry` - Engine registration and lookup |
| 54 | +- `TestBaseEngine` - Base engine functionality |
| 55 | +- `TestPyInstallerEngine` - PyInstaller-specific tests |
| 56 | +- `TestNuitkaEngine` - Nuitka-specific tests |
| 57 | +- `TestCxFreezeEngine` - cx_Freeze-specific tests |
| 58 | +- `TestEnginePlugins` - Plugin detection |
| 59 | +- `TestEngineConfiguration` - Configuration files and language support |
| 60 | + |
| 61 | +### `test_dependencies.py` |
| 62 | +Tests for dependency analysis and management. |
| 63 | + |
| 64 | +**Coverage:** |
| 65 | +- Dependency detection and analysis |
| 66 | +- Standard library identification |
| 67 | +- Third-party module detection |
| 68 | +- Dependency resolution |
| 69 | +- Requirements file parsing |
| 70 | +- Dependency caching |
| 71 | +- Conflict detection |
| 72 | +- Dependency validation |
| 73 | + |
| 74 | +**Key Test Classes:** |
| 75 | +- `TestDependencyAnalyzer` - Core analyzer functionality |
| 76 | +- `TestImportDetection` - Import statement detection |
| 77 | +- `TestDependencyResolution` - Dependency resolution |
| 78 | +- `TestDependencyFiles` - Requirements file handling |
| 79 | +- `TestDependencyCaching` - Caching mechanisms |
| 80 | +- `TestDependencyConflictDetection` - Conflict detection |
| 81 | +- `TestDependencyValidation` - Validation logic |
| 82 | + |
| 83 | +## Running Tests |
| 84 | + |
| 85 | +### Run All Tests |
| 86 | +```bash |
| 87 | +pytest Tests/ -v |
| 88 | +``` |
| 89 | + |
| 90 | +### Run Specific Test File |
| 91 | +```bash |
| 92 | +pytest Tests/test_compilation.py -v |
| 93 | +``` |
| 94 | + |
| 95 | +### Run Specific Test Class |
| 96 | +```bash |
| 97 | +pytest Tests/test_compilation.py::TestArkConfigLoader -v |
| 98 | +``` |
| 99 | + |
| 100 | +### Run Specific Test |
| 101 | +```bash |
| 102 | +pytest Tests/test_compilation.py::TestArkConfigLoader::test_load_ark_config_returns_dict -v |
| 103 | +``` |
| 104 | + |
| 105 | +### Run with Coverage Report |
| 106 | +```bash |
| 107 | +pytest Tests/ --cov=Core --cov=ENGINES --cov-report=html |
| 108 | +``` |
| 109 | + |
| 110 | +### Run Tests in Parallel |
| 111 | +```bash |
| 112 | +pytest Tests/ -n auto |
| 113 | +``` |
| 114 | + |
| 115 | +## Test Fixtures |
| 116 | + |
| 117 | +### `_ensure_offscreen_qt` |
| 118 | +Automatically applied to all tests. Ensures Qt uses an offscreen backend to avoid display/server requirements. |
| 119 | + |
| 120 | +### `temp_workspace` |
| 121 | +Creates a temporary directory for testing file operations. Automatically cleaned up after test. |
| 122 | + |
| 123 | +### `sample_python_file` |
| 124 | +Creates a sample Python file with an entry point (`if __name__ == "__main__"`). |
| 125 | + |
| 126 | +### `sample_library_file` |
| 127 | +Creates a sample Python library file without an entry point. |
| 128 | + |
| 129 | +### `ark_config_file` |
| 130 | +Creates a sample ARK configuration file for testing. |
| 131 | + |
| 132 | +## Test Coverage |
| 133 | + |
| 134 | +Current test coverage includes: |
| 135 | + |
| 136 | +- **Compilation Core**: 85%+ |
| 137 | + - ARK configuration loading |
| 138 | + - File detection and filtering |
| 139 | + - Command building |
| 140 | + - Process management |
| 141 | + |
| 142 | +- **Engines**: 80%+ |
| 143 | + - Registry operations |
| 144 | + - Command generation |
| 145 | + - Engine-specific options |
| 146 | + - Plugin detection |
| 147 | + |
| 148 | +- **Dependencies**: 75%+ |
| 149 | + - Stdlib detection |
| 150 | + - Import detection |
| 151 | + - Dependency resolution |
| 152 | + - File parsing |
| 153 | + |
| 154 | +## Mocking Strategy |
| 155 | + |
| 156 | +Tests use `unittest.mock` for: |
| 157 | +- GUI components (QCheckBox, QLineEdit, etc.) |
| 158 | +- File system operations |
| 159 | +- Process management |
| 160 | +- External dependencies |
| 161 | + |
| 162 | +Example: |
| 163 | +```python |
| 164 | +gui = Mock() |
| 165 | +gui.opt_onefile = Mock() |
| 166 | +gui.opt_onefile.isChecked.return_value = True |
| 167 | +``` |
| 168 | + |
| 169 | +## Best Practices |
| 170 | + |
| 171 | +1. **Isolation**: Each test is independent and doesn't rely on others |
| 172 | +2. **Cleanup**: Temporary files and directories are automatically cleaned up |
| 173 | +3. **Mocking**: External dependencies are mocked to avoid side effects |
| 174 | +4. **Descriptive Names**: Test names clearly describe what they test |
| 175 | +5. **Documentation**: Each test class has a docstring explaining its purpose |
| 176 | + |
| 177 | +## Adding New Tests |
| 178 | + |
| 179 | +When adding new tests: |
| 180 | + |
| 181 | +1. Create a new test class with a descriptive name |
| 182 | +2. Add a docstring explaining the test's purpose |
| 183 | +3. Use appropriate fixtures for setup/teardown |
| 184 | +4. Mock external dependencies |
| 185 | +5. Use descriptive assertion messages |
| 186 | +6. Follow the existing naming conventions |
| 187 | + |
| 188 | +Example: |
| 189 | +```python |
| 190 | +class TestNewFeature: |
| 191 | + """Tests for new feature""" |
| 192 | + |
| 193 | + def test_feature_basic_functionality(self, temp_workspace): |
| 194 | + """Test basic functionality of new feature""" |
| 195 | + # Setup |
| 196 | + test_file = os.path.join(temp_workspace, "test.py") |
| 197 | + |
| 198 | + # Execute |
| 199 | + result = new_feature(test_file) |
| 200 | + |
| 201 | + # Assert |
| 202 | + assert result is not None |
| 203 | + assert isinstance(result, expected_type) |
| 204 | +``` |
| 205 | + |
| 206 | +## Continuous Integration |
| 207 | + |
| 208 | +These tests are designed to run in CI/CD pipelines: |
| 209 | + |
| 210 | +- No GUI display required (offscreen Qt backend) |
| 211 | +- No external network access required |
| 212 | +- Deterministic results |
| 213 | +- Fast execution (< 5 minutes for full suite) |
| 214 | +- Clear error messages for debugging |
| 215 | + |
| 216 | +## Troubleshooting |
| 217 | + |
| 218 | +### Qt Platform Plugin Error |
| 219 | +If you see "Could not find the Qt platform plugin", the `_ensure_offscreen_qt` fixture should handle this. If not, set: |
| 220 | +```bash |
| 221 | +export QT_QPA_PLATFORM=offscreen |
| 222 | +``` |
| 223 | + |
| 224 | +### Import Errors |
| 225 | +Ensure the project root is in PYTHONPATH: |
| 226 | +```bash |
| 227 | +export PYTHONPATH=/path/to/PyCompiler-ARK-Professional:$PYTHONPATH |
| 228 | +``` |
| 229 | + |
| 230 | +### Temporary File Issues |
| 231 | +If tests fail due to temporary file cleanup, check disk space and permissions in `/tmp`. |
| 232 | + |
| 233 | +## Performance |
| 234 | + |
| 235 | +- **Fast tests**: < 100ms (unit tests) |
| 236 | +- **Medium tests**: 100ms - 1s (integration tests) |
| 237 | +- **Slow tests**: > 1s (process tests) |
| 238 | + |
| 239 | +Use `-m "not slow"` to skip slow tests during development: |
| 240 | +```bash |
| 241 | +pytest Tests/ -m "not slow" -v |
| 242 | +``` |
| 243 | + |
| 244 | +## Contributing |
| 245 | + |
| 246 | +When contributing tests: |
| 247 | + |
| 248 | +1. Ensure all tests pass locally |
| 249 | +2. Maintain or improve code coverage |
| 250 | +3. Follow the existing test structure |
| 251 | +4. Add documentation for complex tests |
| 252 | +5. Use meaningful assertion messages |
| 253 | + |
| 254 | +## License |
| 255 | + |
| 256 | +All test files are licensed under Apache License 2.0. See LICENSE file for details. |
0 commit comments