testgenie-py 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- testgenie_py-0.2.4/PKG-INFO +139 -0
- testgenie_py-0.2.4/README.md +112 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/pyproject.toml +2 -2
- testgenie_py-0.2.4/testgen/.coverage +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/ast_analyzer.py +4 -1
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/fuzz_analyzer.py +2 -2
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/random_feedback_analyzer.py +3 -3
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/test_case_analyzer.py +2 -0
- testgenie_py-0.2.4/testgen/code_to_test/boolean.py +146 -0
- testgenie_py-0.2.4/testgen/code_to_test/calculator.py +29 -0
- testgenie_py-0.2.4/testgen/code_to_test/code_to_fuzz.py +234 -0
- testgenie_py-0.2.4/testgen/code_to_test/code_to_fuzz_lite.py +397 -0
- testgenie_py-0.2.4/testgen/code_to_test/decisions.py +57 -0
- testgenie_py-0.2.4/testgen/code_to_test/math_utils.py +47 -0
- testgenie_py-0.2.4/testgen/code_to_test/sample_code_bin.py +141 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/controller/cli_controller.py +0 -1
- testgenie_py-0.2.4/testgen/generated_boolean.py +48 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/reinforcement/agent.py +30 -26
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/reinforcement/environment.py +7 -6
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/reinforcement/statement_coverage_state.py +5 -3
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/service/analysis_service.py +8 -6
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/service/cfg_service.py +2 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/service/generator_service.py +6 -9
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/service/logging_service.py +4 -2
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/service/service.py +11 -20
- testgenie_py-0.2.4/testgen/testgen.db +0 -0
- testgenie_py-0.2.4/testgen/tests/test_boolean.py +81 -0
- testgenie_py-0.2.4/testgen/tests/test_generated_boolean.py +83 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/coverage_visualizer.py +5 -3
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/file_utils.py +1 -1
- testgenie_py-0.2.4/testgen/util/z3_utils/__init__.py +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v1.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v2.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v3.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v4.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v5.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v6.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v7.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_and_coverage_v8.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v1.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v2.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v3.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v4.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v5.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v6.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v7.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_bin_xor_coverage_v8.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v1.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v2.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v3.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v4.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v5.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v6.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v7.png +0 -0
- testgenie_py-0.2.4/testgen/visualize/boolean_status_flags_coverage_v8.png +0 -0
- testgenie_py-0.2.2/PKG-INFO +0 -27
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/contracts/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/contracts/contract.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/contracts/no_exception_contract.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/contracts/nonnull_contract.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/reinforcement_analyzer.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/analyzer/test_case_analyzer_context.py +0 -0
- {testgenie_py-0.2.2/testgen/controller → testgenie_py-0.2.4/testgen/code_to_test}/__init__.py +0 -0
- {testgenie_py-0.2.2/testgen/generator → testgenie_py-0.2.4/testgen/controller}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/controller/docker_controller.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/docker/Dockerfile +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generated_samplecodebin.py +0 -0
- {testgenie_py-0.2.2/testgen/inspector → testgenie_py-0.2.4/testgen/generator}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/code_generator.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/doctest_generator.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/generator.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/pytest_generator.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/test_generator.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/generator/unit_test_generator.py +0 -0
- {testgenie_py-0.2.2/testgen/models → testgenie_py-0.2.4/testgen/inspector}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/inspector/inspector.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/main.py +0 -0
- {testgenie_py-0.2.2/testgen/presentation → testgenie_py-0.2.4/testgen/models}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/models/analysis_context.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/models/function_metadata.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/models/generator_context.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/models/test_case.py +0 -0
- {testgenie_py-0.2.2/testgen/reinforcement → testgenie_py-0.2.4/testgen/presentation}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/presentation/cli_view.py +0 -0
- {testgenie_py-0.2.2/testgen/service → testgenie_py-0.2.4/testgen/reinforcement}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/reinforcement/abstract_state.py +0 -0
- {testgenie_py-0.2.2/testgen/sqlite → testgenie_py-0.2.4/testgen/service}/__init__.py +0 -0
- {testgenie_py-0.2.2/testgen/tree → testgenie_py-0.2.4/testgen/sqlite}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/sqlite/db.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/sqlite/db_service.py +0 -0
- {testgenie_py-0.2.2/testgen/util → testgenie_py-0.2.4/testgen/tests}/__init__.py +0 -0
- {testgenie_py-0.2.2/testgen/util/z3_utils → testgenie_py-0.2.4/testgen/tree}/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/tree/node.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/tree/tree_utils.py +0 -0
- /testgenie_py-0.2.2/README.md → /testgenie_py-0.2.4/testgen/util/__init__.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/coverage_utils.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/randomizer.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/utils.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/z3_utils/ast_to_z3.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/z3_utils/branch_condition.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/z3_utils/constraint_extractor.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/z3_utils/variable_finder.py +0 -0
- {testgenie_py-0.2.2 → testgenie_py-0.2.4}/testgen/util/z3_utils/z3_test_case.py +0 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: testgenie-py
|
3
|
+
Version: 0.2.4
|
4
|
+
Summary: Automated unit test generation tool for Python.
|
5
|
+
Author: cjseitz
|
6
|
+
Author-email: charlesjseitz@gmail.com
|
7
|
+
Requires-Python: >=3.10,<4.0
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
13
|
+
Requires-Dist: ConfigArgParse (==1.7)
|
14
|
+
Requires-Dist: astor (==0.8.1)
|
15
|
+
Requires-Dist: atheris (==2.3.0)
|
16
|
+
Requires-Dist: coverage (==7.6.4)
|
17
|
+
Requires-Dist: docker (>=7.1.0,<8.0.0)
|
18
|
+
Requires-Dist: klara (==0.6.3)
|
19
|
+
Requires-Dist: pygraphviz (>=1.14,<2.0)
|
20
|
+
Requires-Dist: pytest (>=8.3.5,<9.0.0)
|
21
|
+
Requires-Dist: staticfg (>=0.9.5,<0.10.0)
|
22
|
+
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
23
|
+
Requires-Dist: typed-ast (==1.5.5)
|
24
|
+
Requires-Dist: z3-solver (==4.13.3.0)
|
25
|
+
Description-Content-Type: text/markdown
|
26
|
+
|
27
|
+
# TestGenie
|
28
|
+
|
29
|
+
**TestGenie** is an automated unit test generation tool for Python that supports multiple test generation strategies, including static AST analysis, fuzz testing, feedback-directed random testing, and reinforcement learning.
|
30
|
+
Built with a modular Pipe and Filter architecture, it analyzes Python source code to extract function metadata, generates meaningful test cases, and outputs executable test suites in formats like Unittest, PyTest, or Doctest.
|
31
|
+
The system can also measure and report code coverage and safely execute tests in Docker containers.
|
32
|
+
TestGenie aims to reduce manual testing effort, improve coverage, and explore the potential of learning-based approaches for optimizing test generation.
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
Make sure you have **Python 3.10+** and **Poetry** installed.
|
39
|
+
|
40
|
+
Install dependencies:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
poetry install
|
44
|
+
```
|
45
|
+
|
46
|
+
Activate the virtual environment:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
poetry shell
|
50
|
+
```
|
51
|
+
|
52
|
+
---
|
53
|
+
|
54
|
+
## Running the CLI
|
55
|
+
|
56
|
+
To invoke the test generator, run:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
poetry run python -m testgen.main <file_path> [options]
|
60
|
+
```
|
61
|
+
|
62
|
+
**Required Argument:**
|
63
|
+
- `<file_path>`: Path to the Python module you want to analyze.
|
64
|
+
|
65
|
+
---
|
66
|
+
|
67
|
+
## Command-Line Options
|
68
|
+
|
69
|
+
| Command/Flag | Description |
|
70
|
+
|:---|:---|
|
71
|
+
| `--output, -o <path>` | Path to output directory for generated test files (default: `./tests`) |
|
72
|
+
| `--generate-only, -g` | Only generate test code, skip running tests and measuring coverage |
|
73
|
+
| `--test-mode <mode>` | Set the test analysis strategy: `ast` (default), `random`, `fuzz`, or `reinforce` |
|
74
|
+
| `--test-format <format>` | Set the test output format: `unittest` (default), `pytest`, or `doctest` |
|
75
|
+
| `--safe` | Run test generation inside a Docker container for isolation and safety |
|
76
|
+
| `--query, -q` | Query the database for test cases, coverage data, and test results for a specific file |
|
77
|
+
| `--db <db_path>` | Path to SQLite database file (default: `testgen.db`) |
|
78
|
+
| `--reinforce-mode <mode>` | Set mode for reinforcement learning: `train` (default) or `collect` |
|
79
|
+
| `--visualize, -viz` | Visualize generated test coverage graphs using Graphviz |
|
80
|
+
| `--debug` | Enable debug logging output |
|
81
|
+
| `--log-file <path>` | Save logs to the specified file instead of only printing to the console |
|
82
|
+
|
83
|
+
---
|
84
|
+
|
85
|
+
## Examples
|
86
|
+
|
87
|
+
Generate and run unit tests for a Python module:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
poetry run python -m testgen.main mymodule.py
|
91
|
+
```
|
92
|
+
|
93
|
+
Generate tests using fuzzing strategy and output to a custom directory:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
poetry run python -m testgen.main mymodule.py --test-mode fuzz --output generated_tests/
|
97
|
+
```
|
98
|
+
|
99
|
+
Run reinforcement learning-based test generation:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
poetry run python -m testgen.main mymodule.py --test-mode reinforce
|
103
|
+
```
|
104
|
+
|
105
|
+
Query previously generated test results from the database:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
poetry run python -m testgen.main mymodule.py --query
|
109
|
+
```
|
110
|
+
|
111
|
+
Safely generate tests inside a Docker container:
|
112
|
+
|
113
|
+
```bash
|
114
|
+
poetry run python -m testgen.main mymodule.py --safe
|
115
|
+
```
|
116
|
+
|
117
|
+
---
|
118
|
+
|
119
|
+
## Features
|
120
|
+
- Static analysis using Python AST
|
121
|
+
- Fuzz testing using randomized input generation
|
122
|
+
- Feedback-directed random testing
|
123
|
+
- Reinforcement learning-based test case optimization
|
124
|
+
- Supports Unittest, PyTest, and Doctest formats
|
125
|
+
- Code coverage measurement and reporting
|
126
|
+
- Docker sandboxing for safe test execution
|
127
|
+
- SQLite database integration for tracking tests and results
|
128
|
+
- CLI visualization of test coverage graphs
|
129
|
+
|
130
|
+
---
|
131
|
+
|
132
|
+
## Requirements
|
133
|
+
|
134
|
+
- Python 3.10+
|
135
|
+
- Poetry
|
136
|
+
- (Optional) Docker (for safe mode execution)
|
137
|
+
|
138
|
+
---
|
139
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# TestGenie
|
2
|
+
|
3
|
+
**TestGenie** is an automated unit test generation tool for Python that supports multiple test generation strategies, including static AST analysis, fuzz testing, feedback-directed random testing, and reinforcement learning.
|
4
|
+
Built with a modular Pipe and Filter architecture, it analyzes Python source code to extract function metadata, generates meaningful test cases, and outputs executable test suites in formats like Unittest, PyTest, or Doctest.
|
5
|
+
The system can also measure and report code coverage and safely execute tests in Docker containers.
|
6
|
+
TestGenie aims to reduce manual testing effort, improve coverage, and explore the potential of learning-based approaches for optimizing test generation.
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Make sure you have **Python 3.10+** and **Poetry** installed.
|
13
|
+
|
14
|
+
Install dependencies:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
poetry install
|
18
|
+
```
|
19
|
+
|
20
|
+
Activate the virtual environment:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
poetry shell
|
24
|
+
```
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Running the CLI
|
29
|
+
|
30
|
+
To invoke the test generator, run:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
poetry run python -m testgen.main <file_path> [options]
|
34
|
+
```
|
35
|
+
|
36
|
+
**Required Argument:**
|
37
|
+
- `<file_path>`: Path to the Python module you want to analyze.
|
38
|
+
|
39
|
+
---
|
40
|
+
|
41
|
+
## Command-Line Options
|
42
|
+
|
43
|
+
| Command/Flag | Description |
|
44
|
+
|:---|:---|
|
45
|
+
| `--output, -o <path>` | Path to output directory for generated test files (default: `./tests`) |
|
46
|
+
| `--generate-only, -g` | Only generate test code, skip running tests and measuring coverage |
|
47
|
+
| `--test-mode <mode>` | Set the test analysis strategy: `ast` (default), `random`, `fuzz`, or `reinforce` |
|
48
|
+
| `--test-format <format>` | Set the test output format: `unittest` (default), `pytest`, or `doctest` |
|
49
|
+
| `--safe` | Run test generation inside a Docker container for isolation and safety |
|
50
|
+
| `--query, -q` | Query the database for test cases, coverage data, and test results for a specific file |
|
51
|
+
| `--db <db_path>` | Path to SQLite database file (default: `testgen.db`) |
|
52
|
+
| `--reinforce-mode <mode>` | Set mode for reinforcement learning: `train` (default) or `collect` |
|
53
|
+
| `--visualize, -viz` | Visualize generated test coverage graphs using Graphviz |
|
54
|
+
| `--debug` | Enable debug logging output |
|
55
|
+
| `--log-file <path>` | Save logs to the specified file instead of only printing to the console |
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
## Examples
|
60
|
+
|
61
|
+
Generate and run unit tests for a Python module:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
poetry run python -m testgen.main mymodule.py
|
65
|
+
```
|
66
|
+
|
67
|
+
Generate tests using fuzzing strategy and output to a custom directory:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
poetry run python -m testgen.main mymodule.py --test-mode fuzz --output generated_tests/
|
71
|
+
```
|
72
|
+
|
73
|
+
Run reinforcement learning-based test generation:
|
74
|
+
|
75
|
+
```bash
|
76
|
+
poetry run python -m testgen.main mymodule.py --test-mode reinforce
|
77
|
+
```
|
78
|
+
|
79
|
+
Query previously generated test results from the database:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
poetry run python -m testgen.main mymodule.py --query
|
83
|
+
```
|
84
|
+
|
85
|
+
Safely generate tests inside a Docker container:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
poetry run python -m testgen.main mymodule.py --safe
|
89
|
+
```
|
90
|
+
|
91
|
+
---
|
92
|
+
|
93
|
+
## Features
|
94
|
+
- Static analysis using Python AST
|
95
|
+
- Fuzz testing using randomized input generation
|
96
|
+
- Feedback-directed random testing
|
97
|
+
- Reinforcement learning-based test case optimization
|
98
|
+
- Supports Unittest, PyTest, and Doctest formats
|
99
|
+
- Code coverage measurement and reporting
|
100
|
+
- Docker sandboxing for safe test execution
|
101
|
+
- SQLite database integration for tracking tests and results
|
102
|
+
- CLI visualization of test coverage graphs
|
103
|
+
|
104
|
+
---
|
105
|
+
|
106
|
+
## Requirements
|
107
|
+
|
108
|
+
- Python 3.10+
|
109
|
+
- Poetry
|
110
|
+
- (Optional) Docker (for safe mode execution)
|
111
|
+
|
112
|
+
---
|
@@ -1,7 +1,7 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "testgenie-py"
|
3
|
-
version = "0.2.
|
4
|
-
description = ""
|
3
|
+
version = "0.2.4"
|
4
|
+
description = "Automated unit test generation tool for Python."
|
5
5
|
authors = ["cjseitz <charlesjseitz@gmail.com>"]
|
6
6
|
readme = "README.md"
|
7
7
|
include = ["testgen/docker/**"]
|
Binary file
|
@@ -8,6 +8,9 @@ from abc import ABC
|
|
8
8
|
from testgen.models.function_metadata import FunctionMetadata
|
9
9
|
|
10
10
|
class ASTAnalyzer(TestCaseAnalyzerStrategy, ABC):
|
11
|
+
def __init__(self, analysis_context=None):
|
12
|
+
super().__init__(analysis_context)
|
13
|
+
|
11
14
|
def collect_test_cases(self, function_metadata: FunctionMetadata) -> List[TestCase]:
|
12
15
|
"""Collect test cases by analyzing AST conditions and return statements"""
|
13
16
|
|
@@ -34,7 +37,7 @@ class ASTAnalyzer(TestCaseAnalyzerStrategy, ABC):
|
|
34
37
|
for node in func_node_body:
|
35
38
|
if isinstance(node, ast.If):
|
36
39
|
condition_str = self.parse_condition(node.test)
|
37
|
-
|
40
|
+
self.logger.debug(f"Condition found in function: {condition_str}")
|
38
41
|
self.get_conditions_recursively(function_metadata, func_name, node.body, param_names, test_cases, conditions + [condition_str])
|
39
42
|
if node.orelse:
|
40
43
|
self.get_conditions_recursively(function_metadata, func_name, node.orelse, param_names, test_cases, conditions)
|
@@ -61,8 +61,8 @@ class FuzzAnalyzer(TestCaseAnalyzerStrategy, ABC):
|
|
61
61
|
covered_branches = self.get_branch_coverage(module)
|
62
62
|
covered_branches_tuple = tuple(covered_branches)
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
self.logger.debug(f"[COVERED_BRANCHES]: {covered_branches}")
|
65
|
+
self.logger.debug(f"[EXECUTED BRANCHES]: {self.executed_branches}")
|
66
66
|
|
67
67
|
for branch in covered_branches:
|
68
68
|
if branch[1] < 0:
|
@@ -74,7 +74,7 @@ class RandomFeedbackAnalyzer(TestCaseAnalyzerStrategy, ABC):
|
|
74
74
|
break
|
75
75
|
else:
|
76
76
|
# Optionally log duplicate detection
|
77
|
-
|
77
|
+
self.logger.debug(f"Skipping duplicate test case: {func_name}{test_case.inputs}")
|
78
78
|
|
79
79
|
except Exception as e:
|
80
80
|
print(f"Error testing {function_metadata.function_name}: {e}")
|
@@ -97,10 +97,10 @@ class RandomFeedbackAnalyzer(TestCaseAnalyzerStrategy, ABC):
|
|
97
97
|
func.function_name, test_case.inputs)
|
98
98
|
covered = coverage_utils.get_list_of_covered_statements(analysis)
|
99
99
|
self.covered_lines[func.function_name].update(covered)
|
100
|
-
|
100
|
+
self.logger.debug(f"Covered lines for {func.function_name}: {self.covered_lines[func.function_name]}")
|
101
101
|
|
102
102
|
executable_statements = set(self.get_all_executable_statements(func))
|
103
|
-
|
103
|
+
self.logger.debug(f"Executable statements for {func.function_name}: {executable_statements}")
|
104
104
|
|
105
105
|
return self.covered_lines[func.function_name] == executable_statements
|
106
106
|
|
@@ -5,10 +5,12 @@ from typing import List, Dict
|
|
5
5
|
from testgen.models.test_case import TestCase
|
6
6
|
from testgen.models.analysis_context import AnalysisContext
|
7
7
|
from testgen.models.function_metadata import FunctionMetadata
|
8
|
+
from testgen.service.logging_service import get_logger
|
8
9
|
|
9
10
|
class TestCaseAnalyzerStrategy(ABC):
|
10
11
|
def __init__(self, analysis_context: AnalysisContext = None):
|
11
12
|
self._analysis_context = analysis_context
|
13
|
+
self.logger = get_logger()
|
12
14
|
|
13
15
|
@abstractmethod
|
14
16
|
def collect_test_cases(self, function_metadata: FunctionMetadata) -> List[TestCase]:
|
@@ -0,0 +1,146 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
|
4
|
+
def bin_and(a: bool, b: bool) ->bool:
|
5
|
+
"""
|
6
|
+
>>> bin_and(True, False)
|
7
|
+
False
|
8
|
+
|
9
|
+
>>> bin_and(False, True)
|
10
|
+
False
|
11
|
+
|
12
|
+
>>> bin_and(False, False)
|
13
|
+
False
|
14
|
+
|
15
|
+
>>> bin_and(True, True)
|
16
|
+
True
|
17
|
+
"""
|
18
|
+
if a == True:
|
19
|
+
if b == True:
|
20
|
+
return True
|
21
|
+
else:
|
22
|
+
return False
|
23
|
+
else:
|
24
|
+
return False
|
25
|
+
|
26
|
+
|
27
|
+
def bin_xor(a: bool, b: bool) ->bool:
|
28
|
+
"""
|
29
|
+
>>> bin_xor(True, True)
|
30
|
+
False
|
31
|
+
|
32
|
+
>>> bin_xor(True, False)
|
33
|
+
True
|
34
|
+
|
35
|
+
>>> bin_xor(False, False)
|
36
|
+
False
|
37
|
+
|
38
|
+
>>> bin_xor(False, True)
|
39
|
+
True
|
40
|
+
"""
|
41
|
+
if a == True:
|
42
|
+
if b == True:
|
43
|
+
return False
|
44
|
+
else:
|
45
|
+
return True
|
46
|
+
elif b == True:
|
47
|
+
return True
|
48
|
+
else:
|
49
|
+
return False
|
50
|
+
|
51
|
+
|
52
|
+
def status_flags(active: bool, verified: bool, admin: bool) ->str:
|
53
|
+
"""
|
54
|
+
>>> status_flags(False, False, False)
|
55
|
+
'inactive'
|
56
|
+
|
57
|
+
>>> status_flags(False, False, True)
|
58
|
+
'admin-unverified'
|
59
|
+
|
60
|
+
>>> status_flags(True, True, False)
|
61
|
+
'user-verified'
|
62
|
+
|
63
|
+
>>> status_flags(True, True, True)
|
64
|
+
'admin-verified'
|
65
|
+
|
66
|
+
>>> status_flags(True, False, False)
|
67
|
+
'user-unverified'
|
68
|
+
|
69
|
+
>>> status_flags(False, True, True)
|
70
|
+
'admin-verified'
|
71
|
+
|
72
|
+
>>> status_flags(False, True, False)
|
73
|
+
'inactive'
|
74
|
+
|
75
|
+
>>> status_flags(True, False, True)
|
76
|
+
'admin-unverified'
|
77
|
+
"""
|
78
|
+
if admin:
|
79
|
+
if verified:
|
80
|
+
return 'admin-verified'
|
81
|
+
else:
|
82
|
+
return 'admin-unverified'
|
83
|
+
elif active:
|
84
|
+
if verified:
|
85
|
+
return 'user-verified'
|
86
|
+
else:
|
87
|
+
return 'user-unverified'
|
88
|
+
else:
|
89
|
+
return 'inactive'
|
90
|
+
|
91
|
+
|
92
|
+
"""def half_adder(a: bool, b: bool) ->tuple:
|
93
|
+
sum: bool = bin_xor(a, b)
|
94
|
+
carry: bool = bin_and(a, b)
|
95
|
+
return sum, carry
|
96
|
+
|
97
|
+
|
98
|
+
def full_adder(a: bool, b: bool, carry_in: bool) ->tuple:
|
99
|
+
sum1, carry = half_adder(a, b)
|
100
|
+
sum2, carry_out = half_adder(sum1, carry_in)
|
101
|
+
return sum2, carry or carry_out
|
102
|
+
|
103
|
+
|
104
|
+
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
105
|
+
x_bits: List[int] = bit_converter(x)
|
106
|
+
y_bits: List[int] = bit_converter(y)
|
107
|
+
result: List[int] = [0] * 32
|
108
|
+
carry: bool = False
|
109
|
+
for i in range(32):
|
110
|
+
try:
|
111
|
+
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
112
|
+
result[i] = sum_bit
|
113
|
+
except IndexError as e:
|
114
|
+
print(f'Index Out of Bounds Error In ThirtyTwoBitAdder: {e}')
|
115
|
+
result = [1] * 32
|
116
|
+
if carry:
|
117
|
+
return OverflowError('Sum exceeds 32 bits')
|
118
|
+
return result
|
119
|
+
|
120
|
+
|
121
|
+
def thirty_two_bit_adder(x: int, y: int) ->List[int]:
|
122
|
+
print(x.bit_length() - 1)
|
123
|
+
print(y.bit_length() - 1)
|
124
|
+
x_bits: List[int] = bit_converter(x)
|
125
|
+
y_bits: List[int] = bit_converter(y)
|
126
|
+
result: List[int] = [0] * 32
|
127
|
+
carry: bool = False
|
128
|
+
for i in range(32):
|
129
|
+
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
130
|
+
result[i] = sum_bit
|
131
|
+
return result
|
132
|
+
|
133
|
+
def bit_converter(num: int) ->List[int]:
|
134
|
+
binary_str: str = bin(num)[2:]
|
135
|
+
print(bin(num)[2:])
|
136
|
+
return [int(digit) for digit in binary_str]
|
137
|
+
|
138
|
+
def thirty_two_bit_adder_excep(x: int, y: int) ->List[int]:
|
139
|
+
x_bits: List[int] = bit_converter(x)
|
140
|
+
y_bits: List[int] = bit_converter(y)
|
141
|
+
result: List[int] = [0] * 32
|
142
|
+
carry: bool = False
|
143
|
+
for i in range(32):
|
144
|
+
sum_bit, carry = full_adder(x_bits[i], y_bits[i], carry)
|
145
|
+
result[i] = sum_bit
|
146
|
+
return result"""
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class AdvancedCalculator:
|
2
|
+
|
3
|
+
def evaluate(self, a: int, b: int, op: str) ->(int | float | str):
|
4
|
+
""">>> AdvancedCalculator().evaluate(16, 56, 'abc')
|
5
|
+
'invalid'"""
|
6
|
+
if op == 'add':
|
7
|
+
return a + b
|
8
|
+
elif op == 'sub':
|
9
|
+
return a - b
|
10
|
+
elif op == 'mul':
|
11
|
+
return a * b
|
12
|
+
elif op == 'div':
|
13
|
+
if b == 0:
|
14
|
+
return 'undefined'
|
15
|
+
return a / b
|
16
|
+
else:
|
17
|
+
return 'invalid'
|
18
|
+
|
19
|
+
def is_in_range(self, val: float) ->str:
|
20
|
+
""">>> AdvancedCalculator().is_in_range(0.4023417704905361)
|
21
|
+
'fractional'"""
|
22
|
+
if val < 0.0:
|
23
|
+
return 'below zero'
|
24
|
+
elif 0.0 <= val < 1.0:
|
25
|
+
return 'fractional'
|
26
|
+
elif 1.0 <= val <= 100.0:
|
27
|
+
return 'valid'
|
28
|
+
else:
|
29
|
+
return 'out of range'
|