Skip to content

feat: add pytest test suite for 3 Python scripts#2247

Open
AnandSundar wants to merge 1 commit into
OWASP:masterfrom
AnandSundar:feat/add-pytest-tests-3-scripts
Open

feat: add pytest test suite for 3 Python scripts#2247
AnandSundar wants to merge 1 commit into
OWASP:masterfrom
AnandSundar:feat/add-pytest-tests-3-scripts

Conversation

@AnandSundar

@AnandSundar AnandSundar commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Adds a pytest test suite for the three Python build-helper scripts in scripts/ that have no network dependencies: Generate_CheatSheets_TOC.py, Update_CheatSheets_Index.py, and Generate_Technologies_JSON.py. Also establishes the pytest infrastructure (config + dev-dependencies file + test directory) the project currently lacks.

Each script is minimally refactored to expose pure helper functions (to_display_name, parse_index_line, group_by_letter, etc.) and to wrap its imperative top-level code in a main() function with parameterized paths. The refactor preserves byte-for-byte output of the original scripts when invoked from the scripts/ directory — verified via smoke test against the real cheatsheets/ directory.

What's in this PR

  • Refactor of 3 scripts (3 modified files): each now has importable helpers and a main() that returns an exit code, with an if __name__ == "__main__": guard. No behavioral change for the existing CLI usage.
  • Test suite of 56 cases (5 new files): unit tests for the helpers + integration tests for main() end-to-end. HTTP is mocked with stdlib unittest.mock; no new runtime dependencies.
  • Pytest infra (pytest.ini, requirements-dev.txt): kept separate from requirements.txt so the production image does not pull in pytest.
  • .gitignore cleanup: __pycache__/, *.pyc, and docs/plans/ are now ignored (the latter keeps working-tree planning notes out of the repo).

Test results

  • python -m pytest exits 0
  • 56 passed in ~0.25s

PR scope-check compliance

  • Cheat sheets touched: 0
  • Net additions: +742 (well under the 1500 line limit)
  • 0 markdown files modified (the md_lint_check.yml workflow is unaffected)

Out of scope (deferred to follow-up PRs)

  • Refactor + test Generate_RSS_Feed.py and Identify_Old_Issue_And_PR.py (network-dependent; mocking pattern is established by this PR).
  • .github/workflows/test-python.yml to run pytest on every PR. Best added after the suite is broader.

Introduces a pytest-based test suite for the three build-helper scripts
in scripts/ that have no network dependencies:

  - Generate_CheatSheets_TOC.py
  - Update_CheatSheets_Index.py
  - Generate_Technologies_JSON.py

Each script is minimally refactored to expose pure helper functions
(to_display_name, parse_index_line, group_by_letter, etc.) and to
wrap its imperative top-level code in a main() function with
parameterized paths. Byte-for-byte output of the original scripts is
preserved when invoked from the scripts/ directory.

The test suite covers 56 cases (unit + integration), including:

  - helper-function unit tests (display names, language detection,
    letter grouping, whitespace cleanup, line parsing)
  - main() integration tests against fixture cheatsheet directories
  - mocked HTTP path for Generate_Technologies_JSON.main()

Files added:
  - pytest.ini, requirements-dev.txt
  - tests/__init__.py, tests/conftest.py
  - tests/test_*.py for the three scripts

The remaining two scripts (Generate_RSS_Feed.py, Identify_Old_Issue_And_PR.py)
and a CI workflow that runs pytest on PRs are deferred to follow-up PRs.

AI assistance: this change was developed with the help of an AI coding
assistant. The refactor, tests, and commit message were reviewed by the
author before submission.
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