@@ -8,7 +8,7 @@ This design describes a pytest-based testing framework for the Secure Coding Gui
88
99### High-Level Structure
1010
11- ```
11+ ``` text
1212docs/Secure-Coding-Guide-for-Python/
1313├── tests/ # New testing directory
1414│ ├── __init__.py
@@ -26,7 +26,7 @@ docs/Secure-Coding-Guide-for-Python/
2626
2727### GitHub Actions Integration
2828
29- ```
29+ ``` text
3030.github/workflows/
3131├── linter.yml # Existing markdown linter
3232└── python-tests.yml # New Python testing workflow
@@ -39,11 +39,13 @@ docs/Secure-Coding-Guide-for-Python/
3939** Purpose** : Discover Python files and README.md files in the directory structure
4040
4141** Key Functions** :
42+
4243- ` find_python_files(root_dir: str) -> List[Path] ` : Recursively finds all ` .py ` files under the root directory, excluding the tests directory itself
4344- ` find_readme_files(root_dir: str) -> List[Path] ` : Recursively finds all ` README.md ` files in CWE directories
4445- ` get_cwe_directories(root_dir: str) -> List[Path] ` : Identifies all CWE-specific directories
4546
4647** Implementation Notes** :
48+
4749- Use ` pathlib.Path ` for cross-platform compatibility
4850- Exclude template files and test files from validation
4951- Cache results in pytest fixtures for performance
@@ -71,6 +73,7 @@ docs/Secure-Coding-Guide-for-Python/
7173 - Output: Pass/fail with import error details
7274
7375** Implementation Strategy** :
76+
7477- Use ` pytest.mark.parametrize ` with file list from scanner
7578- Capture stdout/stderr during execution to prevent test output pollution
7679- Use subprocess for isolated execution to prevent side effects
@@ -81,12 +84,14 @@ docs/Secure-Coding-Guide-for-Python/
8184** Purpose** : Parse README.md files and extract structural elements
8285
8386** Key Functions** :
87+
8488- ` parse_markdown(file_path: Path) -> Dict ` : Parses markdown and returns structure
8589- ` extract_sections(content: str) -> List[str] ` : Extracts all heading sections
8690- ` extract_code_references(content: str) -> List[str] ` : Finds references to Python files (e.g., ` compliant01.py ` )
8791- ` validate_table_structure(content: str, table_name: str) -> bool ` : Validates presence and structure of required tables
8892
8993** Implementation Notes** :
94+
9095- Use regex patterns to identify markdown elements
9196- Consider using ` markdown ` library or simple regex for lightweight parsing
9297- Return structured data for easy test assertions
@@ -125,6 +130,7 @@ docs/Secure-Coding-Guide-for-Python/
125130 - Output: Pass/fail with ordering issues
126131
127132** Implementation Strategy** :
133+
128134- Use markdown parser utility to extract structure
129135- Compare against template requirements
130136- Provide clear error messages indicating what's missing or incorrect
@@ -151,6 +157,7 @@ docs/Secure-Coding-Guide-for-Python/
151157 - Output: Pass/fail with broken index links
152158
153159** Implementation Strategy** :
160+
154161- Use ` lychee ` CLI tool for comprehensive link checking (supports internal and external links)
155162- Alternative: Use ` markdownlint-cli2 ` with link validation plugins
156163- Wrap CLI tool execution in pytest tests for integration with test suite
@@ -162,12 +169,14 @@ docs/Secure-Coding-Guide-for-Python/
162169** Purpose** : Centralize test configuration and shared fixtures
163170
164171** Fixtures** :
172+
165173- ` python_files ` : Session-scoped fixture returning list of all Python files to validate
166174- ` readme_files ` : Session-scoped fixture returning list of all README.md files to validate
167175- ` project_root ` : Fixture providing path to Secure-Coding-Guide-for-Python directory
168176- ` template_structure ` : Fixture providing parsed template structure for comparison
169177
170178** Configuration** :
179+
171180- Set pytest markers for test categorization (` @pytest.mark.python ` , ` @pytest.mark.markdown ` )
172181- Configure test output formatting
173182- Set up logging for detailed error reporting
@@ -177,6 +186,7 @@ docs/Secure-Coding-Guide-for-Python/
177186** Purpose** : Modern Python project configuration following PEP 735 standards
178187
179188** Configuration Structure** :
189+
180190``` toml
181191[project ]
182192name = " secure-coding-guide-python-tests"
@@ -253,6 +263,7 @@ exclude_lines = [
253263```
254264
255265** Design Decisions** :
266+
256267- Use PEP 735 ` [dependency-groups] ` instead of ` [project.optional-dependencies] `
257268- Separate ` test ` group (minimal) from ` dev ` group (includes linting/tox)
258269- Configure pytest, ruff, and coverage in single file
@@ -264,6 +275,7 @@ exclude_lines = [
264275** Purpose** : Enable local multi-version testing with the same matrix as CI/CD
265276
266277** Configuration Structure** :
278+
267279``` ini
268280[tox]
269281requires = tox-uv
@@ -297,13 +309,15 @@ commands =
297309```
298310
299311** Design Decisions** :
312+
300313- Use ` requires = tox-uv ` to enable uv integration
301314- Use ` groups = test ` to install from PEP 735 dependency groups
302315- Match CI/CD Python version matrix (3.9-3.14) for consistency
303316- Include separate environments for linting and coverage
304317- No ` skipsdist ` needed - tox-uv handles this automatically
305318
306319** Local Usage** :
320+
307321``` bash
308322# Install uv and tox
309323uv pip install tox tox-uv
@@ -329,6 +343,7 @@ tox -e links
329343** Purpose** : Automate test execution on pull requests and pushes using ` uv `
330344
331345** Workflow Structure** :
346+
332347``` yaml
333348name : Python Tests
334349
@@ -381,6 +396,7 @@ jobs:
381396` ` `
382397
383398**Design Decisions**:
399+
384400- Test against multiple Python versions (3.9-3.14) to ensure broad compatibility and catch version-specific deprecation warnings
385401- Use ` astral-sh/setup-uv@v3` action with caching enabled for fast, reliable uv installation
386402- Use `uv python install` to install specific Python version (uv manages Python versions)
@@ -392,6 +408,7 @@ jobs:
392408- Use verbose output (`-v`) and short traceback (`--tb=short`) for readable CI logs
393409
394410**Performance Benefits**:
411+
395412- ` uv` is 10-100x faster than pip for dependency resolution and installation
396413- Parallel dependency downloads
397414- Better caching in CI/CD environments
@@ -400,6 +417,7 @@ jobs:
400417# # Data Models
401418
402419# ## Python File Validation Result
420+
403421` ` ` python
404422@dataclass
405423class PythonValidationResult:
@@ -413,6 +431,7 @@ class PythonValidationResult:
413431` ` `
414432
415433# ## Markdown Validation Result
434+
416435` ` ` python
417436@dataclass
418437class MarkdownValidationResult:
@@ -456,6 +475,7 @@ class MarkdownValidationResult:
456475# ## Unit Tests for Test Utilities
457476
458477Create tests for the testing framework itself :
478+
459479- `test_file_scanner.py` : Validate file discovery logic
460480- `test_markdown_parser.py` : Validate markdown parsing logic
461481
@@ -484,11 +504,13 @@ Create tests for the testing framework itself:
484504All dependencies are managed via PEP 735 dependency groups in `pyproject.toml` :
485505
486506# ## Test Dependencies (dependency-groups.test)
507+
487508- ` pytest>=8.0.0` - Testing framework
488509- ` pytest-cov>=4.1.0` - Coverage reporting
489510- ` pytest-xdist>=3.5.0` - Parallel test execution
490511
491512# ## Development Dependencies (dependency-groups.dev)
513+
492514- All test dependencies plus :
493515- ` ruff>=0.4.0` - Fast Python linter and formatter
494516- ` tox>=4.0.0` - Multi-version testing orchestration
@@ -498,6 +520,7 @@ All dependencies are managed via PEP 735 dependency groups in `pyproject.toml`:
498520# ## Installation
499521
500522**Install uv** (one-time setup):
523+
501524` ` ` bash
502525# Linux/macOS
503526curl -LsSf https://astral.sh/uv/install.sh | sh
@@ -513,6 +536,7 @@ brew install uv
513536` ` `
514537
515538**Install project dependencies**:
539+
516540` ` ` bash
517541cd docs/Secure-Coding-Guide-for-Python
518542
@@ -532,6 +556,7 @@ uv run tox
532556# # Migration and Rollout
533557
534558# ## Phase 1: Initial Implementation
559+
5355601. Create `pyproject.toml` with PEP 735 dependency groups
5365612. Create `tox.ini` with multi-version testing configuration
5375623. Create test directory structure
@@ -541,19 +566,22 @@ uv run tox
5415667. Test with subset of files
542567
543568# ## Phase 2: Enhanced Validation
569+
5445701. Add deprecation warning detection
5455712. Add import validation
5465723. Implement markdown parser utility
5475734. Add markdown structure validation
548574
549575# ## Phase 3: Refinement
576+
5505771. Add code reference validation
5515782. Add table structure validation
5525793. Optimize performance with pytest-xdist
5535804. Add ruff linting configuration
5545815. Add documentation
555582
556583# ## Phase 4: Documentation and Adoption
584+
5575851. Add README in tests/ directory with local testing instructions
5585862. Document uv and tox usage
5595873. Update CONTRIBUTING.md with testing framework information
0 commit comments