|
| 1 | +# Python Test Case Generator |
| 2 | + |
| 3 | +A web application that analyzes Python code, generates test cases, and provides code quality insights. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +### 1. Code Analysis |
| 8 | + |
| 9 | +- Automatic function detection |
| 10 | +- Type hint analysis |
| 11 | +- Complexity metrics calculation |
| 12 | +- Code quality suggestions |
| 13 | +- Best practice recommendations |
| 14 | + |
| 15 | +### 2. Test Case Generation |
| 16 | + |
| 17 | +- Generates edge cases based on type hints |
| 18 | +- Supports multiple test categories: |
| 19 | + - Boundary cases |
| 20 | + - Edge cases |
| 21 | + - Error cases |
| 22 | +- Export tests in different formats (pytest/unittest) |
| 23 | + |
| 24 | +### 3. User Interface |
| 25 | + |
| 26 | +- Interactive code editor with syntax highlighting |
| 27 | +- Dark/Light theme toggle |
| 28 | +- Split view layout |
| 29 | +- Collapsible test case sections |
| 30 | +- Copy-to-clipboard functionality |
| 31 | +- Test case filtering by category |
| 32 | + |
| 33 | +## Project Structure |
| 34 | + |
| 35 | +``` |
| 36 | +python_test_generator/ |
| 37 | +├── app.py # Main Flask application |
| 38 | +├── templates/ |
| 39 | +│ └── index.html # Main HTML template |
| 40 | +├── static/ |
| 41 | +│ ├── css/ |
| 42 | +│ │ └── style.css # Custom styles |
| 43 | +│ └── js/ |
| 44 | +│ └── main.js # Frontend functionality |
| 45 | +└── requirements.txt # Project dependencies |
| 46 | +``` |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +1. Clone the repository |
| 51 | + |
| 52 | +```bash |
| 53 | +git clone |
| 54 | +cd python_test_generator |
| 55 | +``` |
| 56 | + |
| 57 | +2. Create and activate virtual environment |
| 58 | + |
| 59 | +```bash |
| 60 | +python -m venv venv |
| 61 | + |
| 62 | +# Windows |
| 63 | +venv\Scripts\activate |
| 64 | + |
| 65 | +# Unix/MacOS |
| 66 | +source venv/bin/activate |
| 67 | +``` |
| 68 | + |
| 69 | +3. Install dependencies |
| 70 | + |
| 71 | +```bash |
| 72 | +pip install -r requirements.txt |
| 73 | +``` |
| 74 | + |
| 75 | +## Running the Application |
| 76 | + |
| 77 | +1. Start the Flask server |
| 78 | + |
| 79 | +```bash |
| 80 | +python app.py |
| 81 | +``` |
| 82 | + |
| 83 | +2. Open your browser and navigate to `http://localhost:5000` |
| 84 | + |
| 85 | +## Code Examples |
| 86 | + |
| 87 | +### Example Input |
| 88 | + |
| 89 | +```python |
| 90 | +def calculate_discount(price: int, discount_percentage: int) -> float: |
| 91 | + if discount_percentage < 0 or discount_percentage > 100: |
| 92 | + raise ValueError("Discount percentage must be between 0 and 100") |
| 93 | + return price * (1 - discount_percentage / 100) |
| 94 | +``` |
| 95 | + |
| 96 | +### Generated Test Cases |
| 97 | + |
| 98 | +```python |
| 99 | +def test_calculate_discount_boundary(): |
| 100 | + try: |
| 101 | + result = calculate_discount(0, discount_percentage) |
| 102 | + assert result is not None |
| 103 | + except Exception as e: |
| 104 | + pass |
| 105 | + |
| 106 | +def test_calculate_discount_edge(): |
| 107 | + try: |
| 108 | + result = calculate_discount(-1, discount_percentage) |
| 109 | + assert result is not None |
| 110 | + except Exception as e: |
| 111 | + pass |
| 112 | +``` |
| 113 | + |
| 114 | +## Dependencies |
| 115 | + |
| 116 | +- Flask==3.0.0 |
| 117 | +- radon==3.2.6 |
| 118 | + |
| 119 | +## Features in Detail |
| 120 | + |
| 121 | +### Code Analysis |
| 122 | + |
| 123 | +- Function detection using Python's AST |
| 124 | +- Type hint analysis for parameters and return types |
| 125 | +- Cyclomatic complexity calculation |
| 126 | +- Code quality suggestions including: |
| 127 | + - Missing docstrings |
| 128 | + - Missing type hints |
| 129 | + - Function complexity warnings |
| 130 | + |
| 131 | +### Test Case Generation |
| 132 | + |
| 133 | +- Generates test cases based on parameter types |
| 134 | +- Supports different test categories |
| 135 | +- Handles edge cases for common data types: |
| 136 | + - Integers (0, -1, MAX_INT) |
| 137 | + - Strings (empty, very long, special characters) |
| 138 | + - Lists (empty, large, None values) |
| 139 | + |
| 140 | +### UI Features |
| 141 | + |
| 142 | +- Syntax highlighting using CodeMirror |
| 143 | +- Real-time code analysis |
| 144 | +- Theme switching (light/dark) |
| 145 | +- Test case organization and filtering |
| 146 | +- Export functionality |
0 commit comments