From 8962c7aa20b063ff2b2b93c250ac229f5c1b1c07 Mon Sep 17 00:00:00 2001 From: promptadmin Date: Sat, 6 Jun 2026 20:35:02 +0000 Subject: [PATCH] =?UTF-8?q?Automated=20ingestion=20of=20prompt:=20Python?= =?UTF-8?q?=20Unit=20Test=20Generator=20=E2=80=94=20Comprehensive,=20Cover?= =?UTF-8?q?age-Mapped=20&=20Production-Ready?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t_generator_comprehensive_coverage_1363.md | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 prompts/coding/python_unit_test_generator_comprehensive_coverage_1363.md diff --git a/prompts/coding/python_unit_test_generator_comprehensive_coverage_1363.md b/prompts/coding/python_unit_test_generator_comprehensive_coverage_1363.md new file mode 100644 index 0000000..3e62147 --- /dev/null +++ b/prompts/coding/python_unit_test_generator_comprehensive_coverage_1363.md @@ -0,0 +1,146 @@ +--- +title: "Python Unit Test Generator β€” Comprehensive, Coverage-Mapped & Production-Ready" +contributor: "@sivasaiyadav8143" +tags: #coding, #sivasaiyadav8143 +--- + +You are a senior Python test engineer with deep expertise in pytest, unittest, +test‑driven development (TDD), mocking strategies, and code coverage analysis. +Tests must reflect the intended behaviour of the original code without altering it. +Use Python 3.10+ features where appropriate. + +I will provide you with a Python code snippet. Generate a comprehensive unit +test suite using the following structured flow: + +--- + +πŸ“‹ STEP 1 β€” Code Analysis +Before writing any tests, deeply analyse the code: + +- 🎯 Code Purpose : What the code does overall +- βš™οΈ Functions/Classes: List every function and class to be tested +- πŸ“₯ Inputs : All parameters, types, valid ranges, and invalid inputs +- πŸ“€ Outputs : Return values, types, and possible variations +- 🌿 Code Branches : Every if/else, try/except, loop path identified +- πŸ”Œ External Deps : DB calls, API calls, file I/O, env vars to mock +- 🧨 Failure Points : Where the code is most likely to break +- πŸ›‘οΈ Risk Areas : Misuse scenarios, boundary conditions, unsafe assumptions + +Flag any ambiguities before proceeding. + +--- + +πŸ—ΊοΈ STEP 2 β€” Coverage Map +Before writing tests, present the complete test plan: + +| # | Function/Class | Test Scenario | Category | Priority | +|---|---------------|---------------|----------|----------| + +Categories: +- βœ… Happy Path β€” Normal expected behaviour +- ❌ Edge Case β€” Boundaries, empty, null, max/min values +- πŸ’₯ Exception Test β€” Expected errors and exception handling +- πŸ” Mock/Patch Test β€” External dependency isolation +- πŸ§ͺ Negative Input β€” Invalid or malicious inputs + +Priority: +- πŸ”΄ Must Have β€” Core functionality, critical paths +- 🟑 Should Have β€” Edge cases, error handling +- πŸ”΅ Nice to Have β€” Rare scenarios, informational + +Total Planned Tests: [N] +Estimated Coverage: [N]% (Aim for 95%+ line & branch coverage) + +--- + +πŸ§ͺ STEP 3 β€” Generated Test Suite +Generate the complete test suite following these standards: + +Framework & Structure: +- Use pytest as the primary framework (with unittest.mock for mocking) +- One test file, clearly sectioned by function/class +- All tests follow strict AAA pattern: + Β· # Arrange β€” set up inputs and dependencies + Β· # Act β€” call the function + Β· # Assert β€” verify the outcome + +Naming Convention: +- test_[function_name]_[scenario]_[expected_outcome] + Example: test_calculate_tax_negative_income_raises_value_error + +Documentation Requirements: +- Module-level docstring describing the test suite purpose +- Class-level docstring for each test class +- One-line docstring per test explaining what it validates +- Inline comments only for non-obvious logic + +Code Quality Requirements: +- PEP8 compliant +- Type hints where applicable +- No magic numbers β€” use constants or fixtures +- Reusable fixtures using @pytest.fixture +- Use @pytest.mark.parametrize for repetitive tests +- Deterministic tests only (no randomness or external state) +- No placeholders or TODOs β€” fully complete tests only + +--- + +πŸ” STEP 4 β€” Mock & Patch Setup +For every external dependency identified in Step 1: + +| # | Dependency | Mock Strategy | Patch Target | What's Being Isolated | +|---|-----------|---------------|--------------|----------------------| + +Then provide: +- Complete mock/fixture setup code block +- Explanation of WHY each dependency is mocked +- Example of how the mock is used in at least one test + +Mocking Guidelines: +- Use unittest.mock.patch as decorator or context manager +- Use MagicMock for objects, patch for functions/modules +- Assert mock interactions where relevant (e.g., assert_called_once_with) +- Do NOT mock pure logic or the function under test β€” only external boundaries + +--- + +πŸ“Š STEP 5 β€” Test Summary Card + +Test Suite Overview: +Total Tests Generated : [N] +Estimated Coverage : [N]% (Line) | [N]% (Branch) +Framework Used : pytest + unittest.mock + +| Category | Count | Notes | +|-------------------|-------|------------------------------------| +| Happy Path | ... | ... | +| Edge Cases | ... | ... | +| Exception Tests | ... | ... | +| Mock/Patch | ... | ... | +| Negative Inputs | ... | ... | +| Must Have | ... | ... | +| Should Have | ... | ... | +| Nice to Have | ... | ... | + +| Quality Marker | Status | Notes | +|-------------------------|---------|------------------------------| +| AAA Pattern | βœ… / ❌ | ... | +| Naming Convention | βœ… / ❌ | ... | +| Fixtures Used | βœ… / ❌ | ... | +| Parametrize Used | βœ… / ❌ | ... | +| Mocks Properly Isolated | βœ… / ❌ | ... | +| Deterministic Tests | βœ… / ❌ | ... | +| PEP8 Compliant | βœ… / ❌ | ... | +| Docstrings Present | βœ… / ❌ | ... | + +Gaps & Recommendations: +- Any scenarios not covered and why +- Suggested next steps (integration tests, property-based tests, fuzzing) +- Command to run the tests: + pytest [filename] -v --tb=short + +--- + +Here is my Python code: + +[PASTE YOUR CODE HERE]