From 6e7410add6b30d4442e2b5babda3ceb49c064a53 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 01:01:34 -0400 Subject: [PATCH 001/165] Initial commit --- .gitignore | 1 + README.md | 1 + src/unit_test_generator.py | 24 +++++- tests/all_types/coverage_str_helper.json | 70 ++++++++-------- ... => test_coverage_str_helper_all_types.py} | 2 +- tests/all_types/test_get_item_at_index.py | 2 +- ...bal.py => test_update_global_all_types.py} | 0 tests/all_types/update_global.json | 44 +++++----- tests/fizzbuzz/coverage_str_helper.json | 82 ++++++++++--------- tests/fizzbuzz/normalize_arg.json | 36 ++++---- ...y => test_coverage_str_helper_fizzbuzz.py} | 14 ++-- ..._arg.py => test_normalize_arg_fizzbuzz.py} | 2 +- ...obal.py => test_update_global_fizzbuzz.py} | 2 +- tests/fizzbuzz/update_global.json | 56 ++++++------- tests/oo_car/coverage_str_helper.json | 70 ++++++++-------- tests/oo_car/normalize_arg.json | 36 ++++---- ....py => test_coverage_str_helper_oo_car.py} | 2 +- ...ze_arg.py => test_normalize_arg_oo_car.py} | 2 +- ...global.py => test_update_global_oo_car.py} | 0 tests/oo_car/update_global.json | 44 +++++----- tests/pass_by_assignment/normalize_arg.json | 36 ++++---- .../test_add_to_my_set_kwargs.py | 2 +- tests/pass_by_assignment/test_append_list.py | 2 +- .../test_increment_my_list_kwargs.py | 2 +- ... test_normalize_arg_pass_by_assignment.py} | 2 +- .../pass_by_assignment/test_overwrite_list.py | 2 +- ... test_update_global_pass_by_assignment.py} | 0 tests/pass_by_assignment/update_global.json | 44 +++++----- .../coverage_str_helper.json | 82 ++++++++++--------- tests/procedural_division/normalize_arg.json | 36 ++++---- ...overage_str_helper_procedural_division.py} | 14 ++-- tests/procedural_division/test_divide_ints.py | 18 +--- ...test_normalize_arg_procedural_division.py} | 2 +- ...test_update_global_procedural_division.py} | 2 +- tests/procedural_division/update_global.json | 56 ++++++------- tests/test_all.py | 11 --- 36 files changed, 403 insertions(+), 398 deletions(-) rename tests/all_types/{test_coverage_str_helper.py => test_coverage_str_helper_all_types.py} (95%) rename tests/all_types/{test_update_global.py => test_update_global_all_types.py} (100%) rename tests/fizzbuzz/{test_coverage_str_helper.py => test_coverage_str_helper_fizzbuzz.py} (71%) rename tests/fizzbuzz/{test_normalize_arg.py => test_normalize_arg_fizzbuzz.py} (97%) rename tests/fizzbuzz/{test_update_global.py => test_update_global_fizzbuzz.py} (97%) rename tests/oo_car/{test_coverage_str_helper.py => test_coverage_str_helper_oo_car.py} (94%) rename tests/oo_car/{test_normalize_arg.py => test_normalize_arg_oo_car.py} (95%) rename tests/oo_car/{test_update_global.py => test_update_global_oo_car.py} (100%) rename tests/pass_by_assignment/{test_normalize_arg.py => test_normalize_arg_pass_by_assignment.py} (95%) rename tests/pass_by_assignment/{test_update_global.py => test_update_global_pass_by_assignment.py} (100%) rename tests/procedural_division/{test_coverage_str_helper.py => test_coverage_str_helper_procedural_division.py} (71%) rename tests/procedural_division/{test_normalize_arg.py => test_normalize_arg_procedural_division.py} (97%) rename tests/procedural_division/{test_update_global.py => test_update_global_procedural_division.py} (97%) delete mode 100644 tests/test_all.py diff --git a/.gitignore b/.gitignore index 52fcedb..ac1d39d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ settings.json #tests/*/*.json tests/*/.coverage feedback.pdf +.coverage # https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore diff --git a/README.md b/README.md index 1105edc..84b6fec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/coverage.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) +![Coverage Status](https://img.shields.io/codecov/c/github/jahatfi/ddt) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 Notes: diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 7b3fad0..ff72f53 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -63,6 +63,10 @@ logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) +# FUNCTIONS is a set of all function names in this file, to be populated +# at the end of this file +FUNCTIONS = set() + recursion_depth_per_decoratee: dict[str, int] = defaultdict(int) def fullname(o:object)->str: @@ -954,10 +958,10 @@ def iterator_helper(self, function_name = self.this_metadata.name for arg_i, (arg_name, arg) in enumerate(args_dict.items()): if mode == "After": - + if ((which_args == "args" and id(arg) != self.args_addresses[arg_name]) or \ - (which_args == "kwargs" and id(arg) != self.kwargs_addresses[arg_name])): - logger.info("Discarding param #%d: %s for 'after' comparison, address has changed", + (which_args == "kwargs" and id(arg) != self.kwargs_addresses[arg_name])): + logger.info("Discarding param #%d: %s for 'after' comparison, address has changed", arg_i, arg) continue if isinstance(arg, (int, str, float)): @@ -1607,7 +1611,10 @@ def generate_all_tests_and_metadata_helper( local_all_metadata:defaultdict[str, continue local_all_metadata[function_name].coverage_io = {k:v for k,v in local_all_metadata[function_name].coverage_io.items() if v.testable} - result_file_str = f"test_{function_name.lower()}".replace('.','_') + ".py" + if function_name in FUNCTIONS: + result_file_str = f"test_{function_name.lower()}_{os.path.basename(os.getcwd())}".replace('.','_') + ".py" + else: + result_file_str = f"test_{function_name.lower()}".replace('.','_') + ".py" result_file_str = re.sub("__init__", "constructor", result_file_str) result_file = tests_dir.joinpath(result_file_str) @@ -2394,3 +2401,12 @@ def auto_generate_tests(function_metadata:FunctionMetaData, h = hashlib.new('sha256') h.update(str(sorted(test_str_list_def_dict.items())).encode()) return h.digest().hex() + +# REF: https://stackoverflow.com/questions/18451541 +copyied_locals = dict(locals()) +for key, value in copyied_locals.items(): + value = str(value) + if value.startswith(" Date: Sat, 12 Oct 2024 01:16:45 -0400 Subject: [PATCH 002/165] readme --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 84b6fec..bd0fced 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) -![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/coverage.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) -![Coverage Status](https://img.shields.io/codecov/c/github/jahatfi/ddt) - #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 Notes: From 6fffea53b42afa4c6266279e7f36b281d262b4be Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 01:18:30 -0400 Subject: [PATCH 003/165] Gen coerage report --- .github/workflows/python-app-ubuntu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 8eb8240..3543fe3 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -112,4 +112,5 @@ jobs: run: | poetry add coverage-badge poetry run coverage run -m pytest . + poetry run coverage report -m poetry run coverage-badge -o coverage.svg From a9256010e9605b977abae35cfb400a46649e0c28 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 01:29:30 -0400 Subject: [PATCH 004/165] Update python-app-ubuntu.yml Deduplicate pytest runs --- .github/workflows/python-app-ubuntu.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 3543fe3..cfc91b6 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -78,35 +78,35 @@ jobs: run: | cd tests/procedural_division poetry run python divide_ints.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz # continue-on-error: true run: | cd tests/fizzbuzz poetry run python fizzbuzz.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types # continue-on-error: true run: | cd tests/all_types poetry run python all_types.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest oo_car # continue-on-error: true run: | cd tests/oo_car poetry run python car.py - poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment # continue-on-error: true run: | cd tests/pass_by_assignment poetry run python pass_by_assignment.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest coverage badge run: | From 648c306f5d98f972e31c3887b7433afeec79119f Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 01:47:00 -0400 Subject: [PATCH 005/165] Update python-app-ubuntu.yml Omit test files from coverage --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index cfc91b6..18145bd 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -112,5 +112,5 @@ jobs: run: | poetry add coverage-badge poetry run coverage run -m pytest . - poetry run coverage report -m + poetry run coverage report -m --omit="*test_" poetry run coverage-badge -o coverage.svg From 77c5accda6133899115324c78f98514a4f4a4123 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 01:51:14 -0400 Subject: [PATCH 006/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 18145bd..db4ed8f 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -112,5 +112,5 @@ jobs: run: | poetry add coverage-badge poetry run coverage run -m pytest . - poetry run coverage report -m --omit="*test_" + poetry run coverage report -m --omit="*test_*" poetry run coverage-badge -o coverage.svg From 70f161da89810565383da0eaf7c363820b2fc8a0 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 01:58:54 -0400 Subject: [PATCH 007/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index db4ed8f..1d5c3ef 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -112,5 +112,5 @@ jobs: run: | poetry add coverage-badge poetry run coverage run -m pytest . - poetry run coverage report -m --omit="*test_*" + poetry run coverage report -m --omit="*/test_*" poetry run coverage-badge -o coverage.svg From 197e1aae99709d3909710f155f17844cc839b8f1 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 17:22:04 -0400 Subject: [PATCH 008/165] Update unit_test_generator.py Log the coverage --- src/unit_test_generator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index ff72f53..85435fa 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -1252,6 +1252,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, cov.json_report(outfile='-') # result will not exist if the function threw an exception cov_report_ = json.loads(stdout_lines[0]) + logger.critical(cov_report_) expected_type = str(type(result)) parsed_type = re.match("", expected_type) if parsed_type: From 3e13d431b0eee2e0f26d8e3301c487f5e4497618 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 20:22:22 -0400 Subject: [PATCH 009/165] Update fizzbuzz.py Show coverage --- tests/fizzbuzz/fizzbuzz.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 8da3798..6e95591 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -6,11 +6,13 @@ import logging import os from pathlib import Path +import coverage from src import unit_test_generator from src.unit_test_generator import ( generate_all_tests_and_metadata, unit_test_generator_decorator, + Capturing ) FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s' @@ -61,14 +63,21 @@ def main(): Begin ad hoc tests """ global mode # pylint: disable=global-statement - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = 'buzzfizz' - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = "a_test" - print(fizzbuzz(6)) - + cov = coverage.Coverage(): + with cov.collect(): + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = 'buzzfizz' + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = "a_test" + print(fizzbuzz(6)) + + with Capturing() as stdout_lines: + cov.json_report(outfile='-') + + logger.critical(json.loads(stdout_lines[0]) + # The generate_all_tests_and_metadata() function takes 2 Paths: # 1. The output directory for the unit tests (.py) # 2. The output directory for the .json files (I/O for each test) From cdd1d1700a604eefa1d634ba525bfcb0e19bf889 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 20:27:11 -0400 Subject: [PATCH 010/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 6e95591..310ac83 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -63,7 +63,7 @@ def main(): Begin ad hoc tests """ global mode # pylint: disable=global-statement - cov = coverage.Coverage(): + cov = coverage.Coverage(None) with cov.collect(): print(fizzbuzz(6)) print(fizzbuzz(30)) From 3a50a3579a42115bfe62e6376ec81393a40a67b7 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 20:29:23 -0400 Subject: [PATCH 011/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 310ac83..10753f9 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -76,7 +76,7 @@ def main(): with Capturing() as stdout_lines: cov.json_report(outfile='-') - logger.critical(json.loads(stdout_lines[0]) + logger.critical(json.loads(stdout_lines[0])) # The generate_all_tests_and_metadata() function takes 2 Paths: # 1. The output directory for the unit tests (.py) From 2dc390f30813f7630d629a73db25afb2b12e0b38 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 20:31:51 -0400 Subject: [PATCH 012/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 10753f9..7615cca 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -7,6 +7,7 @@ import os from pathlib import Path import coverage +import json from src import unit_test_generator from src.unit_test_generator import ( From 103f4b1f9f3af0744fb4942c83cbce3c95affc47 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 20:38:00 -0400 Subject: [PATCH 013/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 7615cca..ebc46ff 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -76,6 +76,7 @@ def main(): with Capturing() as stdout_lines: cov.json_report(outfile='-') + logger.critical(stdout_lines) logger.critical(json.loads(stdout_lines[0])) From 54ffc13c1debea2efe7921f3a8399d5dfbad7ae4 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 22:33:18 -0400 Subject: [PATCH 014/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index ebc46ff..a4cf15b 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -76,9 +76,10 @@ def main(): with Capturing() as stdout_lines: cov.json_report(outfile='-') - logger.critical(stdout_lines) - - logger.critical(json.loads(stdout_lines[0])) + # result will not exist if the function threw an exception + cov_report_ = json.loads(stdout_lines) + logger.critical(cov_report_) + # The generate_all_tests_and_metadata() function takes 2 Paths: # 1. The output directory for the unit tests (.py) From e68a40f13d7b04847392b076d540e81c55b2c5f6 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 12 Oct 2024 22:35:38 -0400 Subject: [PATCH 015/165] Update fizzbuzz.py --- tests/fizzbuzz/fizzbuzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index a4cf15b..22ecd21 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -77,7 +77,7 @@ def main(): with Capturing() as stdout_lines: cov.json_report(outfile='-') # result will not exist if the function threw an exception - cov_report_ = json.loads(stdout_lines) + cov_report_ = json.loads(stdout_lines[0]) logger.critical(cov_report_) From ba37b5d76b914af39147f99333f6cd393f45d11d Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:13:10 -0400 Subject: [PATCH 016/165] OO and fizzbuzz combined --- .github/workflows/python-app-ubuntu.yml | 8 +++++--- tests/fizzbuzz/fizzbuzz.py | 6 +++--- tests/oo_car/car.py | 9 ++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 1d5c3ef..f6325ff 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -85,7 +85,7 @@ jobs: run: | cd tests/fizzbuzz poetry run python fizzbuzz.py - #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types # continue-on-error: true @@ -99,7 +99,7 @@ jobs: run: | cd tests/oo_car poetry run python car.py - #poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment # continue-on-error: true @@ -111,6 +111,8 @@ jobs: - name: pytest coverage badge run: | poetry add coverage-badge - poetry run coverage run -m pytest . + poetry run coverage combine tests/fizzbuzz tests/oo_car + ls -lah + #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" poetry run coverage-badge -o coverage.svg diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 22ecd21..304be3e 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -64,7 +64,7 @@ def main(): Begin ad hoc tests """ global mode # pylint: disable=global-statement - cov = coverage.Coverage(None) + cov = coverage.Coverage("../.coverage") with cov.collect(): print(fizzbuzz(6)) print(fizzbuzz(30)) @@ -73,13 +73,13 @@ def main(): print(fizzbuzz(30)) mode = "a_test" print(fizzbuzz(6)) - + ''' with Capturing() as stdout_lines: cov.json_report(outfile='-') # result will not exist if the function threw an exception cov_report_ = json.loads(stdout_lines[0]) logger.critical(cov_report_) - + ''' # The generate_all_tests_and_metadata() function takes 2 Paths: # 1. The output directory for the unit tests (.py) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 05ce47c..65f9428 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -6,6 +6,7 @@ import logging import os from pathlib import Path +import coverage from src import unit_test_generator from src.unit_test_generator import ( @@ -209,9 +210,11 @@ def main(): Call test functions for Car class, then generate test files for each method. """ - first_test() - second_test() - generate_all_tests_and_metadata(Path('.'), Path('.')) + cov = coverage.Coverage("../.coverage") + with cov.collect(): + first_test() + second_test() + generate_all_tests_and_metadata(Path('.'), Path('.')) if __name__ == "__main__": From c08fd63c9a1dff18033063d3ec72f7edb54cbbe1 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:19:52 -0400 Subject: [PATCH 017/165] ls --- .github/workflows/python-app-ubuntu.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index f6325ff..0d58b1d 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -110,6 +110,9 @@ jobs: - name: pytest coverage badge run: | + ls -lah + ls -lah tests/fizzbuzz + ls -lah tests/oo_car poetry add coverage-badge poetry run coverage combine tests/fizzbuzz tests/oo_car ls -lah From 0b4f1fc31046f618bdda6c9a207f7a25f12e5c1f Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:31:58 -0400 Subject: [PATCH 018/165] Keep the file here --- tests/fizzbuzz/fizzbuzz.py | 2 +- tests/oo_car/car.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 304be3e..e594b4d 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -64,7 +64,7 @@ def main(): Begin ad hoc tests """ global mode # pylint: disable=global-statement - cov = coverage.Coverage("../.coverage") + cov = coverage.Coverage() with cov.collect(): print(fizzbuzz(6)) print(fizzbuzz(30)) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 65f9428..f5d6ef2 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -210,7 +210,7 @@ def main(): Call test functions for Car class, then generate test files for each method. """ - cov = coverage.Coverage("../.coverage") + cov = coverage.Coverage() with cov.collect(): first_test() second_test() From 99ca6e785ce2eb0db08ad0d26bdaf1bfef3684de Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:40:04 -0400 Subject: [PATCH 019/165] Save file --- tests/fizzbuzz/fizzbuzz.py | 1 + tests/oo_car/car.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index e594b4d..a04ba97 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -73,6 +73,7 @@ def main(): print(fizzbuzz(30)) mode = "a_test" print(fizzbuzz(6)) + cov.save() ''' with Capturing() as stdout_lines: cov.json_report(outfile='-') diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index f5d6ef2..0c50707 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -215,6 +215,7 @@ def main(): first_test() second_test() generate_all_tests_and_metadata(Path('.'), Path('.')) + cov.save() if __name__ == "__main__": From 876e9c92244e97d83afe017a0d0241e87d1c2612 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:42:24 -0400 Subject: [PATCH 020/165] combine --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 0d58b1d..489c399 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -114,7 +114,7 @@ jobs: ls -lah tests/fizzbuzz ls -lah tests/oo_car poetry add coverage-badge - poetry run coverage combine tests/fizzbuzz tests/oo_car + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" From 1c4d4ec0a378819fe08bc7dc1293ed20f3fcf949 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sat, 12 Oct 2024 23:46:47 -0400 Subject: [PATCH 021/165] Consolidated --- src/unit_test_generator.py | 1 - tests/fizzbuzz/fizzbuzz.py | 25 +++++++++++++------------ tests/oo_car/car.py | 16 +++++++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 85435fa..ff72f53 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -1252,7 +1252,6 @@ def do_the_decorator_thing(func: Callable, function_name:str, cov.json_report(outfile='-') # result will not exist if the function threw an exception cov_report_ = json.loads(stdout_lines[0]) - logger.critical(cov_report_) expected_type = str(type(result)) parsed_type = re.match("", expected_type) if parsed_type: diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index a04ba97..a019832 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -64,16 +64,15 @@ def main(): Begin ad hoc tests """ global mode # pylint: disable=global-statement - cov = coverage.Coverage() - with cov.collect(): - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = 'buzzfizz' - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = "a_test" - print(fizzbuzz(6)) - cov.save() + + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = 'buzzfizz' + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = "a_test" + print(fizzbuzz(6)) + ''' with Capturing() as stdout_lines: cov.json_report(outfile='-') @@ -126,5 +125,7 @@ def main(): # Decorating all functions programmatically is left as an exercise to the reader: # Hint: https://stackoverflow.com/questions/3467526/ #fizzbuzz = unit_test_generator_decorator(not args.disable_unit_test_generation)(fizzbuzz) - - main() + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 0c50707..7e91a95 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -210,12 +210,10 @@ def main(): Call test functions for Car class, then generate test files for each method. """ - cov = coverage.Coverage() - with cov.collect(): - first_test() - second_test() - generate_all_tests_and_metadata(Path('.'), Path('.')) - cov.save() + + first_test() + second_test() + generate_all_tests_and_metadata(Path('.'), Path('.')) if __name__ == "__main__": @@ -261,4 +259,8 @@ def main(): Car.change_steer_angle = unit_test_generator_decorator(110, 100, True)(Car.change_steer_angle) Car.is_going_faster_than = unit_test_generator_decorator(110, 110)(Car.is_going_faster_than) Car.__init__ = unit_test_generator_decorator(110, 110)(Car.__init__) - main() + + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() From ffab0003175eb3f90f92f168f1ec190c56b35827 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 13 Oct 2024 00:09:14 -0400 Subject: [PATCH 022/165] Combine all? --- tests/all_types/all_types.py | 7 ++++++- .../pass_by_assignment/pass_by_assignment.py | 21 ++++++++++++------- tests/procedural_division/divide_ints.py | 7 ++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/tests/all_types/all_types.py b/tests/all_types/all_types.py index 54d7de5..e73f0a7 100644 --- a/tests/all_types/all_types.py +++ b/tests/all_types/all_types.py @@ -7,6 +7,8 @@ import os from pathlib import Path +import coverage + from src import unit_test_generator from src.unit_test_generator import ( generate_all_tests_and_metadata, @@ -146,4 +148,7 @@ def main(): # get_key_to_set_with_highest_value = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_key_to_set_with_highest_value) # pylint: disable=line-too-long # get_item_at_index = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_item_at_index) # pylint: disable=line-too-long - main() + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() diff --git a/tests/pass_by_assignment/pass_by_assignment.py b/tests/pass_by_assignment/pass_by_assignment.py index 47b9552..1f5f1fd 100644 --- a/tests/pass_by_assignment/pass_by_assignment.py +++ b/tests/pass_by_assignment/pass_by_assignment.py @@ -8,6 +8,8 @@ from pathlib import Path from typing import Any, List, TypeVar +import coverage + from src import unit_test_generator from src.unit_test_generator import ( generate_all_tests_and_metadata, @@ -23,7 +25,7 @@ def __init__(self, name): def __repr__(self): return f"ClassForTesting('{self.name}')" - + def __eq__(self, __value: Any) -> bool: return self.name == __value.name @@ -40,7 +42,7 @@ def append_list(this_list:List[Any], item:Any)->None: """ logger.info("APPEND %s to %s", item, this_list) this_list.append(item) - + @unit_test_generator_decorator(sample_count=6, keep_subsets=True, percent_coverage=0) def overwrite_list(this_list:List[Any])->None: @@ -69,7 +71,7 @@ def add_to_my_set_kwargs(**kwargs): """ if "my_set" in kwargs and isinstance(kwargs["my_set"], set): kwargs["my_set"].add(1) - + def main(): """ @@ -77,7 +79,7 @@ def main(): """ # Begin ad hoc tests # Test append_list - + my_list = [1,2,3,4] append_list(my_list, 6) overwrite_list(my_list[::-1]) @@ -86,13 +88,13 @@ def main(): print(f"Before: {kwargs=}") increment_my_list_kwargs(**kwargs) print(f"After: {kwargs=}") - - + + kwargs = {} kwargs["my_set"] = set([0,2,3]) add_to_my_set_kwargs(**kwargs) print(f"After: {kwargs=}") - + generate_all_tests_and_metadata(Path("."), Path(".")) if __name__ == "__main__": @@ -141,4 +143,7 @@ def main(): # get_key_to_set_with_highest_value = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_key_to_set_with_highest_value) # pylint: disable=line-too-long # get_item_at_index = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_item_at_index) # pylint: disable=line-too-long - main() + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file diff --git a/tests/procedural_division/divide_ints.py b/tests/procedural_division/divide_ints.py index 570e7d0..950e69e 100644 --- a/tests/procedural_division/divide_ints.py +++ b/tests/procedural_division/divide_ints.py @@ -8,6 +8,8 @@ import time from pathlib import Path +import coverage + from src import unit_test_generator from src.unit_test_generator import ( generate_all_tests_and_metadata, @@ -105,4 +107,7 @@ def main(): # Hint: https://stackoverflow.com/questions/3467526/ divide_ints = unit_test_generator_decorator(percent_coverage=110)(divide_ints) - main() + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file From 178d5ab2bcb0e1f6eafe1be3b8e32ab3072c924c Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 13 Oct 2024 00:10:09 -0400 Subject: [PATCH 023/165] Combine all? --- .github/workflows/python-app-ubuntu.yml | 9 ++++++++- pyproject.toml | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 489c399..86f6855 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -108,13 +108,20 @@ jobs: poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + - name: pytest pass_by_assignment + # continue-on-error: true + run: | + cd src + poetry run coverage run -m pytest . + + - name: pytest coverage badge run: | ls -lah ls -lah tests/fizzbuzz ls -lah tests/oo_car poetry add coverage-badge - poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage src/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" diff --git a/pyproject.toml b/pyproject.toml index 889009f..79cf57d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,11 +25,6 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] -ignore=[ -"src", -"decorator", -"paper", -] norecursedirs=[ "src", "decorator", From 1ce2e63c249a516cc7a0ad82d1878f183d3b8ba8 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 13 Oct 2024 00:11:57 -0400 Subject: [PATCH 024/165] Fixed YAML Syntax error --- .github/workflows/python-app-ubuntu.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 86f6855..30b145f 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -109,10 +109,10 @@ jobs: #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment - # continue-on-error: true - run: | - cd src - poetry run coverage run -m pytest . + # continue-on-error: true + run: | + cd src + poetry run coverage run -m pytest . - name: pytest coverage badge From 680f53c42ead507dfbaff86872951659d2935099 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 13 Oct 2024 00:15:10 -0400 Subject: [PATCH 025/165] Fixed WindowsPath error --- .github/workflows/python-app-ubuntu.yml | 9 +-------- .github/workflows/python-app-windows.yml | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 30b145f..fcc5725 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -108,20 +108,13 @@ jobs: poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - name: pytest pass_by_assignment - # continue-on-error: true - run: | - cd src - poetry run coverage run -m pytest . - - - name: pytest coverage badge run: | ls -lah ls -lah tests/fizzbuzz ls -lah tests/oo_car poetry add coverage-badge - poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage src/.coverage + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index 0fcc453..32d8c42 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -98,3 +98,10 @@ jobs: poetry run python pass_by_assignment.py poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + - name: pytest pass_by_assignment + # continue-on-error: true + run: | + cd src + poetry run -m pytest . + + # TODO Get full coverage \ No newline at end of file From 1f2cb4d013d1b4290cf254e80b5e0506fb4c15e6 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 13 Oct 2024 00:22:55 -0400 Subject: [PATCH 026/165] Looking for .coverage files --- .github/workflows/python-app-ubuntu.yml | 7 +++++-- .github/workflows/python-app-windows.yml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index fcc5725..ce252da 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -111,8 +111,11 @@ jobs: - name: pytest coverage badge run: | ls -lah - ls -lah tests/fizzbuzz - ls -lah tests/oo_car + ls -h tests/fizzbuzz + ls -h tests/oo_car + ls -h tests/all_types + ls -h tests/procedural_division + ls -h tests/pass_by_assignment poetry add coverage-badge poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage ls -lah diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index 32d8c42..c3a933c 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -102,6 +102,6 @@ jobs: # continue-on-error: true run: | cd src - poetry run -m pytest . + poetry run pytest . # TODO Get full coverage \ No newline at end of file From f3623ccde1cbc74c088f9f5e5440999a9c154b8b Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:26:57 -0400 Subject: [PATCH 027/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index ce252da..63add50 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -111,11 +111,11 @@ jobs: - name: pytest coverage badge run: | ls -lah - ls -h tests/fizzbuzz - ls -h tests/oo_car - ls -h tests/all_types - ls -h tests/procedural_division - ls -h tests/pass_by_assignment + ls -lah tests/fizzbuzz + ls -lah tests/oo_car + ls -lah tests/all_types + ls -lah tests/procedural_division + ls -lah tests/pass_by_assignment poetry add coverage-badge poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage ls -lah From 1a032b2c55ad098f7550041d6c90264428884705 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:35:10 -0400 Subject: [PATCH 028/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 63add50..10245fa 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -117,7 +117,7 @@ jobs: ls -lah tests/procedural_division ls -lah tests/pass_by_assignment poetry add coverage-badge - poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/all_types/.coverage tests/procedural_division/.coverage + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" From 9ea8282b3d9e58ffdede2d5f2ab9d23386be618f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:44:32 -0400 Subject: [PATCH 029/165] Update python-app-windows.yml --- .github/workflows/python-app-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index c3a933c..991d8be 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -102,6 +102,6 @@ jobs: # continue-on-error: true run: | cd src - poetry run pytest . + poetry run pytest -s -v . # TODO Get full coverage \ No newline at end of file From 1f935f450489f2a88e72b7b24e6c78d467d0c381 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:48:47 -0400 Subject: [PATCH 030/165] Update unit_test_generator.py Logging --- src/unit_test_generator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index ff72f53..c0d62d1 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -662,12 +662,15 @@ def get_class_import_string(arg:typing.Any)->str: keep_file = None this_type = "" for file in files: + logger.debug(file) file_path = Path(file) if my_path.is_relative_to(file_path): keep_file = file_path this_type = f"{os.path.relpath(file_path, my_path)}" + logger.debug("this_type=%s", this_type) if keep_file: my_path_str = str(my_path)[len(str(keep_file)):] + logger.debug("my_path_str=%s", my_path_str) my_path_str = re.sub(r"^[\\/]", "", my_path_str) this_type = f'{re.sub(".py$", "", my_path_str)}.{arg.__class__.__qualname__}' this_type = re.sub(r"\\", ".", this_type) From d9a62d2d1e9ac82b5bbb9e3528cdaee1f2ff6624 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:51:51 -0400 Subject: [PATCH 031/165] Update python-app-windows.yml --- .github/workflows/python-app-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index 991d8be..4a0a5fb 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -102,6 +102,6 @@ jobs: # continue-on-error: true run: | cd src - poetry run pytest -s -v . + poetry run pytest --log-level=DEBUG -s -v . # TODO Get full coverage \ No newline at end of file From 53581627a11f35151e6c5db4a4aca9f2503532ca Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:58:23 -0400 Subject: [PATCH 032/165] Update test_get_module_import_string.py --- src/test_get_module_import_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index d5fbef4..14466c9 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -24,11 +24,11 @@ [ ( WindowsPath( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" + "tests/oo_car/car.py" ), "tests.oo_car.car", { - "my_path": "WindowsPath('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py')" + "my_path": "WindowsPath('tests/oo_car/car.py')" }, ), ], From 36be3c8a2ef2455e02a067a2ea14ce2dda56853f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 00:58:50 -0400 Subject: [PATCH 033/165] Update python-app-windows.yml --- .github/workflows/python-app-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index 4a0a5fb..be80bd8 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -98,7 +98,7 @@ jobs: poetry run python pass_by_assignment.py poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - name: pytest pass_by_assignment + - name: pytest helper functions # continue-on-error: true run: | cd src From 6b432889abb0afcedf1802c260fe58369f66c5fd Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 01:50:21 -0400 Subject: [PATCH 034/165] Update unit_test_generator.py --- src/unit_test_generator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index c0d62d1..9f95199 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -629,21 +629,24 @@ def get_module_import_string(my_path:Path)->str: files = set(sorted(sys.path)) keep_file = None this_type = "" + logger.critical(f"{files=}") for file_str in files: file = Path(file_str) if my_path.is_relative_to(file): keep_file = file - logger.debug("os.path.relpath(file, my_path, )=%s", + logger.critical("os.path.relpath(file, my_path, )=%s", os.path.relpath(file, my_path, )) this_type = f"{os.path.relpath(file, my_path)}" + break if keep_file: my_path_str = str(my_path)[len(str(keep_file)):] my_path_str = re.sub(r"^[\\/]", "", my_path_str) + logger.critical(f"{my_path_str=}") this_type = re.sub(".py$", "", my_path_str) if not this_type: raise TypeError("Can't determine type") this_type = re.sub(r"\\", ".", this_type) - + logger.critical(f"{this_type=}") # Other other OS's use forward slashes this_type = re.sub(r"/", ".", this_type) From 552e9338b3da6546dd9c17522af3189cd5cf918d Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 07:00:45 -0400 Subject: [PATCH 035/165] Update unit_test_generator.py No break --- src/unit_test_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 9f95199..1d5f918 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -637,7 +637,7 @@ def get_module_import_string(my_path:Path)->str: logger.critical("os.path.relpath(file, my_path, )=%s", os.path.relpath(file, my_path, )) this_type = f"{os.path.relpath(file, my_path)}" - break + #break if keep_file: my_path_str = str(my_path)[len(str(keep_file)):] my_path_str = re.sub(r"^[\\/]", "", my_path_str) From eb83873cabf74e385ea1f44af7f5cb4324941c24 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 07:25:30 -0400 Subject: [PATCH 036/165] Update unit_test_generator.py --- src/unit_test_generator.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 1d5f918..b89136a 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -629,9 +629,10 @@ def get_module_import_string(my_path:Path)->str: files = set(sorted(sys.path)) keep_file = None this_type = "" + logger.critical(f"{my_path=}") logger.critical(f"{files=}") - for file_str in files: - file = Path(file_str) + for file in files: + #file = Path(file_str) if my_path.is_relative_to(file): keep_file = file logger.critical("os.path.relpath(file, my_path, )=%s", @@ -649,7 +650,8 @@ def get_module_import_string(my_path:Path)->str: logger.critical(f"{this_type=}") # Other other OS's use forward slashes this_type = re.sub(r"/", ".", this_type) - + else: + logger.critical("my_path not relative to any sys paths") return this_type #@unit_test_generator_decorator(sample_count=1) From 553e0e98afa1742736aa462a25c47f279bc3ad87 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 07:30:36 -0400 Subject: [PATCH 037/165] Update test_get_module_import_string.py --- src/test_get_module_import_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index 14466c9..28f69f1 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -24,11 +24,11 @@ [ ( WindowsPath( - "tests/oo_car/car.py" + "ddt/tests/oo_car/car.py" ), "tests.oo_car.car", { - "my_path": "WindowsPath('tests/oo_car/car.py')" + "my_path": "WindowsPath('ddt/tests/oo_car/car.py')" }, ), ], From 0dacf3a76900be9f399d20c3c94c3cb7560ffdb1 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 10:15:39 -0400 Subject: [PATCH 038/165] Update test_get_module_import_string.py OS agnostic path --- src/test_get_module_import_string.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index 28f69f1..6829cdf 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -6,6 +6,7 @@ import pytest from collections import OrderedDict from src import unit_test_generator +import pathlib # Now import modules specific to get_module_import_string: from logging import Manager @@ -13,7 +14,7 @@ from logging import StreamHandler from logging import RootLogger from logging import Logger -from pathlib import WindowsPath +#from pathlib import WindowsPath # In sum, these tests covered 85.0% of get_module_import_string's lines @@ -23,12 +24,10 @@ "my_path, expected_result, args_after", [ ( - WindowsPath( - "ddt/tests/oo_car/car.py" - ), + Path("ddt/tests/oo_car/car.py").absolute(), "tests.oo_car.car", { - "my_path": "WindowsPath('ddt/tests/oo_car/car.py')" + "my_path": "Path('ddt/tests/oo_car/car.py').absolute()" }, ), ], From 893c2bb7b61863b3787b8c8fd83761d45be1877a Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 10:25:53 -0400 Subject: [PATCH 039/165] Update test_get_module_import_string.py Import Path --- src/test_get_module_import_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index 6829cdf..ba8dfe6 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -6,7 +6,7 @@ import pytest from collections import OrderedDict from src import unit_test_generator -import pathlib +#import pathlib # Now import modules specific to get_module_import_string: from logging import Manager @@ -14,7 +14,7 @@ from logging import StreamHandler from logging import RootLogger from logging import Logger -#from pathlib import WindowsPath +from pathlib import Path # In sum, these tests covered 85.0% of get_module_import_string's lines From 3f4c0e4acc600d3b7aae2555bbd53bdacbb78f19 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 10:37:06 -0400 Subject: [PATCH 040/165] Update test_get_module_import_string.py Relative pathing --- src/test_get_module_import_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index ba8dfe6..27a291d 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -24,10 +24,10 @@ "my_path, expected_result, args_after", [ ( - Path("ddt/tests/oo_car/car.py").absolute(), + Path("../tests/oo_car/car.py").absolute(), "tests.oo_car.car", { - "my_path": "Path('ddt/tests/oo_car/car.py').absolute()" + "my_path": "Path('../tests/oo_car/car.py').absolute()" }, ), ], From 934af4cd0653aa5a8e6739bb0c642180e41e9030 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 10:47:18 -0400 Subject: [PATCH 041/165] Update test_get_module_import_string.py Resolve --- src/test_get_module_import_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_get_module_import_string.py b/src/test_get_module_import_string.py index 27a291d..9d900eb 100644 --- a/src/test_get_module_import_string.py +++ b/src/test_get_module_import_string.py @@ -24,10 +24,10 @@ "my_path, expected_result, args_after", [ ( - Path("../tests/oo_car/car.py").absolute(), + Path("../tests/oo_car/car.py").resolve(), "tests.oo_car.car", { - "my_path": "Path('../tests/oo_car/car.py').absolute()" + "my_path": "Path('../tests/oo_car/car.py').resolve()" }, ), ], From 1edb54e58f37f7d55cb9a01f109cafbc0d38d6a5 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 13:16:35 -0400 Subject: [PATCH 042/165] Update python-app-ubuntu.yml Include src tests --- .github/workflows/python-app-ubuntu.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 10245fa..56423af 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -108,6 +108,13 @@ jobs: poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest helper functions + # continue-on-error: true + run: | + cd src + poetry run coverage run -m pytest --log-level=DEBUG -s -v . + - name: pytest coverage badge run: | ls -lah @@ -117,7 +124,7 @@ jobs: ls -lah tests/procedural_division ls -lah tests/pass_by_assignment poetry add coverage-badge - poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" From 6ffaaf9706cba39cba547c741c7242bf48fbe11f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 13:24:13 -0400 Subject: [PATCH 043/165] Update test_auto_generate_tests copy.py Replaced WindowsPath with Path --- src/test_auto_generate_tests copy.py | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/test_auto_generate_tests copy.py b/src/test_auto_generate_tests copy.py index ea9cc21..385dcbe 100644 --- a/src/test_auto_generate_tests copy.py +++ b/src/test_auto_generate_tests copy.py @@ -19,7 +19,7 @@ from collections import defaultdict from logging import RootLogger from logging import Logger -from pathlib import WindowsPath +from pathlib import Path ALL_METADATA = defaultdict( FunctionMetaData, @@ -46,7 +46,7 @@ non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, global_vars_read_from={"logger"}, global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" ), coverage_io={ @@ -141,20 +141,20 @@ non_code_lines={1426, 1444, 1446, 1434}, global_vars_read_from={"logger"}, global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" ), coverage_io={ "a957a0aed8423c01c38d1111e384806112a73d4876a082ea2ca1421a6a95602a": CoverageInfo( args_before=[ 'X', - "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=WindowsPath('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={})", + "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={})", ], args_after=OrderedDict( [ ( "this_metadata", - "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[41, 42, 43], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=WindowsPath('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={'__init__': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\tests\\\\oo_car\\\\car.py'})", + "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[41, 42, 43], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={'__init__': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\tests\\\\oo_car\\\\car.py'})", ) ] ), @@ -197,7 +197,7 @@ coverage_percentage=56.41, types_in_use={ "logging.Manager", - "pathlib.WindowsPath", + "pathlib.Path", "logging.Logger", "logging.StreamHandler", "src.unit_test_generator.FunctionMetaData", @@ -242,7 +242,7 @@ non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" ), coverage_io={ @@ -278,7 +278,7 @@ non_code_lines=set(), global_vars_read_from={"method_call_counter", "logger"}, global_vars_written_to={"method_call_counter"}, - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" ), coverage_io={ @@ -336,7 +336,7 @@ non_code_lines=set(), global_vars_read_from={"logger"}, global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" ), coverage_io={ @@ -379,7 +379,7 @@ non_code_lines={89, 82, 84, 85}, global_vars_read_from={"logger"}, global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" ), coverage_io={ @@ -467,7 +467,7 @@ non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" ), coverage_io={ @@ -528,7 +528,7 @@ non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, global_vars_read_from={"logger"}, global_vars_written_to=set(), - source_file=WindowsPath( + source_file=Path( "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" ), coverage_io={ @@ -605,19 +605,19 @@ ) }, "update_global", - WindowsPath( + Path( "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" ), - WindowsPath("."), - WindowsPath("."), + Path("."), + Path("."), 2, "252acc6c11e8af0020608482027ff01a094facec4dddd6c5b97a134d630b6692", { - "function_metadata": "FunctionMetaData(name='update_global', parameter_names=['obj', 'this_global', 'phase', 'this_coverage_info'], is_method=False, lines=[1599, 1600, 1601, 1602, 1603, 1604, 1605, 1607, 1615, 1616, 1617, 1618, 1619], non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, global_vars_read_from={'logger'}, global_vars_written_to=set(), source_file=WindowsPath('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py'), coverage_io={'bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9': CoverageInfo(args_before=['0', '\"method_call_counter\"', '\"Before\"', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'], args_after=OrderedDict([('this_coverage_info', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)')]), kwargs={}, kwargs_after=OrderedDict(), globals_before={}, globals_after={}, expected_result='CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)', expected_type='src.unit_test_generator.CoverageInfo', coverage=[1599, 1602, 1607, 1615, 1616, 1619], exception_type='', exception_message='', constructor='', cost=0.0)}, coverage_percentage=46.15, types_in_use={'logging.Manager', 'logging.RootLogger', 'logging.StreamHandler', 'logging.Logger', 'src.unit_test_generator.CoverageInfo', 'logging.PlaceHolder'}, unified_test_coverage={1602, 1607, 1615, 1616, 1619, 1599}, needs_pytest=False, callable_files={'update_global': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\src\\\\unit_test_generator.py'})", + "function_metadata": "FunctionMetaData(name='update_global', parameter_names=['obj', 'this_global', 'phase', 'this_coverage_info'], is_method=False, lines=[1599, 1600, 1601, 1602, 1603, 1604, 1605, 1607, 1615, 1616, 1617, 1618, 1619], non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, global_vars_read_from={'logger'}, global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py'), coverage_io={'bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9': CoverageInfo(args_before=['0', '\"method_call_counter\"', '\"Before\"', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'], args_after=OrderedDict([('this_coverage_info', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)')]), kwargs={}, kwargs_after=OrderedDict(), globals_before={}, globals_after={}, expected_result='CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)', expected_type='src.unit_test_generator.CoverageInfo', coverage=[1599, 1602, 1607, 1615, 1616, 1619], exception_type='', exception_message='', constructor='', cost=0.0)}, coverage_percentage=46.15, types_in_use={'logging.Manager', 'logging.RootLogger', 'logging.StreamHandler', 'logging.Logger', 'src.unit_test_generator.CoverageInfo', 'logging.PlaceHolder'}, unified_test_coverage={1602, 1607, 1615, 1616, 1619, 1599}, needs_pytest=False, callable_files={'update_global': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\src\\\\unit_test_generator.py'})", "state": "{'bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9': CoverageInfo(args_before=['0', '\"method_call_counter\"', '\"Before\"', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'], args_after={'this_coverage_info': 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'}, kwargs={}, kwargs_after=OrderedDict(), globals_before={}, globals_after={}, expected_result='CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)', expected_type='src.unit_test_generator.CoverageInfo', coverage=[1599, 1602, 1607, 1615, 1616, 1619], exception_type='', exception_message='', constructor='', cost=0.0)}", - "source_file": "WindowsPath('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py')", - "tests_dir": "WindowsPath('.')", - "outdir": "WindowsPath('.')", + "source_file": "Path('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py')", + "tests_dir": "Path('.')", + "outdir": "Path('.')", }, {}, ), From cc2e70c2435f47e244059c5d47ba9287645a6369 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 19:50:52 -0400 Subject: [PATCH 044/165] Update python-app-ubuntu.yml Genbadge --- .github/workflows/python-app-ubuntu.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 56423af..54160e1 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -123,9 +123,12 @@ jobs: ls -lah tests/all_types ls -lah tests/procedural_division ls -lah tests/pass_by_assignment - poetry add coverage-badge + poetry add coverage-badge + poetry run pip install[all] poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" + poetry run coverage xml --omit="*/test_*" poetry run coverage-badge -o coverage.svg + poetrt run genbadge coverage From 82c592d278202fe576f15c06256a4f35250dfbf5 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 19:51:14 -0400 Subject: [PATCH 045/165] Update README.md Gen badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bd0fced..aaf3282 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Coverage Status](./reports/coverage/coverage-badge.svg?dummy=8484744)](./reports/coverage/index.html) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 From cc270aef4f306c4a37a6963317ae90d04b97b5dd Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 20:05:41 -0400 Subject: [PATCH 046/165] Update python-app-ubuntu.yml Fixed typos --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 54160e1..0d4306c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -124,11 +124,11 @@ jobs: ls -lah tests/procedural_division ls -lah tests/pass_by_assignment poetry add coverage-badge - poetry run pip install[all] + poetry run pip install genbadge[all] poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" poetry run coverage xml --omit="*/test_*" poetry run coverage-badge -o coverage.svg - poetrt run genbadge coverage + poetry run genbadge coverage From 1f377c517851a68d0e630dfefffa312ca229fc75 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 20:35:27 -0400 Subject: [PATCH 047/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 0d4306c..d8328c2 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -130,5 +130,6 @@ jobs: #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" poetry run coverage xml --omit="*/test_*" + ls -lah poetry run coverage-badge -o coverage.svg - poetry run genbadge coverage + poetry run genbadge coverage -i coverage.xml From 2ca23b7623bcba9ec1012aef4323f7e0a0a51ce6 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 20:39:54 -0400 Subject: [PATCH 048/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index d8328c2..835a7ed 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -130,6 +130,7 @@ jobs: #poetry run coverage run -m pytest . poetry run coverage report -m --omit="*/test_*" poetry run coverage xml --omit="*/test_*" + poetry run coverage html ls -lah poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml From 7533612581f803773a9c0f29ffc92a4b72a9f642 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 20:54:27 -0400 Subject: [PATCH 049/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 835a7ed..52e148c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -132,5 +132,7 @@ jobs: poetry run coverage xml --omit="*/test_*" poetry run coverage html ls -lah + echo "HTML?" + ls -lah hrmlcov poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml From 319f49213b55d40858cfc12891cfbf637c57f8d1 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 20:56:42 -0400 Subject: [PATCH 050/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 52e148c..82c2a3c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -133,6 +133,6 @@ jobs: poetry run coverage html ls -lah echo "HTML?" - ls -lah hrmlcov + ls -lah htmlcov poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml From 9849ae53b3cd7789c5b7d32f9f245f4afdb7cb97 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 21:03:41 -0400 Subject: [PATCH 051/165] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aaf3282..f48dab5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Coverage Status](./reports/coverage/coverage-badge.svg?dummy=8484744)](./reports/coverage/index.html) +[![Coverage Status](./coverage-badge.svg?dummy=8484744)](./htmlcov/index.html) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 From cf4356a7a923da228bd0ceed06ebc611f655968d Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 21:12:03 -0400 Subject: [PATCH 052/165] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f48dab5..106b527 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Coverage Status](./coverage-badge.svg?dummy=8484744)](./htmlcov/index.html) +[![Coverage Status](./coverage-badge.svg?dummy=8484744)] ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 @@ -128,4 +128,4 @@ The test should assert the same exception is thrown. ## Paper TODO [ ] Add other examples to the repo -[ ] Last: Update section references, e.g. "In sectionV/% I'll discuss... \ No newline at end of file +[ ] Last: Update section references, e.g. "In sectionV/% I'll discuss... From f54830dc84c84cc5dec2c28f21b0f3471569420f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 13 Oct 2024 21:18:56 -0400 Subject: [PATCH 053/165] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 106b527..5dcc07d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Coverage Status](./coverage-badge.svg?dummy=8484744)] +![Coverage Status](./coverage-badge.svg?dummy=8484744) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 From 822d8429482234b514a618dc560ea08abd0b6145 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 06:38:57 -0400 Subject: [PATCH 054/165] Update get_color.sh --- get_color.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 get_color.sh diff --git a/get_color.sh b/get_color.sh new file mode 100644 index 0000000..8e6c72c --- /dev/null +++ b/get_color.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Chaptgpt + +# Check for the correct number of arguments +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Read input arguments +min_value=$1 +max_value=$2 +measured_value=$3 + +# Calculate the range +range=$(echo "$max_value - $min_value" | bc) + +# Calculate percentage of the measured value within the range +if [ $(echo "$range == 0" | bc) -eq 1 ]; then + echo "Error: The minimum and maximum values must be different." + exit 1 +fi + +percentage=$(echo "scale=4; ($measured_value - $min_value) / $range" | bc) + +# Determine the color based on the measured value +if (( $(echo "$percentage <= 0.5" | bc -l) )); then + echo "red" +elif (( $(echo "$percentage >= 1.0" | bc -l) )); then + echo "green" +else + # Calculate intervals + if (( $(echo "$percentage <= 0.6667" | bc -l) )); then + echo "orange" + elif (( $(echo "$percentage <= 0.8333" | bc -l) )); then + echo "yellow" + else + echo "lightgreen" + fi +fi From c7d8c221246d708947531f853c95187082ad2876 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 06:54:16 -0400 Subject: [PATCH 055/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 82c2a3c..bc4196c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -136,3 +136,30 @@ jobs: ls -lah htmlcov poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml + + name: Testing BYOB + steps: + - id: mypy + run: echo "##[set-output name=data;]$($MYPY_RESULT)" + run: echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + - id: pylint + run: echo "##[set-output name=data;]$($PYLINT_RESULT)" + run: echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: pylint + uses: RubbaBoy/BYOB@v1 + with: + NAME: pylint + LABEL: 'pylint' + STATUS: ${{ steps.pylint.outputs.data }} + COLOR: ${{ steps.pylint.outputs.color }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file From e90c62dfbd2856aa6db14a8f3e46b31af0bf3691 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 07:09:15 -0400 Subject: [PATCH 056/165] Update python-app-ubuntu.yml Tokens --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index bc4196c..42e8426 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -152,7 +152,7 @@ jobs: LABEL: 'mypy' STATUS: ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.color }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} - name: pylint uses: RubbaBoy/BYOB@v1 @@ -161,5 +161,5 @@ jobs: LABEL: 'pylint' STATUS: ${{ steps.pylint.outputs.data }} COLOR: ${{ steps.pylint.outputs.color }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} \ No newline at end of file From 46141ae6887563c4d40aaf97118b4954e4f2d237 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 07:11:22 -0400 Subject: [PATCH 057/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 42e8426..983e32c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -153,6 +153,8 @@ jobs: STATUS: ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} + REPOSITORY: ddt + ACTOR: ${{ github.actor }} - name: pylint uses: RubbaBoy/BYOB@v1 @@ -162,4 +164,5 @@ jobs: STATUS: ${{ steps.pylint.outputs.data }} COLOR: ${{ steps.pylint.outputs.color }} GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} - \ No newline at end of file + REPOSITORY: ddt + ACTOR: ${{ github.actor }} \ No newline at end of file From 5afe61df7f466bdd4780f1a15f3ade8b30b276d7 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 07:12:40 -0400 Subject: [PATCH 058/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 983e32c..156cbdd 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -153,7 +153,7 @@ jobs: STATUS: ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} - REPOSITORY: ddt + REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} - name: pylint @@ -164,5 +164,5 @@ jobs: STATUS: ${{ steps.pylint.outputs.data }} COLOR: ${{ steps.pylint.outputs.color }} GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} - REPOSITORY: ddt + REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} \ No newline at end of file From f9bade8db7f6e3918f240d7845ea814f8fc3374a Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 16:16:19 -0400 Subject: [PATCH 059/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 156cbdd..861d3be 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -152,7 +152,7 @@ jobs: LABEL: 'mypy' STATUS: ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.color }} - GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} + GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} @@ -163,6 +163,6 @@ jobs: LABEL: 'pylint' STATUS: ${{ steps.pylint.outputs.data }} COLOR: ${{ steps.pylint.outputs.color }} - GITHUB_TOKEN: ${{ secrets.ACTION.TOKEN }} + GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} \ No newline at end of file From 5796342df37d1591ff1da6fabe0f6d40fb4988cc Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Mon, 14 Oct 2024 22:21:17 -0400 Subject: [PATCH 060/165] Testing badge --- .github/workflows/python-app-ubuntu.yml | 22 ++++++++++++---------- README.md | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 861d3be..9247ebd 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -137,14 +137,18 @@ jobs: poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml - name: Testing BYOB - steps: + + - id: mypy - run: echo "##[set-output name=data;]$($MYPY_RESULT)" - run: echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + run: | + echo "##[set-output name=data;]$($MYPY_RESULT)" + echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + - id: pylint - run: echo "##[set-output name=data;]$($PYLINT_RESULT)" - run: echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + run: | + echo "##[set-output name=data;]$($PYLINT_RESULT)" + echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + - name: mypybadge uses: RubbaBoy/BYOB@v1 with: @@ -156,13 +160,11 @@ jobs: REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} - - name: pylint + - name: pylint badge uses: RubbaBoy/BYOB@v1 with: NAME: pylint LABEL: 'pylint' STATUS: ${{ steps.pylint.outputs.data }} COLOR: ${{ steps.pylint.outputs.color }} - GITHUB_TOKEN: ${{ secrets.DDT }} - REPOSITORY: ${{ github.actor }}/ddt - ACTOR: ${{ github.actor }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.DDT }} \ No newline at end of file diff --git a/README.md b/README.md index 5dcc07d..5a39c4a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ ![Coverage Status](./coverage-badge.svg?dummy=8484744) +![](https://byob.yarr.is/jahatfi/ddt/pylint) +![](https://byob.yarr.is/jahatfi/ddt/mypy) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-ubuntu.yml/badge.svg) ![CI](https://github.com/jahatfi/ddt/actions/workflows/python-app-windows.yml/badge.svg) #### TODO: Update this file - it's quite out of date as of 14 Sept 2024 From ac29796f7ff87a9f7a13188c8e221beb4e1f80a9 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 14 Oct 2024 23:32:21 -0400 Subject: [PATCH 061/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 9247ebd..1c77154 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -72,6 +72,7 @@ jobs: if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT fi + echo "MYPY_RESULT=$MYPY_RESULT" - name: pytest procedural_division # continue-on-error: true @@ -141,6 +142,7 @@ jobs: - id: mypy run: | + echo "MYPY_RESULT=$MYPY_RESULT" echo "##[set-output name=data;]$($MYPY_RESULT)" echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" From de2a1d19b733842cd004b109d0c46d28c29b3361 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Tue, 15 Oct 2024 04:37:49 -0400 Subject: [PATCH 062/165] mypy --- .github/workflows/python-app-ubuntu.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 1c77154..d40d22d 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -69,11 +69,26 @@ jobs: poetry run mypy --version poetry run mypy unit_test_generator.py MYPY_RESULT=$? + echo "MYPY_RESULT=$MYPY_RESULT" + echo "##[set-output name=data;]$($MYPY_RESULT)" + echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT fi echo "MYPY_RESULT=$MYPY_RESULT" + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} + REPOSITORY: ${{ github.actor }}/ddt + ACTOR: ${{ github.actor }} + - name: pytest procedural_division # continue-on-error: true run: | From 2261d4d541eb64fe2ca82e6ce7605d49b5286688 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 15 Oct 2024 04:49:46 -0400 Subject: [PATCH 063/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index d40d22d..6d39bf9 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -62,6 +62,7 @@ jobs: fi - name: Typecheck with mypy + id: mypy continue-on-error: true run: | set +e @@ -155,7 +156,7 @@ jobs: - - id: mypy + - id: mypy2 run: | echo "MYPY_RESULT=$MYPY_RESULT" echo "##[set-output name=data;]$($MYPY_RESULT)" @@ -171,8 +172,8 @@ jobs: with: NAME: mypy LABEL: 'mypy' - STATUS: ${{ steps.mypy.outputs.data }} - COLOR: ${{ steps.mypy.outputs.color }} + STATUS: ${{ steps.mypy2.outputs.data }} + COLOR: ${{ steps.mypy2.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} From ccde6e400a084b60e96699fdd9b0c721db47251d Mon Sep 17 00:00:00 2001 From: James Date: Tue, 15 Oct 2024 04:55:56 -0400 Subject: [PATCH 064/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 6d39bf9..fbb2c5b 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -70,14 +70,15 @@ jobs: poetry run mypy --version poetry run mypy unit_test_generator.py MYPY_RESULT=$? + COLOR=$(.color_picker 0 100 $MYPY_RESULT) + echo "color=$COLOR" echo "MYPY_RESULT=$MYPY_RESULT" echo "##[set-output name=data;]$($MYPY_RESULT)" - echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" + echo "##[set-output name=color;]$($COLOR)" if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT fi - echo "MYPY_RESULT=$MYPY_RESULT" - name: mypybadge uses: RubbaBoy/BYOB@v1 From a8625a2c9365b5ae7a718ba87efac142f2baf578 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 15 Oct 2024 05:01:18 -0400 Subject: [PATCH 065/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index fbb2c5b..9c420b7 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -70,7 +70,7 @@ jobs: poetry run mypy --version poetry run mypy unit_test_generator.py MYPY_RESULT=$? - COLOR=$(.color_picker 0 100 $MYPY_RESULT) + COLOR="blue" echo "color=$COLOR" echo "MYPY_RESULT=$MYPY_RESULT" echo "##[set-output name=data;]$($MYPY_RESULT)" From 87a0f3d4b739e71065a3f8190c8e520114e66f6e Mon Sep 17 00:00:00 2001 From: James Date: Tue, 15 Oct 2024 10:19:42 -0400 Subject: [PATCH 066/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 9c420b7..a852f4c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -74,7 +74,7 @@ jobs: echo "color=$COLOR" echo "MYPY_RESULT=$MYPY_RESULT" echo "##[set-output name=data;]$($MYPY_RESULT)" - echo "##[set-output name=color;]$($COLOR)" + echo "##[set-output name=color;]$(echo $COLOR)" if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT From 93bc6e9de5c44e9d526b6ef5abe809c69bde6404 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 00:46:36 -0400 Subject: [PATCH 067/165] Update python-app-ubuntu.yml Using env vars instead of save state --- .github/workflows/python-app-ubuntu.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index a852f4c..052560c 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -71,10 +71,12 @@ jobs: poetry run mypy unit_test_generator.py MYPY_RESULT=$? COLOR="blue" + echo "SELECTED_COLOR=green" >> "$GITHUB_OUTPUT" + echo "MYPY_RESULT=$MYPY_RESULT" >> "$GITHUB_OUTPUT" echo "color=$COLOR" echo "MYPY_RESULT=$MYPY_RESULT" - echo "##[set-output name=data;]$($MYPY_RESULT)" - echo "##[set-output name=color;]$(echo $COLOR)" + # echo "##[set-output name=data;]$($MYPY_RESULT)" + # echo "##[set-output name=color;]$(echo $COLOR)" if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT @@ -82,11 +84,14 @@ jobs: - name: mypybadge uses: RubbaBoy/BYOB@v1 + env: + SELECTED_COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} + MYPY_RESULT: ${{ steps.mypy.outputs.MYPY_RESULT }} with: NAME: mypy LABEL: 'mypy' - STATUS: ${{ steps.mypy.outputs.data }} - COLOR: ${{ steps.mypy.outputs.color }} + STATUS: $MYPY_RESULT # ${{ steps.mypy.outputs.data }} + COLOR: $SELECTED_COLOR #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} @@ -94,6 +99,7 @@ jobs: - name: pytest procedural_division # continue-on-error: true run: | + exit cd tests/procedural_division poetry run python divide_ints.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From af67cb1a1aa103a8525f146273bb95e0507a1f42 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 01:05:05 -0400 Subject: [PATCH 068/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 052560c..32afe9a 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -90,8 +90,8 @@ jobs: with: NAME: mypy LABEL: 'mypy' - STATUS: $MYPY_RESULT # ${{ steps.mypy.outputs.data }} - COLOR: $SELECTED_COLOR #${{ steps.mypy.outputs.color }} + STATUS: echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} + COLOR: echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} From ff8045516a5db2ae536222ad4bb97baed7209644 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 01:18:44 -0400 Subject: [PATCH 069/165] Update github-actions-byob-test.yml Initial commit --- .../workflows/github-actions-byob-test.yml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/github-actions-byob-test.yml diff --git a/.github/workflows/github-actions-byob-test.yml b/.github/workflows/github-actions-byob-test.yml new file mode 100644 index 0000000..03118e2 --- /dev/null +++ b/.github/workflows/github-actions-byob-test.yml @@ -0,0 +1,85 @@ +# Adapted from: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: BYOB Test on Ubuntu +run-name: ${{ github.actor }} is testing out DDT on Ubuntu (latest) +on: #[push] + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + test-ubuntu: + defaults: + run: + shell: bash + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.7.1 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-pip-wheels + uses: actions/cache@v4 + with: + path: ~/.cache + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + run: | + # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry + poetry --version + poetry install --no-interaction --no-root + + - name: Install library + run: poetry install --no-interaction + - run: | + source $VENV + pytest --version + + - name: Typecheck with mypy + id: mypy + continue-on-error: true + run: | + set +e + cd src + poetry run mypy --version + poetry run mypy unit_test_generator.py + MYPY_RESULT=$? + COLOR="blue" + echo "SELECTED_COLOR=green" >> "$GITHUB_OUTPUT" + echo "MYPY_RESULT=$MYPY_RESULT" >> "$GITHUB_OUTPUT" + echo "color=$COLOR" + echo "MYPY_RESULT=$MYPY_RESULT" + # echo "##[set-output name=data;]$($MYPY_RESULT)" + # echo "##[set-output name=color;]$(echo $COLOR)" + + if [ $MYPY_RESULT -ne 0 ]; then + echo "::notice::mypy found errors." && exit $MYPY_RESULT + fi + + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + env: + SELECTED_COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} + MYPY_RESULT: ${{ steps.mypy.outputs.MYPY_RESULT }} + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.MYPY_RESULT }} # echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} #echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} + REPOSITORY: ${{ github.actor }}/ddt + ACTOR: ${{ github.actor }} \ No newline at end of file From 46b34d86c7246cde4db20859da69ef781199d4a4 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 01:22:18 -0400 Subject: [PATCH 070/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 32afe9a..dd9b5d8 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -90,8 +90,8 @@ jobs: with: NAME: mypy LABEL: 'mypy' - STATUS: echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} - COLOR: echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} + STATUS: ${{ steps.mypy.outputs.MYPY_RESULT }} # echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} #echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} From 4f45ed37418bbfdb6e8dde84220e8282dc97761a Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 04:29:04 -0400 Subject: [PATCH 071/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index dd9b5d8..f615e10 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -70,13 +70,9 @@ jobs: poetry run mypy --version poetry run mypy unit_test_generator.py MYPY_RESULT=$? - COLOR="blue" echo "SELECTED_COLOR=green" >> "$GITHUB_OUTPUT" echo "MYPY_RESULT=$MYPY_RESULT" >> "$GITHUB_OUTPUT" - echo "color=$COLOR" echo "MYPY_RESULT=$MYPY_RESULT" - # echo "##[set-output name=data;]$($MYPY_RESULT)" - # echo "##[set-output name=color;]$(echo $COLOR)" if [ $MYPY_RESULT -ne 0 ]; then echo "::notice::mypy found errors." && exit $MYPY_RESULT @@ -89,7 +85,7 @@ jobs: MYPY_RESULT: ${{ steps.mypy.outputs.MYPY_RESULT }} with: NAME: mypy - LABEL: 'mypy' + LABEL: '# of mypy errors' STATUS: ${{ steps.mypy.outputs.MYPY_RESULT }} # echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} #echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} @@ -99,7 +95,6 @@ jobs: - name: pytest procedural_division # continue-on-error: true run: | - exit cd tests/procedural_division poetry run python divide_ints.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From 611a36879fd62d40e2c826982c0c99794d99e881 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 10:59:44 -0400 Subject: [PATCH 072/165] Update python-app-ubuntu.yml WIP --- .github/workflows/python-app-ubuntu.yml | 75 +++++++++---------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index f615e10..62c75c5 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -51,15 +51,29 @@ jobs: - name: Lint with pylint + id: pylint continue-on-error: true run: | set +e # stop the build if there are Python syntax errors or undefined names poetry run pylint src/unit_test_generator.py - PYLINT_RESULT=$? - if [ $PYLINT_RESULT -ne 0 ]; then - echo "::notice::Pylint recommends changes." && exit $PYLINT_RESULT + DATA=$? + if [ $DATA -ne 0 ]; then + echo "::notice::Pylint recommends changes." && exit $DATA fi + echo "DATA=$DATA" >> "$GITHUB_OUTPUT" + echo "##[set-output name=data;]$($DATA)" + COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" + echo "COLOR=green" >> "$GITHUB_OUTPUT" + + - name: pylint badge + uses: RubbaBoy/BYOB@v1 + with: + NAME: pylint + LABEL: 'pylint' + STATUS: ${{ steps.pylint.outputs.data }} + COLOR: ${{ steps.pylint.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} - name: Typecheck with mypy id: mypy @@ -69,25 +83,25 @@ jobs: cd src poetry run mypy --version poetry run mypy unit_test_generator.py - MYPY_RESULT=$? - echo "SELECTED_COLOR=green" >> "$GITHUB_OUTPUT" - echo "MYPY_RESULT=$MYPY_RESULT" >> "$GITHUB_OUTPUT" - echo "MYPY_RESULT=$MYPY_RESULT" + DATA=$? + echo "COLOR=green" >> "$GITHUB_OUTPUT" + echo "DATA=$DATA" >> "$GITHUB_OUTPUT" + echo "DATA=$DATA" - if [ $MYPY_RESULT -ne 0 ]; then - echo "::notice::mypy found errors." && exit $MYPY_RESULT + if [ $DATA -ne 0 ]; then + echo "::notice::mypy found errors." && exit $DATA fi - name: mypybadge uses: RubbaBoy/BYOB@v1 env: - SELECTED_COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} - MYPY_RESULT: ${{ steps.mypy.outputs.MYPY_RESULT }} + COLOR: ${{ steps.mypy.outputs.COLOR }} + DATA: ${{ steps.mypy.outputs.DATA }} with: NAME: mypy LABEL: '# of mypy errors' - STATUS: ${{ steps.mypy.outputs.MYPY_RESULT }} # echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} - COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} #echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} + STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} REPOSITORY: ${{ github.actor }}/ddt ACTOR: ${{ github.actor }} @@ -154,37 +168,4 @@ jobs: echo "HTML?" ls -lah htmlcov poetry run coverage-badge -o coverage.svg - poetry run genbadge coverage -i coverage.xml - - - - - id: mypy2 - run: | - echo "MYPY_RESULT=$MYPY_RESULT" - echo "##[set-output name=data;]$($MYPY_RESULT)" - echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" - - - id: pylint - run: | - echo "##[set-output name=data;]$($PYLINT_RESULT)" - echo "##[set-output name=color;]$(.color_picker 0 100 $MYPY_RESULT)" - - - name: mypybadge - uses: RubbaBoy/BYOB@v1 - with: - NAME: mypy - LABEL: 'mypy' - STATUS: ${{ steps.mypy2.outputs.data }} - COLOR: ${{ steps.mypy2.outputs.color }} - GITHUB_TOKEN: ${{ secrets.DDT }} - REPOSITORY: ${{ github.actor }}/ddt - ACTOR: ${{ github.actor }} - - - name: pylint badge - uses: RubbaBoy/BYOB@v1 - with: - NAME: pylint - LABEL: 'pylint' - STATUS: ${{ steps.pylint.outputs.data }} - COLOR: ${{ steps.pylint.outputs.color }} - GITHUB_TOKEN: ${{ secrets.DDT }} \ No newline at end of file + poetry run genbadge coverage -i coverage.xml \ No newline at end of file From 4c0f73976c2c83dd19f025437b79eea29ea01d55 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 11:01:54 -0400 Subject: [PATCH 073/165] Update get_mypy_pct_errors.py --- get_mypy_pct_errors.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 get_mypy_pct_errors.py diff --git a/get_mypy_pct_errors.py b/get_mypy_pct_errors.py new file mode 100644 index 0000000..05e046b --- /dev/null +++ b/get_mypy_pct_errors.py @@ -0,0 +1,37 @@ +#!/bin/bash + +# Check if a filename is provided +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +FILE="$1" + +# Check if the file exists +if [ ! -f "$FILE" ]; then + echo "File not found: $FILE" + exit 1 +fi + +# Run mypy and capture the output +OUTPUT=$(mypy "$FILE" 2>&1) + +# Count the number of lines of code (excluding comments and blank lines) using cloc +lines_of_code=$(cloc "$FILE" --json | jq '.files[].nloc' | awk '{s+=$1} END {print s}') + +# Count the number of errors reported by mypy +error_count=$(echo "$OUTPUT" | grep -c 'error:') + +# Calculate the percentage of errors per line of code +if [ $lines_of_code -eq 0 ]; then + echo "No lines of code to analyze." + exit 1 +fi + +percentage=$(echo "scale=2; ($error_count / $lines_of_code) * 100" | bc) + +# Print the results +echo "Lines of code: $lines_of_code" +echo "Mypy errors: $error_count" +echo "Percentage of mypy errors: $percentage%" From 97066ef7beb0cb15e74c8fc90df495196f06d2a2 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 14:42:41 -0400 Subject: [PATCH 074/165] Update python-app-mypy-byob-test.yml --- .github/workflows/python-app-mypy-byob-test.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/python-app-mypy-byob-test.yml diff --git a/.github/workflows/python-app-mypy-byob-test.yml b/.github/workflows/python-app-mypy-byob-test.yml new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/.github/workflows/python-app-mypy-byob-test.yml @@ -0,0 +1 @@ +test \ No newline at end of file From 9f32bf6f7b5edfcb755c72c4d7af84a7b242ce3b Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 14:43:32 -0400 Subject: [PATCH 075/165] Update python-app-mypy-byob-test.yml --- .../workflows/python-app-mypy-byob-test.yml | 86 ++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-mypy-byob-test.yml b/.github/workflows/python-app-mypy-byob-test.yml index 30d74d2..03118e2 100644 --- a/.github/workflows/python-app-mypy-byob-test.yml +++ b/.github/workflows/python-app-mypy-byob-test.yml @@ -1 +1,85 @@ -test \ No newline at end of file +# Adapted from: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: BYOB Test on Ubuntu +run-name: ${{ github.actor }} is testing out DDT on Ubuntu (latest) +on: #[push] + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + test-ubuntu: + defaults: + run: + shell: bash + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.7.1 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-pip-wheels + uses: actions/cache@v4 + with: + path: ~/.cache + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + run: | + # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry + poetry --version + poetry install --no-interaction --no-root + + - name: Install library + run: poetry install --no-interaction + - run: | + source $VENV + pytest --version + + - name: Typecheck with mypy + id: mypy + continue-on-error: true + run: | + set +e + cd src + poetry run mypy --version + poetry run mypy unit_test_generator.py + MYPY_RESULT=$? + COLOR="blue" + echo "SELECTED_COLOR=green" >> "$GITHUB_OUTPUT" + echo "MYPY_RESULT=$MYPY_RESULT" >> "$GITHUB_OUTPUT" + echo "color=$COLOR" + echo "MYPY_RESULT=$MYPY_RESULT" + # echo "##[set-output name=data;]$($MYPY_RESULT)" + # echo "##[set-output name=color;]$(echo $COLOR)" + + if [ $MYPY_RESULT -ne 0 ]; then + echo "::notice::mypy found errors." && exit $MYPY_RESULT + fi + + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + env: + SELECTED_COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} + MYPY_RESULT: ${{ steps.mypy.outputs.MYPY_RESULT }} + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.MYPY_RESULT }} # echo "$MYPY_RESULT" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.SELECTED_COLOR }} #echo "$SELECTED_COLOR" #${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} + REPOSITORY: ${{ github.actor }}/ddt + ACTOR: ${{ github.actor }} \ No newline at end of file From 54ace6c01e146da623a395d3412f8e2a05ff6c89 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 14:44:50 -0400 Subject: [PATCH 076/165] Update github-actions-byob-test.yml --- .github/workflows/github-actions-byob-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-byob-test.yml b/.github/workflows/github-actions-byob-test.yml index 03118e2..1ad0b29 100644 --- a/.github/workflows/github-actions-byob-test.yml +++ b/.github/workflows/github-actions-byob-test.yml @@ -4,7 +4,7 @@ name: BYOB Test on Ubuntu run-name: ${{ github.actor }} is testing out DDT on Ubuntu (latest) on: #[push] pull_request: - branches: [ "master" ] + branches: [ "master3" ] workflow_dispatch: jobs: From 964f990c86f02e6ad25dd64b1c24570826eb5319 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 23:08:25 -0400 Subject: [PATCH 077/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 get_mypy_pct_errors.sh diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh new file mode 100644 index 0000000..05e046b --- /dev/null +++ b/get_mypy_pct_errors.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Check if a filename is provided +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +FILE="$1" + +# Check if the file exists +if [ ! -f "$FILE" ]; then + echo "File not found: $FILE" + exit 1 +fi + +# Run mypy and capture the output +OUTPUT=$(mypy "$FILE" 2>&1) + +# Count the number of lines of code (excluding comments and blank lines) using cloc +lines_of_code=$(cloc "$FILE" --json | jq '.files[].nloc' | awk '{s+=$1} END {print s}') + +# Count the number of errors reported by mypy +error_count=$(echo "$OUTPUT" | grep -c 'error:') + +# Calculate the percentage of errors per line of code +if [ $lines_of_code -eq 0 ]; then + echo "No lines of code to analyze." + exit 1 +fi + +percentage=$(echo "scale=2; ($error_count / $lines_of_code) * 100" | bc) + +# Print the results +echo "Lines of code: $lines_of_code" +echo "Mypy errors: $error_count" +echo "Percentage of mypy errors: $percentage%" From eae68ece9804303105212382d327f7d3a997b5a4 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 23:10:52 -0400 Subject: [PATCH 078/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 62c75c5..5a03ce5 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -80,9 +80,13 @@ jobs: continue-on-error: true run: | set +e + chmod +x get_mypy_pct_errors.sh + ./get_mypy_pct_errors.sh src/unit_test_generator.py cd src poetry run mypy --version poetry run mypy unit_test_generator.py + + DATA=$? echo "COLOR=green" >> "$GITHUB_OUTPUT" echo "DATA=$DATA" >> "$GITHUB_OUTPUT" From 512a641be4c382b2b12c9e9b355ca9cbacf900ab Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 23:16:18 -0400 Subject: [PATCH 079/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 5a03ce5..37ec4b3 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -42,6 +42,7 @@ jobs: # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry poetry --version poetry install --no-interaction --no-root + apt install cloc - name: Install library run: poetry install --no-interaction From 1c8eaa861ee4f1899d0410f289e4c5c873be5885 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 16 Oct 2024 23:31:32 -0400 Subject: [PATCH 080/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 37ec4b3..20658d9 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -42,7 +42,7 @@ jobs: # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry poetry --version poetry install --no-interaction --no-root - apt install cloc + sudo apt install cloc - name: Install library run: poetry install --no-interaction From f33aad8675d80e4c6b299934aa7c90d0bfbf0148 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 00:07:56 -0400 Subject: [PATCH 081/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 05e046b..b65ccef 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -7,6 +7,7 @@ if [ $# -ne 1 ]; then fi FILE="$1" +echo "FILE = $FILE" # Check if the file exists if [ ! -f "$FILE" ]; then From 67f74a4bfc6eda65399967d8e072607edff704a5 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 04:30:44 -0400 Subject: [PATCH 082/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index b65ccef..dfbcb89 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -19,7 +19,8 @@ fi OUTPUT=$(mypy "$FILE" 2>&1) # Count the number of lines of code (excluding comments and blank lines) using cloc -lines_of_code=$(cloc "$FILE" --json | jq '.files[].nloc' | awk '{s+=$1} END {print s}') +lines_of_code=$(cloc "$FILE" | tail -n 3 | head -n 1 | awk '{print $NF}' +echo "loc = $lines_of_code" # Count the number of errors reported by mypy error_count=$(echo "$OUTPUT" | grep -c 'error:') From 3e1654310defcd7ba33524ddbcda026279d53647 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 04:33:38 -0400 Subject: [PATCH 083/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index dfbcb89..657c1ba 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -19,7 +19,7 @@ fi OUTPUT=$(mypy "$FILE" 2>&1) # Count the number of lines of code (excluding comments and blank lines) using cloc -lines_of_code=$(cloc "$FILE" | tail -n 3 | head -n 1 | awk '{print $NF}' +lines_of_code=$(cloc "$FILE" | tail -n 3 | head -n 1 | awk '{print $NF}') echo "loc = $lines_of_code" # Count the number of errors reported by mypy From cf394ebfee6b8cf4a4ad0b543b73be49b023f50f Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 04:38:57 -0400 Subject: [PATCH 084/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 657c1ba..0cb895f 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -19,7 +19,7 @@ fi OUTPUT=$(mypy "$FILE" 2>&1) # Count the number of lines of code (excluding comments and blank lines) using cloc -lines_of_code=$(cloc "$FILE" | tail -n 3 | head -n 1 | awk '{print $NF}') +lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') echo "loc = $lines_of_code" # Count the number of errors reported by mypy From ddc108f06f09da3db52ee1694fdde1a21714f125 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 04:50:36 -0400 Subject: [PATCH 085/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 0cb895f..1819dcd 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -15,22 +15,18 @@ if [ ! -f "$FILE" ]; then exit 1 fi -# Run mypy and capture the output -OUTPUT=$(mypy "$FILE" 2>&1) +# Run mypy and ount the number of errors reported by mypy +error_count=$(mypy "$FILE" | grep -c 'error:') # Count the number of lines of code (excluding comments and blank lines) using cloc lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') echo "loc = $lines_of_code" -# Count the number of errors reported by mypy -error_count=$(echo "$OUTPUT" | grep -c 'error:') - # Calculate the percentage of errors per line of code if [ $lines_of_code -eq 0 ]; then echo "No lines of code to analyze." exit 1 fi - percentage=$(echo "scale=2; ($error_count / $lines_of_code) * 100" | bc) # Print the results From 2db193a388f687c65d53b5e5931dee34b850e09c Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:20:39 -0400 Subject: [PATCH 086/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 1819dcd..7819dc0 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -16,7 +16,7 @@ if [ ! -f "$FILE" ]; then fi # Run mypy and ount the number of errors reported by mypy -error_count=$(mypy "$FILE" | grep -c 'error:') +error_count=$(mypy "$FILE" 2>&1 | grep -c 'error:') # Count the number of lines of code (excluding comments and blank lines) using cloc lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') From ab9ff35248b1325958c98db0f5c83cb2294dd40b Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:24:29 -0400 Subject: [PATCH 087/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 7819dc0..97d4272 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -16,7 +16,7 @@ if [ ! -f "$FILE" ]; then fi # Run mypy and ount the number of errors reported by mypy -error_count=$(mypy "$FILE" 2>&1 | grep -c 'error:') +error_count=$(poetry run mypy "$FILE" 2>&1 | grep -c 'error:') # Count the number of lines of code (excluding comments and blank lines) using cloc lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') From c9d015b3c6ed8439e9c8ab9f041938ae3e837777 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:38:22 -0400 Subject: [PATCH 088/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 97d4272..7cc86ba 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -15,7 +15,23 @@ if [ ! -f "$FILE" ]; then exit 1 fi -# Run mypy and ount the number of errors reported by mypy +get_color() { + local percentage=$1 + + if (( $(echo "$percentage > 10" | bc -l) )); then + echo "red" + elif (( $(echo "$percentage > 5" | bc -l) )); then + echo "orange" + elif (( $(echo "$percentage > 2.5" | bc -l) )); then + echo "yellow" + elif (( $(echo "$percentage > 0" | bc -l) )); then + echo "lightgreen" + else + echo "green" + fi +} + +# Run mypy and count the number of errors reported by mypy error_count=$(poetry run mypy "$FILE" 2>&1 | grep -c 'error:') # Count the number of lines of code (excluding comments and blank lines) using cloc @@ -27,9 +43,12 @@ if [ $lines_of_code -eq 0 ]; then echo "No lines of code to analyze." exit 1 fi -percentage=$(echo "scale=2; ($error_count / $lines_of_code) * 100" | bc) +percentage=$(echo "scale=4; ($error_count / $lines_of_code) * 100" | bc) + +color=$(get_color $percentage) # Print the results echo "Lines of code: $lines_of_code" echo "Mypy errors: $error_count" echo "Percentage of mypy errors: $percentage%" +echo "color=$color" From 3abdc11652f9324a31f3df2a4b78112bc7502920 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:42:13 -0400 Subject: [PATCH 089/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 7cc86ba..4f0d7e4 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -52,3 +52,6 @@ echo "Lines of code: $lines_of_code" echo "Mypy errors: $error_count" echo "Percentage of mypy errors: $percentage%" echo "color=$color" + +echo "COLOR=$color" >> "$GITHUB_OUTPUT" +echo "DATA=$error_count error(s) ($percentage% by LoC)" >> "$GITHUB_OUTPUT" \ No newline at end of file From 5f040ef18b01c58ecd82335ce9834b0402252296 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:43:41 -0400 Subject: [PATCH 090/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 20658d9..56e8d6f 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -83,17 +83,8 @@ jobs: set +e chmod +x get_mypy_pct_errors.sh ./get_mypy_pct_errors.sh src/unit_test_generator.py - cd src - poetry run mypy --version - poetry run mypy unit_test_generator.py - - DATA=$? - echo "COLOR=green" >> "$GITHUB_OUTPUT" - echo "DATA=$DATA" >> "$GITHUB_OUTPUT" - echo "DATA=$DATA" - - if [ $DATA -ne 0 ]; then + if [ $? -ne 0 ]; then echo "::notice::mypy found errors." && exit $DATA fi From 580f34193b67b631e2a4c88904f3bc5229ced744 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:44:19 -0400 Subject: [PATCH 091/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 4f0d7e4..157d168 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -54,4 +54,6 @@ echo "Percentage of mypy errors: $percentage%" echo "color=$color" echo "COLOR=$color" >> "$GITHUB_OUTPUT" -echo "DATA=$error_count error(s) ($percentage% by LoC)" >> "$GITHUB_OUTPUT" \ No newline at end of file +echo "DATA=$error_count error(s) ($percentage% by LoC)" >> "$GITHUB_OUTPUT" + +retuen $error_count \ No newline at end of file From 1189276f9ee19ab15c22644ad2c023d81b9d4efc Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:46:55 -0400 Subject: [PATCH 092/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 157d168..f5874e4 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -56,4 +56,4 @@ echo "color=$color" echo "COLOR=$color" >> "$GITHUB_OUTPUT" echo "DATA=$error_count error(s) ($percentage% by LoC)" >> "$GITHUB_OUTPUT" -retuen $error_count \ No newline at end of file +return $error_count \ No newline at end of file From 1222f441f04f5101ae9811430121b4eac1dfbac8 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:51:53 -0400 Subject: [PATCH 093/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 56e8d6f..f1646d7 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -95,7 +95,7 @@ jobs: DATA: ${{ steps.mypy.outputs.DATA }} with: NAME: mypy - LABEL: '# of mypy errors' + LABEL: 'mypy' STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} GITHUB_TOKEN: ${{ secrets.DDT }} From f05d6c4fabd1ce514af494c702d1aa6dcc4707bd Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 05:52:13 -0400 Subject: [PATCH 094/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index f5874e4..6664671 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -25,7 +25,7 @@ get_color() { elif (( $(echo "$percentage > 2.5" | bc -l) )); then echo "yellow" elif (( $(echo "$percentage > 0" | bc -l) )); then - echo "lightgreen" + echo "light green" else echo "green" fi From c4230735908654fe1df30f9638e75a3a194cdbea Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 09:45:53 -0400 Subject: [PATCH 095/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 6664671..42c2462 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -25,7 +25,7 @@ get_color() { elif (( $(echo "$percentage > 2.5" | bc -l) )); then echo "yellow" elif (( $(echo "$percentage > 0" | bc -l) )); then - echo "light green" + echo "90EE90" else echo "green" fi From 512b0945d3877d0028b54a3d80a68a5e77f509be Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 11:21:27 -0400 Subject: [PATCH 096/165] Update get_mypy_pct_errors.sh --- get_mypy_pct_errors.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 42c2462..7a7309b 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -1,13 +1,15 @@ #!/bin/bash # Check if a filename is provided -if [ $# -ne 1 ]; then - echo "Usage: $0 " +if [ $# -ne 2 ]; then + echo "Usage: $0 " exit 1 fi FILE="$1" echo "FILE = $FILE" +lines_of_code="$2" +echo "loc = $lines_of_code" # Check if the file exists if [ ! -f "$FILE" ]; then @@ -15,6 +17,13 @@ if [ ! -f "$FILE" ]; then exit 1 fi +# Ensure valid loc value +if [ $lines_of_code -le 0 ]; then + echo "No lines of code to analyze." + exit 2 +fi + + get_color() { local percentage=$1 @@ -34,15 +43,6 @@ get_color() { # Run mypy and count the number of errors reported by mypy error_count=$(poetry run mypy "$FILE" 2>&1 | grep -c 'error:') -# Count the number of lines of code (excluding comments and blank lines) using cloc -lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') -echo "loc = $lines_of_code" - -# Calculate the percentage of errors per line of code -if [ $lines_of_code -eq 0 ]; then - echo "No lines of code to analyze." - exit 1 -fi percentage=$(echo "scale=4; ($error_count / $lines_of_code) * 100" | bc) color=$(get_color $percentage) From d6ecaf5aeb53607e68dd5c5846c26872f13b7f11 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 11:28:25 -0400 Subject: [PATCH 097/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index f1646d7..87253d2 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -50,6 +50,13 @@ jobs: source $VENV pytest --version + # Count the number of lines of code (excluding comments and blank lines) using cloc + + - name: Count LoC + id: loc + run: | + lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') + echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" - name: Lint with pylint id: pylint @@ -82,7 +89,7 @@ jobs: run: | set +e chmod +x get_mypy_pct_errors.sh - ./get_mypy_pct_errors.sh src/unit_test_generator.py + ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} if [ $? -ne 0 ]; then echo "::notice::mypy found errors." && exit $DATA From dca8d455ee4f792a48859206647096632befbf0d Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 12:39:01 -0400 Subject: [PATCH 098/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 87253d2..c77f86d 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -55,7 +55,7 @@ jobs: - name: Count LoC id: loc run: | - lines_of_code=$(cloc "$FILE" | tail -n 2 | head -n 1 | awk '{print $NF}') + lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" - name: Lint with pylint From 91e83aeb79e6bf26d5eebf01dc63bf75c69f71fb Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 15:22:44 -0400 Subject: [PATCH 099/165] Update run_pylint.sh --- run_pylint.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 run_pylint.sh diff --git a/run_pylint.sh b/run_pylint.sh new file mode 100644 index 0000000..cc797b2 --- /dev/null +++ b/run_pylint.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Check if a filename is provided +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +PYTHON_FILE=$1 + +# Run pylint and store the output +OUTPUT=$(pylint "$PYTHON_FILE" 2>&1) + +# Initialize counters +ERRORS=0 +WARNINGS=0 +CONVENTIONS=0 +REFS=0 +INFO=0 + +# Parse the pylint output +while IFS= read -r line; do + if [[ $line == *": E"* ]]; then + ((ERRORS++)) + elif [[ $line == *": W"* ]]; then + ((WARNINGS++)) + elif [[ $line == *":C"* ]]; then + ((CONVENTIONS++)) + elif [[ $line == *": R"* ]]; then + ((REFS++)) + elif [[ $line == *": I"* ]]; then + ((INFO++)) + fi +done <<< "$OUTPUT" + +# Output the counts +echo "Pylint Report for $PYTHON_FILE" +echo "Errors: $ERRORS" +echo "Warnings: $WARNINGS" +echo "Convention: $CONVENTIONS" +echo "Refactor: $REFS" +echo "Info: $INFO" + +echo "ERRORS=$ERRORS" >> "$GITHUB_OUTPUT" +echo "WARNINGS=$WARNINGS" >> "$GITHUB_OUTPUT" +echo "CONVENTIONS=$CONVENTIONS" >> "$GITHUB_OUTPUT" +echo "REFS=$REFS" >> "$GITHUB_OUTPUT" +echo "INFO=$INFO" >> "$GITHUB_OUTPUT" \ No newline at end of file From 0fc2dd3c262dc969945ba441d4830c4bcfecfbf1 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 15:28:16 -0400 Subject: [PATCH 100/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index c77f86d..44ca011 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -64,6 +64,9 @@ jobs: run: | set +e # stop the build if there are Python syntax errors or undefined names + + chmod +x run_pylint.sh + ./run_pylint.sh src/unit_test_generator.py poetry run pylint src/unit_test_generator.py DATA=$? if [ $DATA -ne 0 ]; then @@ -79,8 +82,8 @@ jobs: with: NAME: pylint LABEL: 'pylint' - STATUS: ${{ steps.pylint.outputs.data }} - COLOR: ${{ steps.pylint.outputs.color }} + STATUS: ${{ steps.pylint.outputs.ERRORS }} + COLOR: ${{ steps.pylint.outputs.COLOR }} GITHUB_TOKEN: ${{ secrets.DDT }} - name: Typecheck with mypy From cf05aad9d6d062a9c4616cb82065fc5534cfcea9 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 16:59:24 -0400 Subject: [PATCH 101/165] Update run_pylint.sh --- run_pylint.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/run_pylint.sh b/run_pylint.sh index cc797b2..b7ed5c0 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -18,18 +18,23 @@ CONVENTIONS=0 REFS=0 INFO=0 +SCORE=0 + # Parse the pylint output while IFS= read -r line; do if [[ $line == *": E"* ]]; then ((ERRORS++)) elif [[ $line == *": W"* ]]; then ((WARNINGS++)) - elif [[ $line == *":C"* ]]; then + elif [[ $line == *": C"* ]]; then ((CONVENTIONS++)) elif [[ $line == *": R"* ]]; then ((REFS++)) elif [[ $line == *": I"* ]]; then ((INFO++)) + elif [[ $line == "Your code has been rated"* ]]; then + SCORE=$(grep -oP '\d+\.\d+' "$line") + fi done <<< "$OUTPUT" @@ -40,9 +45,12 @@ echo "Warnings: $WARNINGS" echo "Convention: $CONVENTIONS" echo "Refactor: $REFS" echo "Info: $INFO" +echo "Score: $SCORE" echo "ERRORS=$ERRORS" >> "$GITHUB_OUTPUT" echo "WARNINGS=$WARNINGS" >> "$GITHUB_OUTPUT" echo "CONVENTIONS=$CONVENTIONS" >> "$GITHUB_OUTPUT" echo "REFS=$REFS" >> "$GITHUB_OUTPUT" -echo "INFO=$INFO" >> "$GITHUB_OUTPUT" \ No newline at end of file +echo "INFO=$INFO" >> "$GITHUB_OUTPUT" +echo "SCORE=$SCORE" >> "$GITHUB_OUTPUT" +echo "MSG=$ERRORS error(s), $WARNINGS warning(s), $CONVENTIONS convention message(s), $REFS reference(s), and $INFO info message(s)" >> "$GITHUB_OUTPUT" \ No newline at end of file From e9c42c6d9674949995e52ba85d8bef5da87e0fe0 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 17:00:38 -0400 Subject: [PATCH 102/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 44ca011..275b1c0 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -82,7 +82,7 @@ jobs: with: NAME: pylint LABEL: 'pylint' - STATUS: ${{ steps.pylint.outputs.ERRORS }} + STATUS: ${{ steps.pylint.outputs.MSG }} COLOR: ${{ steps.pylint.outputs.COLOR }} GITHUB_TOKEN: ${{ secrets.DDT }} From 4d489cddb5510bb1abca529767651c8c0ae75c1e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 17:02:54 -0400 Subject: [PATCH 103/165] Update get_color.sh --- get_color.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get_color.sh b/get_color.sh index 8e6c72c..e604852 100644 --- a/get_color.sh +++ b/get_color.sh @@ -35,6 +35,7 @@ else elif (( $(echo "$percentage <= 0.8333" | bc -l) )); then echo "yellow" else - echo "lightgreen" + # light green + echo "90EE90" fi fi From 1d68617f10f42b75922d8a67df261883258bfcf4 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 17:04:50 -0400 Subject: [PATCH 104/165] Update run_pylint.sh --- run_pylint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run_pylint.sh b/run_pylint.sh index b7ed5c0..376983c 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -47,10 +47,14 @@ echo "Refactor: $REFS" echo "Info: $INFO" echo "Score: $SCORE" +chmod +x ./get_color.sh +COLOR=$(./get_color.sh 0 10 $SCORE) + echo "ERRORS=$ERRORS" >> "$GITHUB_OUTPUT" echo "WARNINGS=$WARNINGS" >> "$GITHUB_OUTPUT" echo "CONVENTIONS=$CONVENTIONS" >> "$GITHUB_OUTPUT" echo "REFS=$REFS" >> "$GITHUB_OUTPUT" echo "INFO=$INFO" >> "$GITHUB_OUTPUT" echo "SCORE=$SCORE" >> "$GITHUB_OUTPUT" -echo "MSG=$ERRORS error(s), $WARNINGS warning(s), $CONVENTIONS convention message(s), $REFS reference(s), and $INFO info message(s)" >> "$GITHUB_OUTPUT" \ No newline at end of file +echo "MSG=$ERRORS error(s), $WARNINGS warning(s), $CONVENTIONS convention message(s), $REFS reference(s), and $INFO info message(s)" >> "$GITHUB_OUTPUT" +echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" \ No newline at end of file From 4fa7b107fdd0ff12a5c58833cb51fc7ef72ca882 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 17:05:42 -0400 Subject: [PATCH 105/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 275b1c0..649ddbb 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -72,10 +72,10 @@ jobs: if [ $DATA -ne 0 ]; then echo "::notice::Pylint recommends changes." && exit $DATA fi - echo "DATA=$DATA" >> "$GITHUB_OUTPUT" - echo "##[set-output name=data;]$($DATA)" - COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" - echo "COLOR=green" >> "$GITHUB_OUTPUT" + #echo "DATA=$DATA" >> "$GITHUB_OUTPUT" + #echo "##[set-output name=data;]$($DATA)" + #COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" + #echo "COLOR=green" >> "$GITHUB_OUTPUT" - name: pylint badge uses: RubbaBoy/BYOB@v1 From 4f058ad7c6826f7ffd0886f9a6d643a65c86fa31 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 21:17:03 -0400 Subject: [PATCH 106/165] Update run_pylint.sh --- run_pylint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_pylint.sh b/run_pylint.sh index 376983c..6e21182 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -20,8 +20,10 @@ INFO=0 SCORE=0 +echo "Examining each line:" # Parse the pylint output while IFS= read -r line; do + echo "$line" if [[ $line == *": E"* ]]; then ((ERRORS++)) elif [[ $line == *": W"* ]]; then From c3d281c571aeb4752b3e62b7f6b2f0eea753d55d Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 22:27:07 -0400 Subject: [PATCH 107/165] Update run_pylint.sh --- run_pylint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_pylint.sh b/run_pylint.sh index 6e21182..53c1c8b 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -9,7 +9,7 @@ fi PYTHON_FILE=$1 # Run pylint and store the output -OUTPUT=$(pylint "$PYTHON_FILE" 2>&1) +OUTPUT=$(poetry run pylint "$PYTHON_FILE" 2>&1) # Initialize counters ERRORS=0 From 6b121fb549e4939ad9057310af73f3582489b053 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 22:33:59 -0400 Subject: [PATCH 108/165] Update run_pylint.sh --- run_pylint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/run_pylint.sh b/run_pylint.sh index 53c1c8b..24c26b6 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -35,8 +35,7 @@ while IFS= read -r line; do elif [[ $line == *": I"* ]]; then ((INFO++)) elif [[ $line == "Your code has been rated"* ]]; then - SCORE=$(grep -oP '\d+\.\d+' "$line") - + SCORE=$(echo "$line" | grep -oP '\d+\.\d+') fi done <<< "$OUTPUT" From 5b196d8c81a6b1e0f2554b60711b6213fc9ff0de Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 22:50:22 -0400 Subject: [PATCH 109/165] Update run_pylint.sh --- run_pylint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_pylint.sh b/run_pylint.sh index 24c26b6..495d7e9 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -35,7 +35,7 @@ while IFS= read -r line; do elif [[ $line == *": I"* ]]; then ((INFO++)) elif [[ $line == "Your code has been rated"* ]]; then - SCORE=$(echo "$line" | grep -oP '\d+\.\d+') + SCORE=$(echo "$line" | grep -oP '\d+\.\d+' | head -n 1 ) fi done <<< "$OUTPUT" From 4f38bee78dd040a488a7b8b3f8d8bf35ea3a7fc1 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 22:51:20 -0400 Subject: [PATCH 110/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 649ddbb..a0a7021 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -40,8 +40,8 @@ jobs: - name: Install dependencies run: | # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry - poetry --version - poetry install --no-interaction --no-root + #poetry --version + #poetry install --no-interaction --no-root sudo apt install cloc - name: Install library @@ -67,7 +67,7 @@ jobs: chmod +x run_pylint.sh ./run_pylint.sh src/unit_test_generator.py - poetry run pylint src/unit_test_generator.py + #poetry run pylint src/unit_test_generator.py DATA=$? if [ $DATA -ne 0 ]; then echo "::notice::Pylint recommends changes." && exit $DATA From f1ccba701dff161648ff828f7df1cef26d748a73 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 22:52:22 -0400 Subject: [PATCH 111/165] Update run_pylint.sh --- run_pylint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run_pylint.sh b/run_pylint.sh index 495d7e9..e68e83c 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -58,4 +58,6 @@ echo "REFS=$REFS" >> "$GITHUB_OUTPUT" echo "INFO=$INFO" >> "$GITHUB_OUTPUT" echo "SCORE=$SCORE" >> "$GITHUB_OUTPUT" echo "MSG=$ERRORS error(s), $WARNINGS warning(s), $CONVENTIONS convention message(s), $REFS reference(s), and $INFO info message(s)" >> "$GITHUB_OUTPUT" -echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" \ No newline at end of file +echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" + +return $ERRORS+$CONVENTIONS \ No newline at end of file From 4138fbf569cfba3bb041c8bfafd8f887a02d9472 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 23:06:26 -0400 Subject: [PATCH 112/165] Update run_pylint.sh --- run_pylint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_pylint.sh b/run_pylint.sh index e68e83c..e26c2ca 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -57,7 +57,7 @@ echo "CONVENTIONS=$CONVENTIONS" >> "$GITHUB_OUTPUT" echo "REFS=$REFS" >> "$GITHUB_OUTPUT" echo "INFO=$INFO" >> "$GITHUB_OUTPUT" echo "SCORE=$SCORE" >> "$GITHUB_OUTPUT" -echo "MSG=$ERRORS error(s), $WARNINGS warning(s), $CONVENTIONS convention message(s), $REFS reference(s), and $INFO info message(s)" >> "$GITHUB_OUTPUT" +echo "MSG=Score:$SCORE; #E:$ERRORS, #W:$WARNINGS, #C:$CONVENTIONS, #R:$REFS, #I:$INFO" >> "$GITHUB_OUTPUT" echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" -return $ERRORS+$CONVENTIONS \ No newline at end of file +exit $ERRORS+$CONVENTIONS \ No newline at end of file From 2f6be9102a02a9db17fa3f7a1257635a8f289e78 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 17 Oct 2024 23:12:10 -0400 Subject: [PATCH 113/165] Update run_pylint.sh --- run_pylint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run_pylint.sh b/run_pylint.sh index e26c2ca..628fac8 100644 --- a/run_pylint.sh +++ b/run_pylint.sh @@ -58,6 +58,4 @@ echo "REFS=$REFS" >> "$GITHUB_OUTPUT" echo "INFO=$INFO" >> "$GITHUB_OUTPUT" echo "SCORE=$SCORE" >> "$GITHUB_OUTPUT" echo "MSG=Score:$SCORE; #E:$ERRORS, #W:$WARNINGS, #C:$CONVENTIONS, #R:$REFS, #I:$INFO" >> "$GITHUB_OUTPUT" -echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" - -exit $ERRORS+$CONVENTIONS \ No newline at end of file +echo "COLOR=$COLOR" >> "$GITHUB_OUTPUT" \ No newline at end of file From d68f111f2b739d7f0e309767d9400dec83dc9a1d Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 5 Jan 2025 23:24:49 -0500 Subject: [PATCH 114/165] Updated paper --- paper/new.tex | 64 +++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/paper/new.tex b/paper/new.tex index f00c52e..bae6ae1 100644 --- a/paper/new.tex +++ b/paper/new.tex @@ -69,11 +69,10 @@ \title{A Python Decorator for Programmatic and Deterministic Unit Test Code Generation\\} -\author{\IEEEauthorblockN{1\textsuperscript{st} Given Name Surname} -\IEEEauthorblockA{\textit{dept. name of organization (of Aff.)} \\ -\textit{name of organization (of Aff.)}\\ -City, Country \\ -email address or ORCID} +\author{\IEEEauthorblockN{James Hatfield} +\IEEEauthorblockA{ +Glen Burnie, MD, USA \\ +jahatfi@gmail.com} } \maketitle @@ -335,7 +334,7 @@ \subsection{Accessing the function and its arguments}\label{sec:approach-interna \lstinputlisting[language=Python,numbers=left, caption={decorator.py: A sample decorator that takes one argument.},label={lst:decorator},]{examples2/decorator.py} -Running the code in Listing~ref{lst:decorator-output} yields the output shown in +Running the code in Listing~\ref{lst:decorator} yields the output shown in Listing~\ref{lst:decorator-output}. Note the apparently erroneous math (line 1,6 of Listing~\ref{lst:decorator-output}), as the \textit{add\_ints} function is unaware that its first argument was modified by the \text{inner\_most\_decorator}. @@ -632,7 +631,7 @@ \subsubsection{Optimal Result by Solving the Minimum Set Cover Problem}\label{se The author did not implement the Minimum Set Cover problem or its weighted variants, but encourages the interested reader to do so. The author records the execution time of each -execution as the \lq cost \rq. This value could be applied in a weighted +execution as the \lq cost\rq. This value could be applied in a weighted variant of the Minimum Set Cover problem, i.e. select the "best" test cases such that coverage is maximized and run time is minimized. @@ -765,25 +764,29 @@ \subsection{Manually Created Tests}\label{sec:eval-1} are checked for correct values on lines 85-92. Note that not all test cases were retained due to the deduplication logic discussed in Section~\ref{sec:tuning-1}. -Executing the unit test is simple as shown in Listing~\ref{Running}\footnote{Due to the verbose way pytest prints the +Executing the unit test is simple as shown in Listing~\ref{Running Pytest}\footnote{Due to the verbose way pytest prints the all the parameters of parameterized tests such as these, the author removed them for the sake of simpler display. The reader is encouraged to run the code as shown on their own machine}. -\begin{lstlisting}[language=bash, numbers=left, caption={Running}] -pytest -s -v test_divide_ints.py -========== test session starts ========== -platform win32 -- Python 3.11.7, pytest-7.4.4, pluggy-1.4.0 -- <@\textcolor{orange}{PATH REDACTED}@>\.venv\Scripts\python.exe -cachedir: .pytest_cache -rootdir: <@\textcolor{orange}{PATH REDACTED}@>\tests\example_procedural_division -plugins: cov-5.0.0 -collected 4 items - -test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#1 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> -test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#2 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> -test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#3 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> -test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#4 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> -\end{lstlisting} + +\begin{lstlisting}[language=bash, numbers=left, caption={Running Pytest}, label={Running Pytest}] + pytest -s -v test_divide_ints.py + ========== test session starts ========== + platform win32 -- Python 3.11.7, pytest-7.4.4, pluggy-1.4.0 -- <@\textcolor{orange}{PATH REDACTED}@>\.venv\Scripts\python.exe + cachedir: .pytest_cache + rootdir: <@\textcolor{orange}{PATH REDACTED}@>\tests\example_procedural_division + plugins: cov-5.0.0 + collected 4 items + + test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#1 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> + test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#2 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> + test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#3 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> + test_divide_ints.py::test_divide_ints[<@\textcolor{orange}{Test \#4 arguments SNIPPED}@>] <@\textcolor{green}{PASSED}@> + \end{lstlisting} + + + The reader is encouraged to study the other examples in the repository. All examples can be executed via the @@ -904,7 +907,9 @@ \subsection{Related Work}\label{sec:related-work} In the current research this author did not discover a deterministic unit test generation paradigm that monitored other types of tests from which to create unit tests. - \section{Conclusion}\label{sec:conclusion} + +% +\section{Conclusion}\label{sec:conclusion} In this paper the author presented a Python decorator leveraging previously designed test(s) to directly create unit tests at minimal development cost. @@ -936,19 +941,18 @@ \subsection{Related Work}\label{sec:related-work} work for future research and application. The author hopes the concepts described herein will be applied in other languages with strong metaprogramming support -such as C\#, Go, Zig, etc. Further information on the code and documentation, please -find it online at +such as C\#, Go, Zig, etc. The full repo containing both the Python code and +LaTeX files for this report can be found in the "ddt" repo at: \begin{center} - \textbf{LINK REDACTED FOR DOUBLE BLIND REVIEW} + \textbf{https://github.com/jahatfi/ddt} \end{center} \section{Acknowledgements}\label{sec:acknowledgements} -Redacted for double-blind review; will populate if accepted. e.g. -The author wishes to thank Drs. \_\_\_\_\_ \_\_\_\_\_\_ and \_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_ -for their assistance in technical writing, Mr. \_\_\_\_\_ \_\_\_\_\_\_ -for his input on the abstract, and Mr. \_\_\_\_\_ \_\_\_\_\_\_ for sharing his pytest +The author wishes to thank Drs. Dan and Mary Lou Midgett +for their assistance in technical writing, Lt Col Solomon Sonya +for his input on the abstract, and Mr. Brad Stinson for sharing his pytest expertise. From 9a989ecab392c94759c44cbe5c16301b13c214b0 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 5 Jan 2025 23:25:20 -0500 Subject: [PATCH 115/165] updates --- tests/all_types/coverage_str_helper.json | 10 +-- tests/all_types/get_item_at_index.json | 30 ++++----- .../test_coverage_str_helper_all_types.py | 2 +- tests/all_types/test_get_item_at_index.py | 4 +- tests/all_types/update_global.json | 6 +- tests/fizzbuzz/fizzbuzz.json | 48 ++++++------- tests/fizzbuzz/test_fizzbuzz.py | 2 +- tests/oo_car/Car.brake.json | 24 +++---- tests/oo_car/Car.change_steer_angle.json | 58 ++++++++-------- tests/oo_car/Car.constructor.json | 12 ++-- tests/oo_car/Car.gas.json | 22 +++--- tests/oo_car/Car.is_going_faster_than.json | 8 +-- tests/oo_car/coverage_str_helper.json | 28 ++++++-- tests/oo_car/test_car_brake.py | 6 +- tests/oo_car/test_car_change_steer_angle.py | 6 +- tests/oo_car/test_car_constructor.py | 2 +- tests/oo_car/test_car_gas.py | 4 +- tests/oo_car/test_car_is_going_faster_than.py | 3 +- .../oo_car/test_coverage_str_helper_oo_car.py | 15 +++-- tests/oo_car/test_update_global_oo_car.py | 67 ++++++++++++++++++- tests/oo_car/update_global.json | 27 +++++--- .../add_to_my_set_kwargs.json | 14 ++-- tests/pass_by_assignment/append_list.json | 12 ++-- .../increment_my_list_kwargs.json | 18 ++--- tests/pass_by_assignment/overwrite_list.json | 12 ++-- tests/procedural_division/divide_ints.json | 50 +++++++------- tests/procedural_division/test_divide_ints.py | 2 +- tests/test_all_keep_files_keep_output.bat | 9 ++- 28 files changed, 297 insertions(+), 204 deletions(-) diff --git a/tests/all_types/coverage_str_helper.json b/tests/all_types/coverage_str_helper.json index c66fd55..cc98498 100644 --- a/tests/all_types/coverage_str_helper.json +++ b/tests/all_types/coverage_str_helper.json @@ -50,18 +50,18 @@ "coverage_io": { "0": { "args_before": [ - "[30]", - "{35}" + "[32]", + "{37}" ], "args_after": { - "this_list": "[30]", - "non_code_lines": "{35}" + "this_list": "[32]", + "non_code_lines": "{37}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "[30]", + "expected_result": "[32]", "expected_type": "list", "coverage": [ 1748, diff --git a/tests/all_types/get_item_at_index.json b/tests/all_types/get_item_at_index.json index 864e825..7c5d48d 100644 --- a/tests/all_types/get_item_at_index.json +++ b/tests/all_types/get_item_at_index.json @@ -7,16 +7,16 @@ "is_method": false, "source_file": null, "lines": [ - 29, - 30, 31, 32, 33, 34, - 36 + 35, + 36, + 38 ], "non_code_lines": [ - 35 + 37 ], "coverage_io": { "0": { @@ -32,10 +32,10 @@ "expected_result": " ", "expected_type": "str", "coverage": [ - 29, 31, 33, - 36 + 35, + 38 ], "exception_type": "", "exception_message": "", @@ -56,10 +56,10 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 29, 31, 33, - 34 + 35, + 36 ], "exception_type": "", "exception_message": "index must be in range [0, 12], was -5", @@ -82,9 +82,9 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 29, 31, - 32 + 33, + 34 ], "exception_type": "", "exception_message": "index must be in range [0, 9], was 50", @@ -107,10 +107,10 @@ "expected_result": "-1", "expected_type": "int", "coverage": [ - 29, 31, 33, - 36 + 35, + 38 ], "exception_type": "", "exception_message": "", @@ -124,12 +124,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 29, 31, - 32, 33, 34, - 36 + 35, + 36, + 38 ], "needs_pytest": true, "exceptions_raised": [ diff --git a/tests/all_types/test_coverage_str_helper_all_types.py b/tests/all_types/test_coverage_str_helper_all_types.py index 9f7bbb7..86a1baa 100644 --- a/tests/all_types/test_coverage_str_helper_all_types.py +++ b/tests/all_types/test_coverage_str_helper_all_types.py @@ -21,7 +21,7 @@ @pytest.mark.parametrize( "this_list, non_code_lines, expected_result, args_after", [ - ([30], {35}, "[30]", {"this_list": "[30]", "non_code_lines": "{35}"}), + ([32], {37}, "[32]", {"this_list": "[32]", "non_code_lines": "{37}"}), ], ) def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index 6ba7e05..f824263 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -5,12 +5,12 @@ import re import pytest from collections import OrderedDict -import all_types +from tests.all_types import all_types # In sum, these tests covered 85.71% of get_item_at_index's lines # Line(s) not covered by ANY of the tests below: -# [30] +# [32] @pytest.mark.parametrize( "iterable, index, exception_type, exception_message, expected_result, args_after", [ diff --git a/tests/all_types/update_global.json b/tests/all_types/update_global.json index bc2ec12..309f5be 100644 --- a/tests/all_types/update_global.json +++ b/tests/all_types/update_global.json @@ -39,17 +39,17 @@ "", "\"logger\"", "\"Before\"", - "CoverageInfo(args_before=['[30]','{35}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" + "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" ], "args_after": { "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['[30]','{35}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" + "this_coverage_info": "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['[30]','{35}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", + "expected_result": "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ 1690, diff --git a/tests/fizzbuzz/fizzbuzz.json b/tests/fizzbuzz/fizzbuzz.json index eec99a1..8581f9b 100644 --- a/tests/fizzbuzz/fizzbuzz.json +++ b/tests/fizzbuzz/fizzbuzz.json @@ -6,9 +6,6 @@ "is_method": false, "source_file": null, "lines": [ - 40, - 41, - 42, 43, 44, 45, @@ -21,11 +18,14 @@ 52, 53, 54, + 55, 56, - 57 + 57, + 59, + 60 ], "non_code_lines": [ - 55 + 58 ], "coverage_io": { "0": { @@ -42,11 +42,11 @@ "expected_result": "Mode 'a_test' invalid for fizzbuzz()", "expected_type": "str", "coverage": [ - 40, - 41, - 48, - 56, - 57 + 43, + 44, + 51, + 59, + 60 ], "exception_type": "", "exception_message": "", @@ -68,16 +68,16 @@ "expected_result": "30 with mode='buzzfizz' yields 'buzzfizz'", "expected_type": "str", "coverage": [ - 40, - 41, - 48, - 49, - 50, + 43, + 44, 51, 52, 53, 54, - 57 + 55, + 56, + 57, + 60 ], "exception_type": "", "exception_message": "", @@ -99,15 +99,15 @@ "expected_result": "30 with mode='fizzbuzz' yields 'fizzbuzz'", "expected_type": "str", "coverage": [ - 40, - 41, - 42, 43, 44, 45, 46, 47, - 57 + 48, + 49, + 50, + 60 ], "exception_type": "", "exception_message": "", @@ -123,9 +123,6 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 40, - 41, - 42, 43, 44, 45, @@ -138,8 +135,11 @@ 52, 53, 54, + 55, 56, - 57 + 57, + 59, + 60 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/fizzbuzz/test_fizzbuzz.py b/tests/fizzbuzz/test_fizzbuzz.py index ed398a1..27e71df 100644 --- a/tests/fizzbuzz/test_fizzbuzz.py +++ b/tests/fizzbuzz/test_fizzbuzz.py @@ -5,7 +5,7 @@ import re import pytest from collections import OrderedDict -from tests.fizzbuzz import fizzbuzz +import fizzbuzz from _pytest.monkeypatch import MonkeyPatch diff --git a/tests/oo_car/Car.brake.json b/tests/oo_car/Car.brake.json index 869ed14..f2fd9a4 100644 --- a/tests/oo_car/Car.brake.json +++ b/tests/oo_car/Car.brake.json @@ -8,13 +8,13 @@ "is_method": true, "source_file": null, "lines": [ - 50, 51, 52, 53, 54, 55, - 56 + 56, + 57 ], "non_code_lines": [], "coverage_io": { @@ -31,11 +31,11 @@ "expected_result": "9", "expected_type": "int", "coverage": [ - 50, 51, - 53, - 55, - 56 + 52, + 54, + 56, + 57 ], "exception_type": "", "exception_message": "", @@ -46,23 +46,23 @@ }, "coverage_percentage": 71.43, "types_in_use": [ + "car.Car", "logging.Logger", "logging.Manager", "logging.PlaceHolder", "logging.RootLogger", - "logging.StreamHandler", - "tests.oo_car.car.Car" + "logging.StreamHandler" ], "global_vars_read_from": [ "logger" ], "global_vars_written_to": [], "unified_test_coverage": [ - 50, 51, - 53, - 55, - 56 + 52, + 54, + 56, + 57 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/Car.change_steer_angle.json b/tests/oo_car/Car.change_steer_angle.json index 773a66e..f0c8803 100644 --- a/tests/oo_car/Car.change_steer_angle.json +++ b/tests/oo_car/Car.change_steer_angle.json @@ -7,22 +7,22 @@ "is_method": true, "source_file": null, "lines": [ - 79, 80, 81, - 83, - 86, + 82, + 84, 87, - 86, 88, - 86, - 90 + 87, + 89, + 87, + 91 ], "non_code_lines": [ - 82, - 84, + 83, 85, - 89 + 86, + 90 ], "coverage_io": { "0": { @@ -37,9 +37,9 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 79, 80, - 81 + 81, + 82 ], "exception_type": "", "exception_message": "angle=-1080 out of bounds!", @@ -59,11 +59,11 @@ "expected_result": "210", "expected_type": "int", "coverage": [ - 79, 80, - 83, - 86, - 90 + 81, + 84, + 87, + 91 ], "exception_type": "", "exception_message": "", @@ -83,11 +83,11 @@ "expected_result": "30", "expected_type": "int", "coverage": [ - 79, 80, - 83, - 86, - 90 + 81, + 84, + 87, + 91 ], "exception_type": "", "exception_message": "", @@ -107,11 +107,11 @@ "expected_result": "60", "expected_type": "int", "coverage": [ - 79, 80, - 83, - 86, - 90 + 81, + 84, + 87, + 91 ], "exception_type": "", "exception_message": "", @@ -122,24 +122,24 @@ }, "coverage_percentage": 60.0, "types_in_use": [ + "car.Car", "logging.Logger", "logging.Manager", "logging.PlaceHolder", "logging.RootLogger", - "logging.StreamHandler", - "tests.oo_car.car.Car" + "logging.StreamHandler" ], "global_vars_read_from": [ "logger" ], "global_vars_written_to": [], "unified_test_coverage": [ - 79, 80, 81, - 83, - 86, - 90 + 82, + 84, + 87, + 91 ], "needs_pytest": true, "exceptions_raised": [ diff --git a/tests/oo_car/Car.constructor.json b/tests/oo_car/Car.constructor.json index 84a1002..258f078 100644 --- a/tests/oo_car/Car.constructor.json +++ b/tests/oo_car/Car.constructor.json @@ -9,9 +9,9 @@ "is_method": true, "source_file": null, "lines": [ - 41, 42, - 43 + 43, + 44 ], "non_code_lines": [], "coverage_io": { @@ -29,9 +29,9 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 41, 42, - 43 + 43, + 44 ], "exception_type": "", "exception_message": "", @@ -45,9 +45,9 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 41, 42, - 43 + 43, + 44 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/Car.gas.json b/tests/oo_car/Car.gas.json index b8c24ac..d910fa7 100644 --- a/tests/oo_car/Car.gas.json +++ b/tests/oo_car/Car.gas.json @@ -8,12 +8,12 @@ "is_method": true, "source_file": null, "lines": [ - 66, 67, 68, 69, 70, - 71 + 71, + 72 ], "non_code_lines": [], "coverage_io": { @@ -34,10 +34,10 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 66, 67, 68, - 69 + 69, + 70 ], "exception_type": "", "exception_message": "Gas rate (m/s) must be positive.", @@ -62,11 +62,11 @@ "expected_result": "16", "expected_type": "int", "coverage": [ - 66, 67, 68, - 70, - 71 + 69, + 71, + 72 ], "exception_type": "", "exception_message": "", @@ -77,12 +77,12 @@ }, "coverage_percentage": 100.0, "types_in_use": [ + "car.Car", "logging.Logger", "logging.Manager", "logging.PlaceHolder", "logging.RootLogger", - "logging.StreamHandler", - "tests.oo_car.car.Car" + "logging.StreamHandler" ], "global_vars_read_from": [ "logger", @@ -92,12 +92,12 @@ "method_call_counter" ], "unified_test_coverage": [ - 66, 67, 68, 69, 70, - 71 + 71, + 72 ], "needs_pytest": true, "exceptions_raised": [ diff --git a/tests/oo_car/Car.is_going_faster_than.json b/tests/oo_car/Car.is_going_faster_than.json index 3a66e48..026adb3 100644 --- a/tests/oo_car/Car.is_going_faster_than.json +++ b/tests/oo_car/Car.is_going_faster_than.json @@ -7,7 +7,7 @@ "is_method": true, "source_file": null, "lines": [ - 126 + 127 ], "non_code_lines": [], "coverage_io": { @@ -25,7 +25,7 @@ "expected_result": "True", "expected_type": "bool", "coverage": [ - 126 + 127 ], "exception_type": "", "exception_message": "", @@ -37,12 +37,12 @@ "coverage_percentage": 100.0, "types_in_use": [ "__main__.Car", - "tests.oo_car.car.Car" + "car.Car" ], "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 126 + 127 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/coverage_str_helper.json b/tests/oo_car/coverage_str_helper.json index aac2c1a..562aa00 100644 --- a/tests/oo_car/coverage_str_helper.json +++ b/tests/oo_car/coverage_str_helper.json @@ -50,18 +50,18 @@ "coverage_io": { "0": { "args_before": [ - "[52, 54]", - "set()" + "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", + "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" ], "args_after": { - "this_list": "[52, 54]", - "non_code_lines": "set()" + "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", + "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['52']", + "expected_result": "['1696', '1708-1709', '1691-1692', '1694-1695']", "expected_type": "list", "coverage": [ 1748, @@ -72,13 +72,21 @@ 1754, 1755, 1756, + 1757, + 1758, + 1759, 1760, 1762, + 1763, + 1764, 1766, 1767, 1768, 1769, 1770, + 1771, + 1772, + 1773, 1778, 1784 ], @@ -89,7 +97,7 @@ "testable": true } }, - "coverage_percentage": 53.12, + "coverage_percentage": 78.12, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -110,13 +118,21 @@ 1754, 1755, 1756, + 1757, + 1758, + 1759, 1760, 1762, + 1763, + 1764, 1766, 1767, 1768, 1769, 1770, + 1771, + 1772, + 1773, 1778, 1784 ], diff --git a/tests/oo_car/test_car_brake.py b/tests/oo_car/test_car_brake.py index b7b4277..0f07625 100644 --- a/tests/oo_car/test_car_brake.py +++ b/tests/oo_car/test_car_brake.py @@ -5,20 +5,20 @@ import re import pytest from collections import OrderedDict -from tests.oo_car import car +import car # Now import modules specific to Car.brake: +from car import Car from logging import Logger from logging import Manager from logging import PlaceHolder from logging import RootLogger from logging import StreamHandler -from tests.oo_car.car import Car # In sum, these tests covered 71.43% of Car.brake's lines # Line(s) not covered by ANY of the tests below: -# ['52'] +# ['53'] @pytest.mark.parametrize( "test_class_instance, rate, duration, expected_result", [ diff --git a/tests/oo_car/test_car_change_steer_angle.py b/tests/oo_car/test_car_change_steer_angle.py index dba587c..2f9c6e2 100644 --- a/tests/oo_car/test_car_change_steer_angle.py +++ b/tests/oo_car/test_car_change_steer_angle.py @@ -5,20 +5,20 @@ import re import pytest from collections import OrderedDict -from tests.oo_car import car +import car # Now import modules specific to Car.change_steer_angle: +from car import Car from logging import Logger from logging import Manager from logging import PlaceHolder from logging import RootLogger from logging import StreamHandler -from tests.oo_car.car import Car # In sum, these tests covered 60.0% of Car.change_steer_angle's lines # Line(s) not covered by ANY of the tests below: -# ['87-88'] +# ['88-89'] @pytest.mark.parametrize( "test_class_instance, angle, exception_type, exception_message, expected_result", [ diff --git a/tests/oo_car/test_car_constructor.py b/tests/oo_car/test_car_constructor.py index 2da3280..cb166d5 100644 --- a/tests/oo_car/test_car_constructor.py +++ b/tests/oo_car/test_car_constructor.py @@ -5,7 +5,7 @@ import re import pytest from collections import OrderedDict -from tests.oo_car import car +import car # In sum, these tests covered 100.0% of Car.__init__'s lines diff --git a/tests/oo_car/test_car_gas.py b/tests/oo_car/test_car_gas.py index 53c0570..0f38729 100644 --- a/tests/oo_car/test_car_gas.py +++ b/tests/oo_car/test_car_gas.py @@ -5,16 +5,16 @@ import re import pytest from collections import OrderedDict -from tests.oo_car import car +import car from _pytest.monkeypatch import MonkeyPatch # Now import modules specific to Car.gas: +from car import Car from logging import Logger from logging import Manager from logging import PlaceHolder from logging import RootLogger from logging import StreamHandler -from tests.oo_car.car import Car # In sum, these tests covered 100.0% of Car.gas's lines diff --git a/tests/oo_car/test_car_is_going_faster_than.py b/tests/oo_car/test_car_is_going_faster_than.py index 8c97803..8ea7bb3 100644 --- a/tests/oo_car/test_car_is_going_faster_than.py +++ b/tests/oo_car/test_car_is_going_faster_than.py @@ -5,11 +5,10 @@ import re import pytest from collections import OrderedDict -from tests.oo_car import car +import car # Now import modules specific to Car.is_going_faster_than: from car import Car -from tests.oo_car.car import Car # In sum, these tests covered 100.0% of Car.is_going_faster_than's lines diff --git a/tests/oo_car/test_coverage_str_helper_oo_car.py b/tests/oo_car/test_coverage_str_helper_oo_car.py index f602ca7..27c9e7b 100644 --- a/tests/oo_car/test_coverage_str_helper_oo_car.py +++ b/tests/oo_car/test_coverage_str_helper_oo_car.py @@ -15,17 +15,20 @@ from logging import StreamHandler -# In sum, these tests covered 53.12% of coverage_str_helper's lines +# In sum, these tests covered 78.12% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1750', '1757-1759', '1761', '1763-1764', '1771-1773', '1775-1776', '1779-1780'] +# ['1750', '1761', '1775-1776', '1779-1780'] @pytest.mark.parametrize( "this_list, non_code_lines, expected_result, args_after", [ ( - [52, 54], - set(), - "['52']", - {"this_list": "[52, 54]", "non_code_lines": "set()"}, + [1696, 1708, 1709, 1691, 1692, 1694, 1695], + {1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}, + "['1696', '1708-1709', '1691-1692', '1694-1695']", + { + "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", + "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}", + }, ), ], ) diff --git a/tests/oo_car/test_update_global_oo_car.py b/tests/oo_car/test_update_global_oo_car.py index e1c5f58..a63085b 100644 --- a/tests/oo_car/test_update_global_oo_car.py +++ b/tests/oo_car/test_update_global_oo_car.py @@ -1,2 +1,65 @@ -import warnings -warnings.warn("No testable samples!") \ No newline at end of file +""" +Programmatically generated test function for update_global() +""" + +import re +import pytest +from collections import OrderedDict +from src import unit_test_generator + +# Now import modules specific to update_global: +from logging import Logger +from logging import Manager +from logging import PlaceHolder +from logging import RootLogger +from logging import StreamHandler +from src.unit_test_generator import CoverageInfo + + +# In sum, these tests covered 46.15% of update_global's lines +# Line(s) not covered by ANY of the tests below: +# ['1696', '1708-1709', '1691-1692', '1694-1695'] +@pytest.mark.parametrize( + "obj, this_global, phase, this_coverage_info, expected_result, args_after", + [ + ( + 0, + "method_call_counter", + "Before", + CoverageInfo( + args_before=["-1", "1"], + args_after={}, + kwargs={}, + kwargs_after={}, + globals_before={}, + globals_after={}, + expected_result="", + expected_type="", + coverage=[], + exception_type="", + exception_message="", + constructor='Car("Red", 10, 0)', + cost=0.0, + testable=0.0, + ), + "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)", + { + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" + }, + ), + ], +) +def test_update_global( + obj, this_global, phase, this_coverage_info, expected_result, args_after +): + """ + Programmatically generated test function for update_global() + """ + result = unit_test_generator.update_global( + obj, this_global, phase, this_coverage_info + ) + assert result == expected_result or result == eval(expected_result) + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) diff --git a/tests/oo_car/update_global.json b/tests/oo_car/update_global.json index e27f9b0..afb84fa 100644 --- a/tests/oo_car/update_global.json +++ b/tests/oo_car/update_global.json @@ -36,34 +36,36 @@ "coverage_io": { "0": { "args_before": [ - "", - "\"logger\"", + "0", + "\"method_call_counter\"", "\"Before\"", "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" ], "args_after": { - "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)", + "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ 1690, - 1691, - 1692 + 1693, + 1698, + 1706, + 1707, + 1710 ], "exception_type": "", "exception_message": "", "constructor": "", "cost": 0.0, - "testable": false + "testable": true } }, - "coverage_percentage": 23.08, + "coverage_percentage": 46.15, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -78,8 +80,11 @@ "global_vars_written_to": [], "unified_test_coverage": [ 1690, - 1691, - 1692 + 1693, + 1698, + 1706, + 1707, + 1710 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/add_to_my_set_kwargs.json b/tests/pass_by_assignment/add_to_my_set_kwargs.json index e4b6554..0cc75be 100644 --- a/tests/pass_by_assignment/add_to_my_set_kwargs.json +++ b/tests/pass_by_assignment/add_to_my_set_kwargs.json @@ -4,9 +4,9 @@ "is_method": false, "source_file": null, "lines": [ - 70, - 71, - 70 + 72, + 73, + 72 ], "non_code_lines": [], "coverage_io": { @@ -28,8 +28,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 70, - 71 + 72, + 73 ], "exception_type": "", "exception_message": "", @@ -43,8 +43,8 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 70, - 71 + 72, + 73 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/append_list.json b/tests/pass_by_assignment/append_list.json index f3e848a..a662ebd 100644 --- a/tests/pass_by_assignment/append_list.json +++ b/tests/pass_by_assignment/append_list.json @@ -7,8 +7,8 @@ "is_method": false, "source_file": null, "lines": [ - 41, - 42 + 43, + 44 ], "non_code_lines": [], "coverage_io": { @@ -27,8 +27,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 41, - 42 + 43, + 44 ], "exception_type": "", "exception_message": "", @@ -50,8 +50,8 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 41, - 42 + 43, + 44 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/increment_my_list_kwargs.json b/tests/pass_by_assignment/increment_my_list_kwargs.json index b6bafe0..ab3cef3 100644 --- a/tests/pass_by_assignment/increment_my_list_kwargs.json +++ b/tests/pass_by_assignment/increment_my_list_kwargs.json @@ -4,10 +4,10 @@ "is_method": false, "source_file": null, "lines": [ - 60, - 61, 62, - 60 + 63, + 64, + 62 ], "non_code_lines": [], "coverage_io": { @@ -28,9 +28,9 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 60, - 61, - 62 + 62, + 63, + 64 ], "exception_type": "", "exception_message": "", @@ -46,9 +46,9 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 60, - 61, - 62 + 62, + 63, + 64 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/overwrite_list.json b/tests/pass_by_assignment/overwrite_list.json index 66a0b05..866e5a1 100644 --- a/tests/pass_by_assignment/overwrite_list.json +++ b/tests/pass_by_assignment/overwrite_list.json @@ -6,8 +6,8 @@ "is_method": false, "source_file": null, "lines": [ - 51, - 52 + 53, + 54 ], "non_code_lines": [], "coverage_io": { @@ -25,8 +25,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 51, - 52 + 53, + 54 ], "exception_type": "", "exception_message": "", @@ -40,8 +40,8 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 51, - 52 + 53, + 54 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/divide_ints.json b/tests/procedural_division/divide_ints.json index e47ebbf..48572ea 100644 --- a/tests/procedural_division/divide_ints.json +++ b/tests/procedural_division/divide_ints.json @@ -7,8 +7,6 @@ "is_method": false, "source_file": null, "lines": [ - 32, - 33, 34, 35, 36, @@ -17,7 +15,9 @@ 39, 40, 41, - 42 + 42, + 43, + 44 ], "non_code_lines": [], "coverage_io": { @@ -38,10 +38,10 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 32, - 33, 34, - 35 + 35, + 36, + 37 ], "exception_type": "", "exception_message": "TypeError: Variable a='10' is not an int!", @@ -66,12 +66,12 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 32, - 33, - 36, - 39, - 40, - 41 + 34, + 35, + 38, + 41, + 42, + 43 ], "exception_type": "", "exception_message": "ValueError: Cannot divide by zero!", @@ -96,11 +96,11 @@ "expected_result": "6/2=3.0", "expected_type": "str", "coverage": [ - 32, - 33, - 36, - 39, - 42 + 34, + 35, + 38, + 41, + 44 ], "exception_type": "", "exception_message": "", @@ -127,11 +127,11 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 32, - 33, - 36, - 37, - 38 + 34, + 35, + 38, + 39, + 40 ], "exception_type": "", "exception_message": "TypeError: Variable b=[] is not an int!", @@ -156,8 +156,6 @@ "error_code" ], "unified_test_coverage": [ - 32, - 33, 34, 35, 36, @@ -166,7 +164,9 @@ 39, 40, 41, - 42 + 42, + 43, + 44 ], "needs_pytest": true, "exceptions_raised": [ diff --git a/tests/procedural_division/test_divide_ints.py b/tests/procedural_division/test_divide_ints.py index 700eda5..1e64b66 100644 --- a/tests/procedural_division/test_divide_ints.py +++ b/tests/procedural_division/test_divide_ints.py @@ -5,7 +5,7 @@ import re import pytest from collections import OrderedDict -from tests.procedural_division import divide_ints +import divide_ints from _pytest.monkeypatch import MonkeyPatch # Now import modules specific to divide_ints: diff --git a/tests/test_all_keep_files_keep_output.bat b/tests/test_all_keep_files_keep_output.bat index 14f2051..61b0427 100644 --- a/tests/test_all_keep_files_keep_output.bat +++ b/tests/test_all_keep_files_keep_output.bat @@ -21,4 +21,11 @@ cd .. cd pass_by_assignment python pass_by_assignment.py pytest -s -vv . -cd .. \ No newline at end of file +cd .. + +cd ..\src +pytest . +cd ..\tests + +coverage combine tests\fizzbuzz\.coverage tests\oo_car\.coverage tests\all_types\.coverage tests\all_types\.coverage tests\procedural_division\.coverage src\.coverage +coverage report -m \ No newline at end of file From ee7a7fbc62d13938e7811bc8885fa0462c6ee692 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 19:01:17 -0500 Subject: [PATCH 116/165] Merged in SIFT changes --- src/unit_test_generator.py | 56 ++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index b89136a..d13f28e 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -629,29 +629,24 @@ def get_module_import_string(my_path:Path)->str: files = set(sorted(sys.path)) keep_file = None this_type = "" - logger.critical(f"{my_path=}") - logger.critical(f"{files=}") - for file in files: - #file = Path(file_str) + for file_str in files: + file = Path(file_str) if my_path.is_relative_to(file): keep_file = file - logger.critical("os.path.relpath(file, my_path, )=%s", + logger.debug("os.path.relpath(file, my_path, )=%s", os.path.relpath(file, my_path, )) this_type = f"{os.path.relpath(file, my_path)}" - #break if keep_file: my_path_str = str(my_path)[len(str(keep_file)):] my_path_str = re.sub(r"^[\\/]", "", my_path_str) - logger.critical(f"{my_path_str=}") this_type = re.sub(".py$", "", my_path_str) if not this_type: raise TypeError("Can't determine type") this_type = re.sub(r"\\", ".", this_type) - logger.critical(f"{this_type=}") + # Other other OS's use forward slashes this_type = re.sub(r"/", ".", this_type) - else: - logger.critical("my_path not relative to any sys paths") + return this_type #@unit_test_generator_decorator(sample_count=1) @@ -667,15 +662,12 @@ def get_class_import_string(arg:typing.Any)->str: keep_file = None this_type = "" for file in files: - logger.debug(file) file_path = Path(file) if my_path.is_relative_to(file_path): keep_file = file_path this_type = f"{os.path.relpath(file_path, my_path)}" - logger.debug("this_type=%s", this_type) if keep_file: my_path_str = str(my_path)[len(str(keep_file)):] - logger.debug("my_path_str=%s", my_path_str) my_path_str = re.sub(r"^[\\/]", "", my_path_str) this_type = f'{re.sub(".py$", "", my_path_str)}.{arg.__class__.__qualname__}' this_type = re.sub(r"\\", ".", this_type) @@ -951,7 +943,7 @@ def args_iterator(self, args_dict = dict(zip(self.this_metadata.parameter_names, self.args)) elif which_args == "kwargs": - args_dict = self.kwargs + args_dict = copy.deepcopy(self.kwargs) else: logger.critical("Invalid option %s!", which_args) sys.exit(1) @@ -1006,12 +998,14 @@ def iterator_helper(self, self.new_types_in_use.add(newest_import) continue + self.new_types_in_use |= get_all_types("1", arg, True, 0, function_name) if hasattr(arg, "__dict__"): logger.debug("Adding types for function %s for arg %s", function_name, arg) for v in arg.__dict__.values(): self.new_types_in_use |= get_all_types("1.1", v, False, 0, function_name) + #sys.exit(1) elif isinstance(arg, str): if which_args == "args": @@ -1086,7 +1080,7 @@ def iterator_helper(self, else: self.kwargs_copy[arg_name] = class_repr else: - logger.critical(f"arg_name=%s mode=%s", arg_name, mode) + logger.debug(f"arg_name=%s mode=%s", arg_name, mode) if which_args == "args": self.args_copy[arg_name] = repr(arg) else: @@ -1131,8 +1125,9 @@ def do_the_decorator_thing(func: Callable, function_name:str, per decorated function. """ # pylint: disable-next=global-variable-not-assigned - logger.critical(function_name) - global all_metadata, unique_inputs + logger.debug("function_name = %s", function_name) + + global all_metadata, hashed_inputs caught_exception = None kwargs = kwargs.get("kwargs", kwargs) #if 'kwargs' in kwargs: @@ -1156,7 +1151,6 @@ def do_the_decorator_thing(func: Callable, function_name:str, this_coverage_info: CoverageInfo = CoverageInfo() #args_copy = [convert_to_serializable(x) for x in args] - logger.critical("function_name = %s", function_name) class_type = "" if this_metadata.is_method: if not function_name.endswith("__init__"): @@ -1345,7 +1339,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, #logger.critical(f"Undecorating {function_name}".center(80, '-')) return result - logger.debug("%s coverage @%s is not a subset", function_name, unique_input) + logger.debug("%s coverage @%s is not a subset", function_name, hashed_input) if caught_exception: caught_exception_str = str(caught_exception) @@ -1491,7 +1485,7 @@ def update_metadata(f: Callable, this_metadata: FunctionMetaData)->None: dis_ = capture(dis) logger.debug("f=%s type(f)=%s", f.__name__, type(f)) disassembled_function = dis_(f) - print(f.__name__) + logger.debug("Updating metadata for %s", f.__name__) for line in disassembled_function.splitlines(): #print(line) if "faster" in f.__name__ or "gas" in f.__name__: @@ -1696,7 +1690,7 @@ def update_global(obj, function skips it. """ if repr(obj).startswith("<"): - logger.critical("Skipping %s", obj) + logger.debug("Skipping %s", obj) return this_coverage_info if isinstance(obj, set): this_entry = sorted_set_repr(obj) @@ -2011,8 +2005,9 @@ def auto_generate_tests(function_metadata:FunctionMetaData, outdir = outdir.absolute() tests_dir = tests_dir.absolute() imports = ["import re\n", + "import itertools\n", "import pytest\n", - "from collections import OrderedDict\n"] + "from collections import OrderedDict, defaultdict\n"] if function_name == "meta_program_function_call": imports.append("from collections import OrderedDict\n") @@ -2362,9 +2357,22 @@ def auto_generate_tests(function_metadata:FunctionMetaData, h.update(str(sorted(test_str_list_def_dict.items())).encode()) return h.digest().hex() - parameterization_list[-1] += "])\n" + + # Define and use counter function for the ids function in pytest, see + # https://docs.pytest.org/en/7.1.x/example/parametrize.html + + parameterization_list[-1] += "], ids=counter)\n" docstring = f'\"\"\"\nProgrammatically generated test function for {function_name}()\n\"\"\"' - print(f"Creating {result_file}...") + + header.extend( + [ + "def counter(start=0)->str:\n", + f"{tab}while True:\n", + f"{tab*2}yield f\"test#-{{start}}\"\n", + f"{tab*2}start += 1\n\n" + ] + ) + logger.critical("Creating %s ...", result_file) with open(result_file, "w", encoding="utf-8") as st: st.write(docstring+"\n") for item in [imports, header, parameterization_list]: From aef5eb66641fa3809fa9e8f8a94972ac59d8182f Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 22:43:38 -0500 Subject: [PATCH 117/165] Fixed hashed/unique input merge bug --- src/unit_test_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index d13f28e..5676098 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -1127,7 +1127,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, # pylint: disable-next=global-variable-not-assigned logger.debug("function_name = %s", function_name) - global all_metadata, hashed_inputs + global all_metadata, unique_inputs caught_exception = None kwargs = kwargs.get("kwargs", kwargs) #if 'kwargs' in kwargs: @@ -1339,7 +1339,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, #logger.critical(f"Undecorating {function_name}".center(80, '-')) return result - logger.debug("%s coverage @%s is not a subset", function_name, hashed_input) + logger.debug("%s coverage @%s is not a subset", function_name, unique_input) if caught_exception: caught_exception_str = str(caught_exception) From d8b9313b9ad52ec05be15f36af1f53d99a0a83d3 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 22:57:08 -0500 Subject: [PATCH 118/165] GitHub actions fixes: Added colors and exiting with mypy script error code --- .github/workflows/python-app-ubuntu.yml | 20 +++++++++++++++++--- get_mypy_pct_errors.sh | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index a0a7021..c0d539a 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -55,7 +55,7 @@ jobs: - name: Count LoC id: loc run: | - lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') + lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" - name: Lint with pylint @@ -113,6 +113,8 @@ jobs: ACTOR: ${{ github.actor }} - name: pytest procedural_division + env: + PY_COLORS: "1" # continue-on-error: true run: | cd tests/procedural_division @@ -120,6 +122,8 @@ jobs: #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz + env: + PY_COLORS: "1" # continue-on-error: true run: | cd tests/fizzbuzz @@ -127,6 +131,8 @@ jobs: poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types + env: + PY_COLORS: "1" # continue-on-error: true run: | cd tests/all_types @@ -134,6 +140,8 @@ jobs: #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest oo_car + env: + PY_COLORS: "1" # continue-on-error: true run: | cd tests/oo_car @@ -141,6 +149,8 @@ jobs: poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment + env: + PY_COLORS: "1" # continue-on-error: true run: | cd tests/pass_by_assignment @@ -148,13 +158,17 @@ jobs: #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - name: pytest helper functions + - name: pytest helper functions + env: + PY_COLORS: "1" # continue-on-error: true run: | cd src poetry run coverage run -m pytest --log-level=DEBUG -s -v . - name: pytest coverage badge + env: + PY_COLORS: "1" run: | ls -lah ls -lah tests/fizzbuzz @@ -162,7 +176,7 @@ jobs: ls -lah tests/all_types ls -lah tests/procedural_division ls -lah tests/pass_by_assignment - poetry add coverage-badge + poetry add coverage-badge poetry run pip install genbadge[all] poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 7a7309b..1d155a3 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -56,4 +56,4 @@ echo "color=$color" echo "COLOR=$color" >> "$GITHUB_OUTPUT" echo "DATA=$error_count error(s) ($percentage% by LoC)" >> "$GITHUB_OUTPUT" -return $error_count \ No newline at end of file +exit $error_count \ No newline at end of file From 5e500eb4e8c59163306ccee9462d02a2bbdc48dd Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 23:05:26 -0500 Subject: [PATCH 119/165] Show myppy output --- get_mypy_pct_errors.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 1d155a3..8b7b0ef 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -41,7 +41,9 @@ get_color() { } # Run mypy and count the number of errors reported by mypy -error_count=$(poetry run mypy "$FILE" 2>&1 | grep -c 'error:') +mypy_output=$(poetry run mypy "$FILE" 2>&1) +echo $mypy_output +error_count=$(cat $mypy_output | grep -c 'error:') percentage=$(echo "scale=4; ($error_count / $lines_of_code) * 100" | bc) From 9d76eac2c7c77ad7f58db806b26ebe3b9afdad8b Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 23:12:31 -0500 Subject: [PATCH 120/165] Show myppy output --- get_mypy_pct_errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_mypy_pct_errors.sh b/get_mypy_pct_errors.sh index 8b7b0ef..04de1fa 100644 --- a/get_mypy_pct_errors.sh +++ b/get_mypy_pct_errors.sh @@ -43,7 +43,7 @@ get_color() { # Run mypy and count the number of errors reported by mypy mypy_output=$(poetry run mypy "$FILE" 2>&1) echo $mypy_output -error_count=$(cat $mypy_output | grep -c 'error:') +error_count=$(echo $mypy_output | grep -c 'error:') percentage=$(echo "scale=4; ($error_count / $lines_of_code) * 100" | bc) From 58b5d95d6b0eed9e2824e099e11b1fc74fb275ae Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Sun, 16 Feb 2025 23:54:55 -0500 Subject: [PATCH 121/165] Linted and typed --- src/unit_test_generator.py | 54 ++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 5676098..75e5885 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -172,10 +172,13 @@ def repr(self)->str: the object in Python. """ args_before_repr = [repr(x) for x in self.args_before] + # pylint: disable-next=C0200 for i in range(len(args_before_repr)): #if ")", r"'\1'", args_before_repr[i]) + args_before_repr[i] = re.sub(r"()", + r"'\1'", + args_before_repr[i]) result = ["CoverageInfo(args_before=["+','.join(args_before_repr)+"]"] #logger.critical(f"{result=}") result.append(" args_after="+repr(self.args_after)) @@ -961,9 +964,10 @@ def iterator_helper(self, if ((which_args == "args" and id(arg) != self.args_addresses[arg_name]) or \ (which_args == "kwargs" and id(arg) != self.kwargs_addresses[arg_name])): - logger.info("Discarding param #%d: %s for 'after' comparison, address has changed", - arg_i, arg) - continue + # pylint: disable-next=line-too-long + logger.info("Discarding param #%d: %s for 'after' comparison, address has changed", + arg_i, arg) + continue if isinstance(arg, (int, str, float)): logger.info("After: Skip it!") continue @@ -1080,7 +1084,7 @@ def iterator_helper(self, else: self.kwargs_copy[arg_name] = class_repr else: - logger.debug(f"arg_name=%s mode=%s", arg_name, mode) + logger.debug("arg_name=%s mode=%s", arg_name, mode) if which_args == "args": self.args_copy[arg_name] = repr(arg) else: @@ -1592,7 +1596,8 @@ def generate_all_tests_and_metadata_helper( local_all_metadata:defaultdict[str, # Replace unique keys with numbers sorted_unique_keys = sorted(test_suite.keys()) for sorted_unique_key_index, sorted_unique_key in enumerate(sorted_unique_keys): - test_suite[sorted_unique_key_index] = test_suite[sorted_unique_key] + # pylint: disable-next=line-too-long + test_suite[sorted_unique_key_index] = test_suite[sorted_unique_key] # type: ignore[index] del test_suite[sorted_unique_key] # The json file is optional and unused but makes for @@ -1612,9 +1617,12 @@ def generate_all_tests_and_metadata_helper( local_all_metadata:defaultdict[str, logger.debug("No test record for %s", function_name) continue - local_all_metadata[function_name].coverage_io = {k:v for k,v in local_all_metadata[function_name].coverage_io.items() if v.testable} + for k,v in local_all_metadata[function_name].coverage_io.items(): + if v.testable: + local_all_metadata[function_name].coverage_io[k] = v if function_name in FUNCTIONS: - result_file_str = f"test_{function_name.lower()}_{os.path.basename(os.getcwd())}".replace('.','_') + ".py" + tmp_str = f"test_{function_name.lower()}_{os.path.basename(os.getcwd())}" + result_file_str = tmp_str.replace('.','_') + ".py" else: result_file_str = f"test_{function_name.lower()}".replace('.','_') + ".py" result_file_str = re.sub("__init__", "constructor", result_file_str) @@ -1817,7 +1825,7 @@ def gen_coverage_list( function_metadata:FunctionMetaData, #percent_covered = 100*percent_covered coverage_str_list = [] start_list = [] - start_list.append(f"{tab}# Coverage: {percent_covered:.2f}% of function lines ") + start_list.append(f"{tab}# Coverage: {percent_covered:.2f}% of function lines") start_list.append(f"[{first_source_line_num}-{last_source_line_num}]\n") start_list.append(f"{tab}# Covered Lines: ") start = ''.join(start_list) @@ -1957,10 +1965,19 @@ def meta_program_function_call( this_state:CoverageInfo, # TODO Why is this_state.args_after sometimes a tuple?? if isinstance(this_state.args_after, dict) and this_state.args_after.keys(): for arg_after in this_state.args_after.keys(): - list_of_lines.append(f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"]) or args_after[\"{arg_after}\"] == {arg_after}\n") + line_list = [ + f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"])", + f"or args_after[\"{arg_after}\"] == {arg_after}\n" + ] + list_of_lines.append(' '.join(line_list)) if isinstance(this_state.kwargs_after, dict) and this_state.kwargs_after.keys(): for arg_after in this_state.kwargs_after.keys(): - list_of_lines.append(f"{indent}assert kwargs[\"{arg_after}\"] == eval(kwargs_after['{arg_after}']) or kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n") + line_list = [ + f"{indent}assert kwargs[\"{arg_after}\"] ==", + f"eval(kwargs_after['{arg_after}']) or", + f"kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n" + ] + list_of_lines.append(' '.join(line_list)) else: for name in parameter_names: @@ -1979,6 +1996,7 @@ def normalize_defaultdict_repr(repr_value:str)->str: class_name = class_name_matcher.groups()[0].split('.')[-1] logger.debug(class_name) + # pylint: disable-next=line-too-long result = re.sub(r"^(defaultdict\()([^']+)'>", r"\1\g",repr_value) #logger.debug(f"{repr_value=}") return result @@ -2183,9 +2201,7 @@ def auto_generate_tests(function_metadata:FunctionMetaData, if args_after: these_aa :dict[str, typing.Any] = {} for arg_name, arg_value in state[unique_key].args_after.items(): - #if isinstance(arg_value, (int, str, float)): - # logger.info("In '%s' Skipping '%s': %s (type:%s)", function_name, arg_name, arg_value, type(arg_value)) - # continue + logger.debug("Keeping '%s':'%s", arg_name, arg_value) these_aa[arg_name] = arg_value state[unique_key].args_after = these_aa @@ -2193,9 +2209,7 @@ def auto_generate_tests(function_metadata:FunctionMetaData, if kwargs_after: these_kaa :dict[str, typing.Any] = {} for arg_name, arg_value in state[unique_key].kwargs_after.items(): - #if isinstance(arg_value, (int, str, float)): - # logger.info("In '%s' Skipping '%s': %s (type:%s)", function_name, arg_name, arg_value, type(arg_value)) - # continue + logger.debug("Keeping '%s':'%s", arg_name, arg_value) these_kaa[arg_name] = arg_value state[unique_key].kwargs_after = these_kaa @@ -2419,10 +2433,10 @@ def auto_generate_tests(function_metadata:FunctionMetaData, return h.digest().hex() # REF: https://stackoverflow.com/questions/18451541 -copyied_locals = dict(locals()) -for key, value in copyied_locals.items(): +copied_locals = dict(locals()) +for value in copied_locals.values(): value = str(value) if value.startswith(" Date: Mon, 17 Feb 2025 00:05:37 -0500 Subject: [PATCH 122/165] Trying to fix GH action --- src/unit_test_generator.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 75e5885..19692d7 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -1965,19 +1965,10 @@ def meta_program_function_call( this_state:CoverageInfo, # TODO Why is this_state.args_after sometimes a tuple?? if isinstance(this_state.args_after, dict) and this_state.args_after.keys(): for arg_after in this_state.args_after.keys(): - line_list = [ - f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"])", - f"or args_after[\"{arg_after}\"] == {arg_after}\n" - ] - list_of_lines.append(' '.join(line_list)) + list_of_lines.append(f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"]) or args_after[\"{arg_after}\"] == {arg_after}\n") if isinstance(this_state.kwargs_after, dict) and this_state.kwargs_after.keys(): for arg_after in this_state.kwargs_after.keys(): - line_list = [ - f"{indent}assert kwargs[\"{arg_after}\"] ==", - f"eval(kwargs_after['{arg_after}']) or", - f"kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n" - ] - list_of_lines.append(' '.join(line_list)) + list_of_lines.append(f"{indent}assert kwargs[\"{arg_after}\"] == eval(kwargs_after['{arg_after}']) or kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n") else: for name in parameter_names: From d963252b71da06becf25f427b396388bc1e9f653 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Mon, 17 Feb 2025 00:10:06 -0500 Subject: [PATCH 123/165] Trying to fix GH action --- .github/workflows/python-app-ubuntu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index c0d539a..824707a 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -92,6 +92,7 @@ jobs: run: | set +e chmod +x get_mypy_pct_errors.sh + python3 -m pip install pandas-stubs ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} if [ $? -ne 0 ]; then From 57a81ed91e6fe77106464a78f0c9ca5cfa192b6d Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Mon, 17 Feb 2025 00:17:46 -0500 Subject: [PATCH 124/165] Run all tests in their own step --- .github/workflows/python-app-ubuntu.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 824707a..af1c891 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -120,7 +120,7 @@ jobs: run: | cd tests/procedural_division poetry run python divide_ints.py - #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz env: @@ -138,7 +138,7 @@ jobs: run: | cd tests/all_types poetry run python all_types.py - #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest oo_car env: @@ -156,7 +156,7 @@ jobs: run: | cd tests/pass_by_assignment poetry run python pass_by_assignment.py - #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest helper functions @@ -177,7 +177,7 @@ jobs: ls -lah tests/all_types ls -lah tests/procedural_division ls -lah tests/pass_by_assignment - poetry add coverage-badge + poetry add coverage-badge 2>&1 1>/dev/null poetry run pip install genbadge[all] poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah From 0a1355dad174c1b20b89f90c43189cf7c62725c3 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Mon, 17 Feb 2025 00:22:58 -0500 Subject: [PATCH 125/165] Trying to fix GH action --- .github/workflows/python-app-ubuntu.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index af1c891..5805f7f 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -120,7 +120,7 @@ jobs: run: | cd tests/procedural_division poetry run python divide_ints.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz env: @@ -129,7 +129,7 @@ jobs: run: | cd tests/fizzbuzz poetry run python fizzbuzz.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types env: @@ -138,7 +138,7 @@ jobs: run: | cd tests/all_types poetry run python all_types.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest oo_car env: @@ -156,7 +156,7 @@ jobs: run: | cd tests/pass_by_assignment poetry run python pass_by_assignment.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest helper functions From 7337e39eac729f19d57dddd757387bc2583b1bff Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:10:38 -0500 Subject: [PATCH 126/165] Create control_car.py Has no decorator --- tests/oo_car/control_car.py | 245 ++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 tests/oo_car/control_car.py diff --git a/tests/oo_car/control_car.py b/tests/oo_car/control_car.py new file mode 100644 index 0000000..1be3e80 --- /dev/null +++ b/tests/oo_car/control_car.py @@ -0,0 +1,245 @@ +""" +Object-oriented test sample +""" + +import argparse +import logging +import os +from pathlib import Path +import coverage + + +FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-25s:%(lineno)-4d:%(message)s' +logging.basicConfig(level=logging.INFO, format=FMT_STR) +logger = logging.getLogger(__name__) +unit_test_generator.logger.setLevel(logging.CRITICAL) + +# The global below is simply so the update_global() function in +# unit_test_generator.py will be executed, without which that +# unit test will be empty and will raise an exception. +method_call_counter = 0 # pylint: disable=invalid-name + +class Car: + """ + A simple class with basic methods for testing the + unit_test_generator_decorator on class methods. + """ + MAX_ANGLE = 720 + MIN_ANGLE = -720 + def __init__( self, + color:str="black",# pylint: disable= used-before-assignment + speed:float=0.0, + steer_angle:int=0): + """ + Create a new Car class with car color, + initial speed and steering angle + """ + self.color = color + self.speed = speed + self.steer_angle = steer_angle + + def brake(self, rate:float, duration:int=1)-> float: + """ + Apply the brake pedal at some negative "rate" + (e.g. -N m/s for "duration" seconds) + """ + logger.debug("rate=%.2f duration=%d", rate, duration) + if rate > 0: + raise ValueError("Brake rate (m/s) must be negative.") + if duration < 0: + raise ValueError("Duration (s) must be positive.") + self.speed = max(0.0, self.speed+rate*duration) + return self.speed + + def gas(self, + rate:float, + duration:int=1): + """ + Apply the gas pedal at some positive "rate" + (e.g. +N m/s for "duration" seconds) + """ + global method_call_counter # pylint: disable=global-statement + method_call_counter +=1 + logger.debug("rate=%.2f duration=%d", rate, duration) + if rate < 0: + raise ValueError("Gas rate (m/s) must be positive.") + self.speed = max(0.0, self.speed+rate*duration) + return self.speed + + def change_steer_angle(self, angle:int): + """ + Add this new steer angle (could be a negative value) + to the current steer angle, and clamp to restrict + within the valid range. + """ + logger.debug("angle=%d", angle) + if angle > self.MAX_ANGLE or angle < self.MIN_ANGLE: + raise AssertionError(f"{angle=:<8} out of bounds!") + + self.steer_angle += angle + # Simple clamp from Sven Marnach + # https://stackoverflow.com/questions/9775731 + self.steer_angle = max(min(self.steer_angle, + self.MAX_ANGLE), + self.MIN_ANGLE + ) + return self.steer_angle + + + def str(self) -> str: + """ + Return a string representation of this Car object + Create string in a list and join it to keep the + line lengths short. + """ + result = [ + f"\'{self.color} car: {self.speed} m/s; ", + f"steer angle = {self.steer_angle} degrees\'" + ] + return ''.join(result) + + def __repr__(self, **kwargs): + """ + Return this objective as a valid Python string that can + be used to recreate this object. + """ + return f"Car(\"{self.color}\", {self.speed}, {self.steer_angle})" + + + def repr(self): + """ + Simply call the magic __repr__ method + """ + return self.__repr__() # pylint: disable=unnecessary-dunder-call + + + def is_going_faster_than(self, other_car): + """ + Return True if this car (self) has a higher value + in its "speed" property compared to other_car.speed; + else return False. + """ + return self.speed > other_car.speed + + def __eq__(self, other_car:object) -> bool: + """ + Return True if and only if the two Car classes + are identical, doesn't compare private variables. + """ + if self.color != other_car.color: + return False + if self.speed != other_car.speed: + return False + if self.steer_angle != other_car.steer_angle: + return False + return True +def first_test(): + """ + Create a bunch of cars to test all the Car class methods + except for is_going_faster_than() + """ + # Create a bunch of cars in a loop for testing: + colors = ["Red", "White", "Blue", "Green"] + init_speeds = [10,12,14,16] + init_angles = [0, -30, 30, 90 ] + change_angles = [30, 90, 180, -1080] + change_speed = [-1, 2, 3, 4] + durations = [1,2,-3,4] + lists = [ + colors, + init_speeds, + init_angles, + change_angles, + change_speed, + durations + ] + for i, (color, speed, angle, c_angle, c_speed, duration) in enumerate(zip(*lists)): + logger.info(f"Car #{i}".center(80, '-')) + this_car = Car(color, speed, angle) + if this_car is None or not this_car: + raise ValueError("this_car is None!") + + logger.info(this_car) + logger.info("Driving %s", {this_car.repr()}) + # Note the intentional bug here for the + # sake of demonstrating the ValueError: + try: + this_car.gas(c_speed, duration) + except ValueError as e: + logger.error("gas(%.2f,%d) raised %s", c_speed, duration, type(e)) + # Instead of a try/except we should do: + if c_speed >= 0: + this_car.gas(c_speed, duration) + else: + this_car.brake(c_speed, duration) + + #car.change_steer_angle(c_angle) + try: + this_car.change_steer_angle(c_angle) + except AssertionError as e: + logger.error("change_steer_angle(%s) raised %s", c_angle, type(e)) + + logger.info(this_car) + +def second_test(): + """ + Create two cars and determine which one is going faster + by using the is_going_faster_than() Car method + """ + logger.info("Test 2.1".center(80, '-')) + car_1 = Car("Red", 20, 0) + car_2 = Car("White", 19, 0) + + if car_1.is_going_faster_than(car_2): + logger.info("%s is going faster than %s", car_1, car_2) + else: + logger.info("%s's speed is less than or equal to %s's speed", car_1, car_2) + + logger.info("Test 2.2".center(80, '-')) + # The invocation below will also work, + # demonstrating that the unit_test_generator_decorator works on both + Car.is_going_faster_than(car_1, car_2) + +def main(): + """ + Call test functions for Car class, then generate test files for each + method. + """ + + first_test() + second_test() + generate_all_tests_and_metadata(Path('.'), Path('.')) + +if __name__ == "__main__": + + log_levels = { + 'critical': logging.CRITICAL, + 'error': logging.ERROR, + 'warn': logging.WARNING, + 'warning': logging.WARNING, + 'info': logging.INFO, + 'debug': logging.DEBUG + } + + # Create the parser and add argument(s) + parser = argparse.ArgumentParser() + parser.add_argument('--log-level', + "-l", + help='log level', + type=str, + choices=log_levels.keys(), + default='info') + parser.add_argument("--disable-unit-test-generation", "-d", + action="store_true", + help="Set this flag to deactivate unit test generation for this code") + args = parser.parse_args() + logger.info("args=%s", args) + + this_file = Path(__file__).absolute() + for file in this_file.parent.rglob("*"): + if file.suffix in (".py", ".json") and file.absolute() != this_file: + logger.debug("%s != %s", file.absolute().name, this_file.name) + logger.debug("Deleting %s to ensure clean start", file.name) + os.remove(file) + + main() From 823d0d75c050e632adb46f164155a498110c9d25 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:13:10 -0500 Subject: [PATCH 127/165] Update python-app-ubuntu.yml Added control car example with no decorator to measure overhead --- .github/workflows/python-app-ubuntu.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 5805f7f..262b11f 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -146,7 +146,8 @@ jobs: # continue-on-error: true run: | cd tests/oo_car - poetry run python car.py + time poetry run python control_car.py + time poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From 97973f962154194f5d73a2e0e3d3a8dcad0eb40b Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:17:12 -0500 Subject: [PATCH 128/165] Update control_car.py Removed stray logger initialization --- tests/oo_car/control_car.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/oo_car/control_car.py b/tests/oo_car/control_car.py index 1be3e80..db03bcc 100644 --- a/tests/oo_car/control_car.py +++ b/tests/oo_car/control_car.py @@ -12,7 +12,6 @@ FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-25s:%(lineno)-4d:%(message)s' logging.basicConfig(level=logging.INFO, format=FMT_STR) logger = logging.getLogger(__name__) -unit_test_generator.logger.setLevel(logging.CRITICAL) # The global below is simply so the update_global() function in # unit_test_generator.py will be executed, without which that From dc600b66f838cbd99dc88762f2cf7e14108168db Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:20:07 -0500 Subject: [PATCH 129/165] Update car.py Now using disable-unit-test-generation flag --- tests/oo_car/car.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 7e91a95..8b9c647 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -246,7 +246,9 @@ def main(): logger.debug("%s != %s", file.absolute().name, this_file.name) logger.debug("Deleting %s to ensure clean start", file.name) os.remove(file) - + if args.disable_unit_test_generation(): + main() + return # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From a94ef101c4f8fdd049268ab6a03fa187738249f4 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:22:28 -0500 Subject: [PATCH 130/165] Update python-app-ubuntu.yml Disable car overhead --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 262b11f..e02412d 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -146,8 +146,8 @@ jobs: # continue-on-error: true run: | cd tests/oo_car - time poetry run python control_car.py - time poetry run python car.py + time poetry run python car.py -d + time poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From 95d16ce87350e443c26880f0bbbd10633b5f6149 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:26:15 -0500 Subject: [PATCH 131/165] Update car.py Exit --- tests/oo_car/car.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 8b9c647..b0ac0d9 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -7,6 +7,7 @@ import os from pathlib import Path import coverage +import sys from src import unit_test_generator from src.unit_test_generator import ( @@ -248,7 +249,7 @@ def main(): os.remove(file) if args.disable_unit_test_generation(): main() - return + sys.exit(0) # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From d6fbbf6a2b52a49a2f0c486409d62d67c6a83b33 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 12 Nov 2025 18:29:23 -0500 Subject: [PATCH 132/165] Update car.py Typo fix --- tests/oo_car/car.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index b0ac0d9..8a41041 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -247,7 +247,7 @@ def main(): logger.debug("%s != %s", file.absolute().name, this_file.name) logger.debug("Deleting %s to ensure clean start", file.name) os.remove(file) - if args.disable_unit_test_generation(): + if args.disable_unit_test_generation: main() sys.exit(0) # The code below applies the CLI arg above to selectively enable/disable From 9aa5545b0f57ff63faa65aaa6a031ef17222305d Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 00:11:48 -0500 Subject: [PATCH 133/165] Update all_types.py Use disable flag --- tests/all_types/all_types.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/all_types/all_types.py b/tests/all_types/all_types.py index e73f0a7..a36068a 100644 --- a/tests/all_types/all_types.py +++ b/tests/all_types/all_types.py @@ -5,6 +5,7 @@ import argparse import logging import os +import sys from pathlib import Path import coverage @@ -138,6 +139,11 @@ def main(): os.remove(file) logger.info("%s", __file__) + + if args.disable_unit_test_generation: + main() + sys.exit(0) + # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From b039d7fe50ce50c5c02fc46c3061ca1dc0857cfc Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 00:13:29 -0500 Subject: [PATCH 134/165] Update fizzbuzz.py Use disable flag --- tests/fizzbuzz/fizzbuzz.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index a019832..4313ae5 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -5,6 +5,7 @@ import argparse import logging import os +import sys from pathlib import Path import coverage import json @@ -117,6 +118,12 @@ def main(): if file.suffix in (".py", ".json") and file.absolute() != this_file: logger.debug("Deleting %s to ensure clean start", this_file) os.remove(file) + + + if args.disable_unit_test_generation: + main() + sys.exit(0) + # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From 1e73ff3e47401d11eb1c7828f421f1a9d3a439bf Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 00:14:30 -0500 Subject: [PATCH 135/165] Update pass_by_assignment.py Use disable flag --- tests/pass_by_assignment/pass_by_assignment.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/pass_by_assignment/pass_by_assignment.py b/tests/pass_by_assignment/pass_by_assignment.py index 1f5f1fd..4c6ae26 100644 --- a/tests/pass_by_assignment/pass_by_assignment.py +++ b/tests/pass_by_assignment/pass_by_assignment.py @@ -5,6 +5,7 @@ import argparse import logging import os +import sys from pathlib import Path from typing import Any, List, TypeVar @@ -133,6 +134,12 @@ def main(): os.remove(file) logger.info("%s", __file__) + + + if args.disable_unit_test_generation: + main() + sys.exit(0) + # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From 55b4b013ccfdede0487260d33653e18e1a33c9d2 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 00:15:06 -0500 Subject: [PATCH 136/165] Update divide_ints.py Use disable flag --- tests/procedural_division/divide_ints.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/procedural_division/divide_ints.py b/tests/procedural_division/divide_ints.py index 950e69e..7ac3d4d 100644 --- a/tests/procedural_division/divide_ints.py +++ b/tests/procedural_division/divide_ints.py @@ -5,6 +5,7 @@ import argparse import logging import os +import sys import time from pathlib import Path @@ -98,6 +99,12 @@ def main(): logger.debug("Deleting %s to ensure clean start", this_file) os.remove(file) + + if args.disable_unit_test_generation: + main() + sys.exit(0) + + # The code below applies the CLI arg above to selectively enable/disable # automatic unit test generation (Could not use the syntactic sugar method # of applying decorators as the user's input isn't parsed until now.) From d9f57fad4ed8687eb902d83cdec4631cd26bbb84 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 00:24:30 -0500 Subject: [PATCH 137/165] Update python-app-ubuntu.yml Disabling via flag --- .github/workflows/python-app-ubuntu.yml | 143 +++++++++++++----------- 1 file changed, 79 insertions(+), 64 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index e02412d..2ef642d 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -50,75 +50,15 @@ jobs: source $VENV pytest --version - # Count the number of lines of code (excluding comments and blank lines) using cloc - - - name: Count LoC - id: loc - run: | - lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') - echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" - - - name: Lint with pylint - id: pylint - continue-on-error: true - run: | - set +e - # stop the build if there are Python syntax errors or undefined names - - chmod +x run_pylint.sh - ./run_pylint.sh src/unit_test_generator.py - #poetry run pylint src/unit_test_generator.py - DATA=$? - if [ $DATA -ne 0 ]; then - echo "::notice::Pylint recommends changes." && exit $DATA - fi - #echo "DATA=$DATA" >> "$GITHUB_OUTPUT" - #echo "##[set-output name=data;]$($DATA)" - #COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" - #echo "COLOR=green" >> "$GITHUB_OUTPUT" - - - name: pylint badge - uses: RubbaBoy/BYOB@v1 - with: - NAME: pylint - LABEL: 'pylint' - STATUS: ${{ steps.pylint.outputs.MSG }} - COLOR: ${{ steps.pylint.outputs.COLOR }} - GITHUB_TOKEN: ${{ secrets.DDT }} - - - name: Typecheck with mypy - id: mypy - continue-on-error: true - run: | - set +e - chmod +x get_mypy_pct_errors.sh - python3 -m pip install pandas-stubs - ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} - - if [ $? -ne 0 ]; then - echo "::notice::mypy found errors." && exit $DATA - fi - - - name: mypybadge - uses: RubbaBoy/BYOB@v1 - env: - COLOR: ${{ steps.mypy.outputs.COLOR }} - DATA: ${{ steps.mypy.outputs.DATA }} - with: - NAME: mypy - LABEL: 'mypy' - STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} - COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} - GITHUB_TOKEN: ${{ secrets.DDT }} - REPOSITORY: ${{ github.actor }}/ddt - ACTOR: ${{ github.actor }} - - name: pytest procedural_division env: PY_COLORS: "1" # continue-on-error: true run: | cd tests/procedural_division + echo "divide_ints.py -d runtime:" + poetry run python divide_ints.py -d + echo "divide_ints.py runtime:" poetry run python divide_ints.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html @@ -128,6 +68,9 @@ jobs: # continue-on-error: true run: | cd tests/fizzbuzz + echo "fizzbuzz.py -d runtime:" + poetry run python fizzbuzz.py -d + echo "fizzbuzz.py runtime:" poetry run python fizzbuzz.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html @@ -137,6 +80,9 @@ jobs: # continue-on-error: true run: | cd tests/all_types + echo "all_types.py -d runtime:" + poetry run python all_types.py -d + echo "all_types.py runtime:" poetry run python all_types.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html @@ -146,7 +92,9 @@ jobs: # continue-on-error: true run: | cd tests/oo_car + echo "car.py -d runtime:" time poetry run python car.py -d + echo "car.py runtime:" time poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html @@ -156,6 +104,9 @@ jobs: # continue-on-error: true run: | cd tests/pass_by_assignment + echo "pass_by_assignment -d runtime:" + poetry run python pass_by_assignment.py + echo "pass_by_assignment runtime:" poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html @@ -190,4 +141,68 @@ jobs: echo "HTML?" ls -lah htmlcov poetry run coverage-badge -o coverage.svg - poetry run genbadge coverage -i coverage.xml \ No newline at end of file + poetry run genbadge coverage -i coverage.xml + + # Count the number of lines of code (excluding comments and blank lines) using cloc + + - name: Count LoC + id: loc + run: | + lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') + echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" + + - name: Lint with pylint + id: pylint + continue-on-error: true + run: | + set +e + # stop the build if there are Python syntax errors or undefined names + + chmod +x run_pylint.sh + ./run_pylint.sh src/unit_test_generator.py + #poetry run pylint src/unit_test_generator.py + DATA=$? + if [ $DATA -ne 0 ]; then + echo "::notice::Pylint recommends changes." && exit $DATA + fi + #echo "DATA=$DATA" >> "$GITHUB_OUTPUT" + #echo "##[set-output name=data;]$($DATA)" + #COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" + #echo "COLOR=green" >> "$GITHUB_OUTPUT" + + - name: pylint badge + uses: RubbaBoy/BYOB@v1 + with: + NAME: pylint + LABEL: 'pylint' + STATUS: ${{ steps.pylint.outputs.MSG }} + COLOR: ${{ steps.pylint.outputs.COLOR }} + GITHUB_TOKEN: ${{ secrets.DDT }} + + - name: Typecheck with mypy + id: mypy + continue-on-error: true + run: | + set +e + chmod +x get_mypy_pct_errors.sh + python3 -m pip install pandas-stubs + ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} + + if [ $? -ne 0 ]; then + echo "::notice::mypy found errors." && exit $DATA + fi + + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + env: + COLOR: ${{ steps.mypy.outputs.COLOR }} + DATA: ${{ steps.mypy.outputs.DATA }} + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} + REPOSITORY: ${{ github.actor }}/ddt + ACTOR: ${{ github.actor }} + From 8a6546056de1b4830918077faea9d142e0d2a83a Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 05:59:57 -0500 Subject: [PATCH 138/165] Update python-app-ubuntu.yml Back up --- .github/workflows/python-app-ubuntu.yml | 128 ++++++++++++------------ 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 2ef642d..12fca16 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -50,6 +50,71 @@ jobs: source $VENV pytest --version + # Count the number of lines of code (excluding comments and blank lines) using cloc + + - name: Count LoC + id: loc + run: | + lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') + echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" + + - name: Lint with pylint + id: pylint + continue-on-error: true + run: | + set +e + # stop the build if there are Python syntax errors or undefined names + + chmod +x run_pylint.sh + ./run_pylint.sh src/unit_test_generator.py + #poetry run pylint src/unit_test_generator.py + DATA=$? + if [ $DATA -ne 0 ]; then + echo "::notice::Pylint recommends changes." && exit $DATA + fi + #echo "DATA=$DATA" >> "$GITHUB_OUTPUT" + #echo "##[set-output name=data;]$($DATA)" + #COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" + #echo "COLOR=green" >> "$GITHUB_OUTPUT" + + - name: pylint badge + uses: RubbaBoy/BYOB@v1 + with: + NAME: pylint + LABEL: 'pylint' + STATUS: ${{ steps.pylint.outputs.MSG }} + COLOR: ${{ steps.pylint.outputs.COLOR }} + GITHUB_TOKEN: ${{ secrets.DDT }} + + - name: Typecheck with mypy + id: mypy + continue-on-error: true + run: | + set +e + chmod +x get_mypy_pct_errors.sh + python3 -m pip install pandas-stubs + ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} + + if [ $? -ne 0 ]; then + echo "::notice::mypy found errors." && exit $DATA + fi + + - name: mypybadge + uses: RubbaBoy/BYOB@v1 + env: + COLOR: ${{ steps.mypy.outputs.COLOR }} + DATA: ${{ steps.mypy.outputs.DATA }} + with: + NAME: mypy + LABEL: 'mypy' + STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} + COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} + GITHUB_TOKEN: ${{ secrets.DDT }} + REPOSITORY: ${{ github.actor }}/ddt + ACTOR: ${{ github.actor }} + + + - name: pytest procedural_division env: PY_COLORS: "1" @@ -143,66 +208,3 @@ jobs: poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml - # Count the number of lines of code (excluding comments and blank lines) using cloc - - - name: Count LoC - id: loc - run: | - lines_of_code=$(cloc src/unit_test_generator.py | tail -n 2 | head -n 1 | awk '{print $NF}') - echo "LOC=$lines_of_code" >> "$GITHUB_OUTPUT" - - - name: Lint with pylint - id: pylint - continue-on-error: true - run: | - set +e - # stop the build if there are Python syntax errors or undefined names - - chmod +x run_pylint.sh - ./run_pylint.sh src/unit_test_generator.py - #poetry run pylint src/unit_test_generator.py - DATA=$? - if [ $DATA -ne 0 ]; then - echo "::notice::Pylint recommends changes." && exit $DATA - fi - #echo "DATA=$DATA" >> "$GITHUB_OUTPUT" - #echo "##[set-output name=data;]$($DATA)" - #COLOR#$(chmod +x color_picker.sh && ./color_picker.sh 0 100 $DATA)" - #echo "COLOR=green" >> "$GITHUB_OUTPUT" - - - name: pylint badge - uses: RubbaBoy/BYOB@v1 - with: - NAME: pylint - LABEL: 'pylint' - STATUS: ${{ steps.pylint.outputs.MSG }} - COLOR: ${{ steps.pylint.outputs.COLOR }} - GITHUB_TOKEN: ${{ secrets.DDT }} - - - name: Typecheck with mypy - id: mypy - continue-on-error: true - run: | - set +e - chmod +x get_mypy_pct_errors.sh - python3 -m pip install pandas-stubs - ./get_mypy_pct_errors.sh src/unit_test_generator.py ${{ steps.loc.outputs.LOC }} - - if [ $? -ne 0 ]; then - echo "::notice::mypy found errors." && exit $DATA - fi - - - name: mypybadge - uses: RubbaBoy/BYOB@v1 - env: - COLOR: ${{ steps.mypy.outputs.COLOR }} - DATA: ${{ steps.mypy.outputs.DATA }} - with: - NAME: mypy - LABEL: 'mypy' - STATUS: ${{ steps.mypy.outputs.DATA }} # echo "$DATA" # ${{ steps.mypy.outputs.data }} - COLOR: ${{ steps.mypy.outputs.COLOR }} #echo "$COLOR" #${{ steps.mypy.outputs.color }} - GITHUB_TOKEN: ${{ secrets.DDT }} - REPOSITORY: ${{ github.actor }}/ddt - ACTOR: ${{ github.actor }} - From 3a0458d62b007a4d3ba6c5edc3c5ae214089f1d0 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 06:05:58 -0500 Subject: [PATCH 139/165] Update python-app-ubuntu.yml Time --- .github/workflows/python-app-ubuntu.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 12fca16..5c8227a 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -122,9 +122,9 @@ jobs: run: | cd tests/procedural_division echo "divide_ints.py -d runtime:" - poetry run python divide_ints.py -d + time poetry run python divide_ints.py -d echo "divide_ints.py runtime:" - poetry run python divide_ints.py + time poetry run python divide_ints.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz @@ -134,9 +134,9 @@ jobs: run: | cd tests/fizzbuzz echo "fizzbuzz.py -d runtime:" - poetry run python fizzbuzz.py -d + time poetry run python fizzbuzz.py -d echo "fizzbuzz.py runtime:" - poetry run python fizzbuzz.py + time poetry run python fizzbuzz.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types @@ -146,9 +146,9 @@ jobs: run: | cd tests/all_types echo "all_types.py -d runtime:" - poetry run python all_types.py -d + time poetry run python all_types.py -d echo "all_types.py runtime:" - poetry run python all_types.py + time poetry run python all_types.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest oo_car @@ -170,9 +170,9 @@ jobs: run: | cd tests/pass_by_assignment echo "pass_by_assignment -d runtime:" - poetry run python pass_by_assignment.py + time poetry run python pass_by_assignment.py echo "pass_by_assignment runtime:" - poetry run python pass_by_assignment.py + time poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From b47a754482eb9230dcb48e20ecc6f033870f491b Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 06:15:01 -0500 Subject: [PATCH 140/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 5c8227a..17d0d52 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -158,9 +158,9 @@ jobs: run: | cd tests/oo_car echo "car.py -d runtime:" - time poetry run python car.py -d + poetry run python car.py -d echo "car.py runtime:" - time poetry run python car.py + poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From 4abe141e7984e59e468ff5f0e470ae090170b2f1 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 14:45:33 -0500 Subject: [PATCH 141/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 17d0d52..3692c0a 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -158,7 +158,7 @@ jobs: run: | cd tests/oo_car echo "car.py -d runtime:" - poetry run python car.py -d + #poetry run python car.py -d echo "car.py runtime:" poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From 019c54555afc0a1bc80ed938be7d195864f4cfdf Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 15:31:26 -0500 Subject: [PATCH 142/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 3692c0a..3010968 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -157,9 +157,9 @@ jobs: # continue-on-error: true run: | cd tests/oo_car - echo "car.py -d runtime:" + # echo "car.py -d runtime:" #poetry run python car.py -d - echo "car.py runtime:" + #echo "car.py runtime:" poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From f0c65ac1fc9f50c09bc8f1305184471f79d03778 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 15:35:55 -0500 Subject: [PATCH 143/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 3010968..074f370 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -160,7 +160,7 @@ jobs: # echo "car.py -d runtime:" #poetry run python car.py -d #echo "car.py runtime:" - poetry run python car.py + time poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From d5bc0ebcc8f6d60b0dfd253112defd4e7c890b11 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 15:43:36 -0500 Subject: [PATCH 144/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 074f370..ba86073 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -172,7 +172,7 @@ jobs: echo "pass_by_assignment -d runtime:" time poetry run python pass_by_assignment.py echo "pass_by_assignment runtime:" - time poetry run python pass_by_assignment.py + poetry run python pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From 569ff9e48a4df1148317ecc6403aafc5da278877 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 15:46:56 -0500 Subject: [PATCH 145/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index ba86073..deda4f2 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -160,7 +160,7 @@ jobs: # echo "car.py -d runtime:" #poetry run python car.py -d #echo "car.py runtime:" - time poetry run python car.py + poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From 6ab3cc05b9db1685d45c326452ce359e7d2ec97e Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 16:09:08 -0500 Subject: [PATCH 146/165] Adding standalone car example --- .github/workflows/python-app-ubuntu-car.yml | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/python-app-ubuntu-car.yml diff --git a/.github/workflows/python-app-ubuntu-car.yml b/.github/workflows/python-app-ubuntu-car.yml new file mode 100644 index 0000000..cbd142f --- /dev/null +++ b/.github/workflows/python-app-ubuntu-car.yml @@ -0,0 +1,82 @@ +# Adapted from: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Lint and Test on Ubuntu +run-name: ${{ github.actor }} is testing out DDT on Ubuntu (latest) +on: #[push] + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + test-ubuntu: + defaults: + run: + shell: bash + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.7.1 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-pip-wheels + uses: actions/cache@v4 + with: + path: ~/.cache + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + run: | + # set PATH=%PATH%;C:/Users/runneradmin/.local/bin/poetry + #poetry --version + #poetry install --no-interaction --no-root + sudo apt install cloc + + - name: Install library + run: poetry install --no-interaction + - run: | + source $VENV + pytest --version + + - name: pytest oo_car + env: + PY_COLORS: "1" + # continue-on-error: true + run: | + cd tests/oo_car + # echo "car.py -d runtime:" + #poetry run python car.py -d + #echo "car.py runtime:" + poetry run python car.py + poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest coverage badge + env: + PY_COLORS: "1" + run: | + poetry add coverage-badge 2>&1 1>/dev/null + poetry run pip install genbadge[all] + poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage + ls -lah + #poetry run coverage run -m pytest . + poetry run coverage report -m --omit="*/test_*" + poetry run coverage xml --omit="*/test_*" + poetry run coverage html + ls -lah + echo "HTML?" + ls -lah htmlcov + poetry run coverage-badge -o coverage.svg + poetry run genbadge coverage -i coverage.xml + From b19afe420a8eb28c16f2f2bfa4f02f9e2f047659 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 16:15:48 -0500 Subject: [PATCH 147/165] minor change --- .github/workflows/python-app-ubuntu-car.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu-car.yml b/.github/workflows/python-app-ubuntu-car.yml index cbd142f..45b7a93 100644 --- a/.github/workflows/python-app-ubuntu-car.yml +++ b/.github/workflows/python-app-ubuntu-car.yml @@ -75,7 +75,7 @@ jobs: poetry run coverage xml --omit="*/test_*" poetry run coverage html ls -lah - echo "HTML?" + #echo "HTML?" ls -lah htmlcov poetry run coverage-badge -o coverage.svg poetry run genbadge coverage -i coverage.xml From 1d191cd343fa00fd878b8d73ce1dff2d39889503 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 16:24:22 -0500 Subject: [PATCH 148/165] Testing --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index deda4f2..a4559df 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -158,7 +158,7 @@ jobs: run: | cd tests/oo_car # echo "car.py -d runtime:" - #poetry run python car.py -d + poetry run python car.py -d #echo "car.py runtime:" poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From 465a1ebaa679790400ff4c0a7394357f1df7b668 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 17:54:49 -0500 Subject: [PATCH 149/165] time and print removal --- tests/oo_car/car.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 8a41041..9401b4e 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -8,6 +8,7 @@ from pathlib import Path import coverage import sys +import time from src import unit_test_generator from src.unit_test_generator import ( @@ -246,7 +247,9 @@ def main(): if file.suffix in (".py", ".json") and file.absolute() != this_file: logger.debug("%s != %s", file.absolute().name, this_file.name) logger.debug("Deleting %s to ensure clean start", file.name) + print(f"Removing {file}") os.remove(file) + time.sleep(1) if args.disable_unit_test_generation: main() sys.exit(0) From e1714e862dd55c747df0b3dfd25db47ef36749ea Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 18:29:55 -0500 Subject: [PATCH 150/165] sleep 1 --- tests/oo_car/car.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 9401b4e..25e41c2 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -247,8 +247,9 @@ def main(): if file.suffix in (".py", ".json") and file.absolute() != this_file: logger.debug("%s != %s", file.absolute().name, this_file.name) logger.debug("Deleting %s to ensure clean start", file.name) - print(f"Removing {file}") + logger.warning(f"Removing {file=}") os.remove(file) + logger.warning("Sleep 1 s...") time.sleep(1) if args.disable_unit_test_generation: main() From 5cfd17403484f65ef05f0324134ffe5110ee3dc5 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 18:43:45 -0500 Subject: [PATCH 151/165] Update car.py --- tests/oo_car/car.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 25e41c2..4f0e47a 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -249,7 +249,7 @@ def main(): logger.debug("Deleting %s to ensure clean start", file.name) logger.warning(f"Removing {file=}") os.remove(file) - logger.warning("Sleep 1 s...") + logger.info("Sleep 1 s...") time.sleep(1) if args.disable_unit_test_generation: main() From 45713978ab4905b9b39d98f7c79921ef3b82a09a Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 18:55:16 -0500 Subject: [PATCH 152/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index a4559df..24cee94 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -158,9 +158,9 @@ jobs: run: | cd tests/oo_car # echo "car.py -d runtime:" - poetry run python car.py -d + time poetry run python car.py -d #echo "car.py runtime:" - poetry run python car.py + time poetry run python car.py poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From e693b10144c1422c2ab8341e313ac626f66d4341 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Nov 2025 19:25:53 -0500 Subject: [PATCH 153/165] Update python-app-ubuntu.yml --- .github/workflows/python-app-ubuntu.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 24cee94..9ac47af 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -158,9 +158,10 @@ jobs: run: | cd tests/oo_car # echo "car.py -d runtime:" - time poetry run python car.py -d + poetry run python car.py -d #echo "car.py runtime:" - time poetry run python car.py + poetry run python car.py + sleep 1 poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment From 16002298a6b9c703f9a4e10884138347e0178024 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 20:39:21 -0500 Subject: [PATCH 154/165] hide output of gitbadge --- .github/workflows/python-app-ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index 5805f7f..cc30ce1 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -178,7 +178,7 @@ jobs: ls -lah tests/procedural_division ls -lah tests/pass_by_assignment poetry add coverage-badge 2>&1 1>/dev/null - poetry run pip install genbadge[all] + poetry run pip install genbadge[all] 2>&1 1>/dev/null poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah #poetry run coverage run -m pytest . From bb53955cc41f3067dcb7cf8bf28697a4ecf8cd02 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 22:21:08 -0500 Subject: [PATCH 155/165] Bug fixes before presentation --- src/unit_test_generator.py | 24 +- tests/all_types/coverage_str_helper.json | 234 ++++++------ tests/all_types/get_item_at_index.json | 280 +++++++------- .../test_coverage_str_helper_all_types.py | 80 ++-- tests/all_types/test_get_item_at_index.py | 102 ++--- .../all_types/test_update_global_all_types.py | 5 +- tests/all_types/update_global.json | 176 ++++----- tests/fizzbuzz/coverage_str_helper.json | 282 +++++++------- tests/fizzbuzz/fizzbuzz.json | 296 +++++++-------- tests/fizzbuzz/normalize_arg.json | 132 +++---- .../test_coverage_str_helper_fizzbuzz.py | 96 ++--- tests/fizzbuzz/test_fizzbuzz.py | 63 ++-- tests/fizzbuzz/test_normalize_arg_fizzbuzz.py | 61 +-- tests/fizzbuzz/test_update_global_fizzbuzz.py | 130 +++---- tests/fizzbuzz/update_global.json | 186 ++++----- tests/oo_car/Car.brake.json | 142 +++---- tests/oo_car/Car.change_steer_angle.json | 300 +++++++-------- tests/oo_car/Car.constructor.json | 112 +++--- tests/oo_car/Car.gas.json | 216 +++++------ tests/oo_car/Car.is_going_faster_than.json | 102 ++--- tests/oo_car/control_car.py | 244 ------------ tests/oo_car/coverage_str_helper.json | 270 +++++++------ tests/oo_car/normalize_arg.json | 132 +++---- tests/oo_car/test_car_brake.py | 65 ++-- tests/oo_car/test_car_change_steer_angle.py | 96 ++--- tests/oo_car/test_car_constructor.py | 57 +-- tests/oo_car/test_car_gas.py | 151 ++++---- tests/oo_car/test_car_is_going_faster_than.py | 79 ++-- .../oo_car/test_coverage_str_helper_oo_car.py | 93 +++-- tests/oo_car/test_normalize_arg_oo_car.py | 55 +-- tests/oo_car/test_update_global_oo_car.py | 68 +--- tests/oo_car/update_global.json | 181 +++++---- .../add_to_my_set_kwargs.json | 111 +++--- tests/pass_by_assignment/append_list.json | 120 +++--- .../increment_my_list_kwargs.json | 113 +++--- tests/pass_by_assignment/normalize_arg.json | 132 +++---- tests/pass_by_assignment/overwrite_list.json | 100 ++--- .../pass_by_assignment/pass_by_assignment.py | 9 +- .../test_add_to_my_set_kwargs.py | 60 +-- tests/pass_by_assignment/test_append_list.py | 68 ++-- .../test_increment_my_list_kwargs.py | 67 ++-- .../test_normalize_arg_pass_by_assignment.py | 55 +-- .../pass_by_assignment/test_overwrite_list.py | 59 +-- .../test_update_global_pass_by_assignment.py | 5 +- tests/pass_by_assignment/update_global.json | 176 ++++----- .../coverage_str_helper.json | 144 ------- tests/procedural_division/divide_ints.json | 356 +++++++++--------- tests/procedural_division/normalize_arg.json | 130 ++++--- ...coverage_str_helper_procedural_division.py | 48 --- tests/procedural_division/test_divide_ints.py | 153 ++++---- .../test_normalize_arg_procedural_division.py | 58 +-- .../test_update_global_procedural_division.py | 68 +--- tests/procedural_division/update_global.json | 181 +++++---- 53 files changed, 3092 insertions(+), 3631 deletions(-) delete mode 100644 tests/oo_car/control_car.py delete mode 100644 tests/procedural_division/coverage_str_helper.json delete mode 100644 tests/procedural_division/test_coverage_str_helper_procedural_division.py diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 19692d7..8861e23 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -193,7 +193,7 @@ def repr(self)->str: result.append(" exception_message="+repr(self.exception_message)) result.append(" constructor="+repr(self.constructor).replace('\"', "\"")) result.append(" cost="+repr(self.cost)) - result.append(" testable="+repr(self.cost)+')') + result.append(" testable="+repr(self.testable)+')') result_str:str = ','.join(result) #logger.debug("result=%s", result_str) @@ -227,7 +227,7 @@ def __str__(self) -> str: result.append(" exception_message="+repr(self.exception_message)) result.append(" constructor="+repr(self.constructor).replace('"', "\"")) result.append(" cost="+repr(self.cost)) - result.append(" testable="+repr(self.cost)+')') + result.append(" testable="+repr(self.testable)+')') result_str = ','.join(result) logger.debug("result=%s", result_str) @@ -1203,6 +1203,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, this_metadata.types_in_use |= these_types if kwargs: + logger.debug(f"{kwargs=}") this_coverage_info.kwargs = copy.deepcopy(kwargs) # TODO Add the function file and function name @@ -1382,10 +1383,10 @@ def do_the_decorator_thing(func: Callable, function_name:str, args_iterator_class.args_iterator("After") this_coverage_info.args_after = copy.deepcopy(args_iterator_class.args_copy) - logger.debug("args_iterator_class.kwargs_copy=%s", args_iterator_class.kwargs_copy) + logger.debug("args_iterator_class.args_copy=%s", args_iterator_class.args_copy) args_iterator_class.args_iterator("After", "kwargs") - this_coverage_info.kwargs_after = copy.deepcopy(args_iterator_class.kwargs_copy) + this_coverage_info.kwargs_after = copy.deepcopy(kwargs) logger.debug("args_iterator_class.kwargs_copy=%s", args_iterator_class.kwargs_copy) #this_coverage_info.args_after = args_iterator_class.args this_metadata.types_in_use |= args_iterator_class.new_types_in_use @@ -1968,7 +1969,7 @@ def meta_program_function_call( this_state:CoverageInfo, list_of_lines.append(f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"]) or args_after[\"{arg_after}\"] == {arg_after}\n") if isinstance(this_state.kwargs_after, dict) and this_state.kwargs_after.keys(): for arg_after in this_state.kwargs_after.keys(): - list_of_lines.append(f"{indent}assert kwargs[\"{arg_after}\"] == eval(kwargs_after['{arg_after}']) or kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n") + list_of_lines.append(f"{indent}kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n") else: for name in parameter_names: @@ -2006,10 +2007,17 @@ def auto_generate_tests(function_metadata:FunctionMetaData, This is the function that can automatically create a unit test file for each decorated function. The contents of the unit test file(s) are created by appending - to lists of strings, these lists of strings are evenutally + to lists of strings, these lists of strings are eventually written to a file, one per decorated function. """ + logger.debug("Dropping any untestable records") + state = {k:v for k,v in state.items() if v.testable} + if not state: + logger.warning("No testable inputs for %s, skipping it completely", function_name) + with open(result_file, "w", encoding="utf-8") as st: + st.write("\"\"\"\nNo testable inputs - see accompanying JSON file.\n\"\"\"") + return print(f"Auto-generating test for {function_name}...") outdir = outdir.absolute() tests_dir = tests_dir.absolute() @@ -2403,7 +2411,7 @@ def auto_generate_tests(function_metadata:FunctionMetaData, logger.error(e.stdout.decode()) logger.info("Re-formatted %s with black formatter", result_file) - ''' + try: subprocess.run( f"ruff {result_file} --fix".split(), check=True, @@ -2417,7 +2425,7 @@ def auto_generate_tests(function_metadata:FunctionMetaData, logger.error(e.stdout.decode()) logger.info("Linted %s with ruff", result_file) - ''' + # Return hash of resulting string here h = hashlib.new('sha256') h.update(str(sorted(test_str_list_def_dict.items())).encode()) diff --git a/tests/all_types/coverage_str_helper.json b/tests/all_types/coverage_str_helper.json index cc98498..2d354a0 100644 --- a/tests/all_types/coverage_str_helper.json +++ b/tests/all_types/coverage_str_helper.json @@ -1,118 +1,118 @@ -{ - "name": "coverage_str_helper", - "parameter_names": [ - "this_list", - "non_code_lines" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1748, - 1749, - 1750, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1775, - 1776, - 1778, - 1779, - 1780, - 1782, - 1784 - ], - "non_code_lines": [ - 1765, - 1774, - 1777, - 1781, - 1783 - ], - "coverage_io": { - "0": { - "args_before": [ - "[32]", - "{37}" - ], - "args_after": { - "this_list": "[32]", - "non_code_lines": "{37}" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "[32]", - "expected_type": "list", - "coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1770, - 1778, - 1779, - 1780, - 1784 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 37.5, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1770, - 1778, - 1779, - 1780, - 1784 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "coverage_str_helper", + "parameter_names": [ + "this_list", + "non_code_lines" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1759, + 1760, + 1761, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1773, + 1774, + 1775, + 1777, + 1778, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1786, + 1787, + 1789, + 1790, + 1791, + 1793, + 1795 + ], + "non_code_lines": [ + 1776, + 1785, + 1788, + 1792, + 1794 + ], + "coverage_io": { + "0": { + "args_before": [ + "[33]", + "{38}" + ], + "args_after": { + "this_list": "[33]", + "non_code_lines": "{38}" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "[33]", + "expected_type": "list", + "coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1781, + 1789, + 1790, + 1791, + 1795 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 37.5, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1781, + 1789, + 1790, + 1791, + 1795 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/all_types/get_item_at_index.json b/tests/all_types/get_item_at_index.json index 7c5d48d..ccb0114 100644 --- a/tests/all_types/get_item_at_index.json +++ b/tests/all_types/get_item_at_index.json @@ -1,141 +1,141 @@ -{ - "name": "get_item_at_index", - "parameter_names": [ - "iterable", - "index" - ], - "is_method": false, - "source_file": null, - "lines": [ - 31, - 32, - 33, - 34, - 35, - 36, - 38 - ], - "non_code_lines": [ - 37 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"The quick red fox jumped over the lazy brown dog\"", - "3" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": " ", - "expected_type": "str", - "coverage": [ - 31, - 33, - 35, - 38 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "\"a test string\"", - "-5" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 31, - 33, - 35, - 36 - ], - "exception_type": "", - "exception_message": "index must be in range [0, 12], was -5", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "2": { - "args_before": [ - "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)", - "50" - ], - "args_after": { - "iterable": "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 31, - 33, - 34 - ], - "exception_type": "", - "exception_message": "index must be in range [0, 9], was 50", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "3": { - "args_before": [ - "[-1, -2, -3, -4]", - "0" - ], - "args_after": { - "iterable": "[-1, -2, -3, -4]" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "-1", - "expected_type": "int", - "coverage": [ - 31, - 33, - 35, - 38 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 85.71, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 31, - 33, - 34, - 35, - 36, - 38 - ], - "needs_pytest": true, - "exceptions_raised": [ - "" - ], - "callable_files": { - "get_item_at_index": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\all_types\\all_types.py" - } +{ + "name": "get_item_at_index", + "parameter_names": [ + "iterable", + "index" + ], + "is_method": false, + "source_file": null, + "lines": [ + 32, + 33, + 34, + 35, + 36, + 37, + 39 + ], + "non_code_lines": [ + 38 + ], + "coverage_io": { + "0": { + "args_before": [ + "\"The quick red fox jumped over the lazy brown dog\"", + "3" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": " ", + "expected_type": "str", + "coverage": [ + 32, + 34, + 36, + 39 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "1": { + "args_before": [ + "\"a test string\"", + "-5" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 32, + 34, + 36, + 37 + ], + "exception_type": "", + "exception_message": "index must be in range [0, 12], was -5", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "2": { + "args_before": [ + "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)", + "50" + ], + "args_after": { + "iterable": "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 32, + 34, + 35 + ], + "exception_type": "", + "exception_message": "index must be in range [0, 9], was 50", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "3": { + "args_before": [ + "[-1, -2, -3, -4]", + "0" + ], + "args_after": { + "iterable": "[-1, -2, -3, -4]" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "-1", + "expected_type": "int", + "coverage": [ + 32, + 34, + 36, + 39 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 85.71, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 32, + 34, + 35, + 36, + 37, + 39 + ], + "needs_pytest": true, + "exceptions_raised": [ + "" + ], + "callable_files": { + "get_item_at_index": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\all_types\\all_types.py" + } } \ No newline at end of file diff --git a/tests/all_types/test_coverage_str_helper_all_types.py b/tests/all_types/test_coverage_str_helper_all_types.py index 86a1baa..ac0f852 100644 --- a/tests/all_types/test_coverage_str_helper_all_types.py +++ b/tests/all_types/test_coverage_str_helper_all_types.py @@ -1,40 +1,40 @@ -""" -Programmatically generated test function for coverage_str_helper() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to coverage_str_helper: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 37.5% of coverage_str_helper's lines -# Line(s) not covered by ANY of the tests below: -# ['1750', '1756-1764', '1766-1769', '1771-1773', '1775-1776'] -@pytest.mark.parametrize( - "this_list, non_code_lines, expected_result, args_after", - [ - ([32], {37}, "[32]", {"this_list": "[32]", "non_code_lines": "{37}"}), - ], -) -def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): - """ - Programmatically generated test function for coverage_str_helper() - """ - result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) +""" +Programmatically generated test function for coverage_str_helper() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to coverage_str_helper: + + +# In sum, these tests covered 37.5% of coverage_str_helper's lines +# Line(s) not covered by ANY of the tests below: +# ['1793', '1761', '1767-1775', '1777-1780', '1782-1784', '1786-1787'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, non_code_lines, expected_result, args_after", + [ + ([33], {38}, "[33]", {"this_list": "[33]", "non_code_lines": "{38}"}), + ], + ids=counter, +) +def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): + """ + Programmatically generated test function for coverage_str_helper() + """ + result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index f824263..2456493 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -1,48 +1,54 @@ -""" -Programmatically generated test function for get_item_at_index() -""" - -import re -import pytest -from collections import OrderedDict -from tests.all_types import all_types - - -# In sum, these tests covered 85.71% of get_item_at_index's lines -# Line(s) not covered by ANY of the tests below: -# [32] -@pytest.mark.parametrize( - "iterable, index, exception_type, exception_message, expected_result, args_after", - [ - ("The quick red fox jumped over the lazy brown dog", 3, "N/A", "N/A", " ", {}), - ( - "a test string", - -5, - ValueError, - "index must be in range [0, 12], was -5", - "None", - {}, - ), - ( - (5, 6, 7, 8, 9, 10, 11, 12, 13, 14), - 50, - ValueError, - "index must be in range [0, 9], was 50", - "None", - {"iterable": "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)"}, - ), - ([-1, -2, -3, -4], 0, "N/A", "N/A", "-1", {"iterable": "[-1, -2, -3, -4]"}), - ], -) -def test_get_item_at_index( - iterable, index, exception_type, exception_message, expected_result, args_after -): - """ - Programmatically generated test function for get_item_at_index() - """ - if exception_type != "N/A": - with pytest.raises(exception_type, match=re.escape(exception_message)): - all_types.get_item_at_index(iterable, index) - else: - result = all_types.get_item_at_index(iterable, index) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for get_item_at_index() +""" + +import re +import pytest +import all_types + + +# In sum, these tests covered 85.71% of get_item_at_index's lines +# Line(s) not covered by ANY of the tests below: +# [33] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "iterable, index, exception_type, exception_message, expected_result, args_after", + [ + ("The quick red fox jumped over the lazy brown dog", 3, "N/A", "N/A", " ", {}), + ( + "a test string", + -5, + ValueError, + "index must be in range [0, 12], was -5", + "None", + {}, + ), + ( + (5, 6, 7, 8, 9, 10, 11, 12, 13, 14), + 50, + ValueError, + "index must be in range [0, 9], was 50", + "None", + {"iterable": "(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)"}, + ), + ([-1, -2, -3, -4], 0, "N/A", "N/A", "-1", {"iterable": "[-1, -2, -3, -4]"}), + ], + ids=counter, +) +def test_get_item_at_index( + iterable, index, exception_type, exception_message, expected_result, args_after +): + """ + Programmatically generated test function for get_item_at_index() + """ + if exception_type != "N/A": + with pytest.raises(exception_type, match=re.escape(exception_message)): + all_types.get_item_at_index(iterable, index) + else: + result = all_types.get_item_at_index(iterable, index) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/all_types/test_update_global_all_types.py b/tests/all_types/test_update_global_all_types.py index e1c5f58..53dfbc4 100644 --- a/tests/all_types/test_update_global_all_types.py +++ b/tests/all_types/test_update_global_all_types.py @@ -1,2 +1,3 @@ -import warnings -warnings.warn("No testable samples!") \ No newline at end of file +""" +No testable inputs - see accompanying JSON file. +""" \ No newline at end of file diff --git a/tests/all_types/update_global.json b/tests/all_types/update_global.json index 309f5be..7236818 100644 --- a/tests/all_types/update_global.json +++ b/tests/all_types/update_global.json @@ -1,89 +1,89 @@ -{ - "name": "update_global", - "parameter_names": [ - "obj", - "this_global", - "phase", - "this_coverage_info" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1690, - 1691, - 1692, - 1693, - 1694, - 1695, - 1696, - 1698, - 1706, - 1707, - 1708, - 1709, - 1710 - ], - "non_code_lines": [ - 1697, - 1699, - 1700, - 1701, - 1702, - 1703, - 1704, - 1705 - ], - "coverage_io": { - "0": { - "args_before": [ - "", - "\"logger\"", - "\"Before\"", - "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - ], - "args_after": { - "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['[32]','{37}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "src.unit_test_generator.CoverageInfo", - "coverage": [ - 1690, - 1691, - 1692 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": false - } - }, - "coverage_percentage": 23.08, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler", - "src.unit_test_generator.CoverageInfo" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1690, - 1691, - 1692 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "update_global", + "parameter_names": [ + "obj", + "this_global", + "phase", + "this_coverage_info" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1709, + 1717, + 1718, + 1719, + 1720, + 1721 + ], + "non_code_lines": [ + 1708, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716 + ], + "coverage_io": { + "0": { + "args_before": [ + "", + "\"logger\"", + "\"Before\"", + "CoverageInfo(args_before=['[33]','{38}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + ], + "args_after": { + "obj": "", + "this_coverage_info": "CoverageInfo(args_before=['[33]','{38}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['[33]','{38}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "src.unit_test_generator.CoverageInfo", + "coverage": [ + 1701, + 1702, + 1703 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": false + } + }, + "coverage_percentage": 23.08, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "src.unit_test_generator.CoverageInfo" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1701, + 1702, + 1703 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/fizzbuzz/coverage_str_helper.json b/tests/fizzbuzz/coverage_str_helper.json index 562aa00..d66660a 100644 --- a/tests/fizzbuzz/coverage_str_helper.json +++ b/tests/fizzbuzz/coverage_str_helper.json @@ -1,144 +1,140 @@ -{ - "name": "coverage_str_helper", - "parameter_names": [ - "this_list", - "non_code_lines" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1748, - 1749, - 1750, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1775, - 1776, - 1778, - 1779, - 1780, - 1782, - 1784 - ], - "non_code_lines": [ - 1765, - 1774, - 1777, - 1781, - 1783 - ], - "coverage_io": { - "0": { - "args_before": [ - "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - ], - "args_after": { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "['1696', '1708-1709', '1691-1692', '1694-1695']", - "expected_type": "list", - "coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 78.12, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "coverage_str_helper", + "parameter_names": [ + "this_list", + "non_code_lines" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1759, + 1760, + 1761, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1773, + 1774, + 1775, + 1777, + 1778, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1786, + 1787, + 1789, + 1790, + 1791, + 1793, + 1795 + ], + "non_code_lines": [ + 1776, + 1785, + 1788, + 1792, + 1794 + ], + "coverage_io": { + "0": { + "args_before": [ + "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + ], + "args_after": { + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "['1702-1703', '1705-1707', '1719-1720']", + "expected_type": "list", + "coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1773, + 1774, + 1775, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1789, + 1795 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 71.88, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1773, + 1774, + 1775, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1789, + 1795 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/fizzbuzz/fizzbuzz.json b/tests/fizzbuzz/fizzbuzz.json index 8581f9b..a487d0a 100644 --- a/tests/fizzbuzz/fizzbuzz.json +++ b/tests/fizzbuzz/fizzbuzz.json @@ -1,149 +1,149 @@ -{ - "name": "fizzbuzz", - "parameter_names": [ - "number" - ], - "is_method": false, - "source_file": null, - "lines": [ - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 59, - 60 - ], - "non_code_lines": [ - 58 - ], - "coverage_io": { - "0": { - "args_before": [ - "6" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "mode": "a_test" - }, - "globals_after": {}, - "expected_result": "Mode 'a_test' invalid for fizzbuzz()", - "expected_type": "str", - "coverage": [ - 43, - 44, - 51, - 59, - 60 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "30" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "mode": "buzzfizz" - }, - "globals_after": {}, - "expected_result": "30 with mode='buzzfizz' yields 'buzzfizz'", - "expected_type": "str", - "coverage": [ - 43, - 44, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 60 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "2": { - "args_before": [ - "30" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "mode": "fizzbuzz" - }, - "globals_after": {}, - "expected_result": "30 with mode='fizzbuzz' yields 'fizzbuzz'", - "expected_type": "str", - "coverage": [ - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 60 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [], - "global_vars_read_from": [ - "mode" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 59, - 60 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "fizzbuzz": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\fizzbuzz\\fizzbuzz.py" - } +{ + "name": "fizzbuzz", + "parameter_names": [ + "number" + ], + "is_method": false, + "source_file": null, + "lines": [ + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 60, + 61 + ], + "non_code_lines": [ + 59 + ], + "coverage_io": { + "0": { + "args_before": [ + "6" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "mode": "a_test" + }, + "globals_after": {}, + "expected_result": "Mode 'a_test' invalid for fizzbuzz()", + "expected_type": "str", + "coverage": [ + 44, + 45, + 52, + 60, + 61 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "1": { + "args_before": [ + "30" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "mode": "buzzfizz" + }, + "globals_after": {}, + "expected_result": "30 with mode='buzzfizz' yields 'buzzfizz'", + "expected_type": "str", + "coverage": [ + 44, + 45, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 61 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "2": { + "args_before": [ + "30" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "mode": "fizzbuzz" + }, + "globals_after": {}, + "expected_result": "30 with mode='fizzbuzz' yields 'fizzbuzz'", + "expected_type": "str", + "coverage": [ + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 61 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [], + "global_vars_read_from": [ + "mode" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 60, + 61 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "fizzbuzz": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\fizzbuzz\\fizzbuzz.py" + } } \ No newline at end of file diff --git a/tests/fizzbuzz/normalize_arg.json b/tests/fizzbuzz/normalize_arg.json index 369d3a4..aac86a8 100644 --- a/tests/fizzbuzz/normalize_arg.json +++ b/tests/fizzbuzz/normalize_arg.json @@ -1,67 +1,67 @@ -{ - "name": "normalize_arg", - "parameter_names": [ - "arg" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1718, - 1719, - 1720, - 1721, - 1722, - 1723, - 1725, - 1726, - 1727, - 1728 - ], - "non_code_lines": [ - 1724 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)\"" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "str", - "coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 60.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "normalize_arg", + "parameter_names": [ + "arg" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1729, + 1730, + 1731, + 1732, + 1733, + 1734, + 1736, + 1737, + 1738, + 1739 + ], + "non_code_lines": [ + 1735 + ], + "coverage_io": { + "0": { + "args_before": [ + "\"CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)\"" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "str", + "coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 60.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py b/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py index 27c9e7b..6e329d3 100644 --- a/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py +++ b/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py @@ -1,48 +1,48 @@ -""" -Programmatically generated test function for coverage_str_helper() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to coverage_str_helper: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 78.12% of coverage_str_helper's lines -# Line(s) not covered by ANY of the tests below: -# ['1750', '1761', '1775-1776', '1779-1780'] -@pytest.mark.parametrize( - "this_list, non_code_lines, expected_result, args_after", - [ - ( - [1696, 1708, 1709, 1691, 1692, 1694, 1695], - {1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}, - "['1696', '1708-1709', '1691-1692', '1694-1695']", - { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}", - }, - ), - ], -) -def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): - """ - Programmatically generated test function for coverage_str_helper() - """ - result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) +""" +Programmatically generated test function for coverage_str_helper() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to coverage_str_helper: + + +# In sum, these tests covered 71.88% of coverage_str_helper's lines +# Line(s) not covered by ANY of the tests below: +# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, non_code_lines, expected_result, args_after", + [ + ( + [1702, 1703, 1705, 1706, 1707, 1719, 1720], + {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, + "['1702-1703', '1705-1707', '1719-1720']", + { + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", + }, + ), + ], + ids=counter, +) +def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): + """ + Programmatically generated test function for coverage_str_helper() + """ + result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) diff --git a/tests/fizzbuzz/test_fizzbuzz.py b/tests/fizzbuzz/test_fizzbuzz.py index 27e71df..a51e286 100644 --- a/tests/fizzbuzz/test_fizzbuzz.py +++ b/tests/fizzbuzz/test_fizzbuzz.py @@ -1,29 +1,34 @@ -""" -Programmatically generated test function for fizzbuzz() -""" - -import re -import pytest -from collections import OrderedDict -import fizzbuzz -from _pytest.monkeypatch import MonkeyPatch - - -# In sum, these tests covered 100.0% of fizzbuzz's lines -@pytest.mark.parametrize( - "number, expected_result, globals_before", - [ - (6, "Mode 'a_test' invalid for fizzbuzz()", {"mode": "a_test"}), - (30, "30 with mode='buzzfizz' yields 'buzzfizz'", {"mode": "buzzfizz"}), - (30, "30 with mode='fizzbuzz' yields 'fizzbuzz'", {"mode": "fizzbuzz"}), - ], -) -def test_fizzbuzz(number, expected_result, globals_before): - """ - Programmatically generated test function for fizzbuzz() - """ - monkeypatch = MonkeyPatch() - for k, v in globals_before.items(): - monkeypatch.setattr(fizzbuzz, k, v) - result = fizzbuzz.fizzbuzz(number) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for fizzbuzz() +""" + +import pytest +from tests.fizzbuzz import fizzbuzz +from _pytest.monkeypatch import MonkeyPatch + + +# In sum, these tests covered 100.0% of fizzbuzz's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "number, expected_result, globals_before", + [ + (6, "Mode 'a_test' invalid for fizzbuzz()", {"mode": "a_test"}), + (30, "30 with mode='buzzfizz' yields 'buzzfizz'", {"mode": "buzzfizz"}), + (30, "30 with mode='fizzbuzz' yields 'fizzbuzz'", {"mode": "fizzbuzz"}), + ], + ids=counter, +) +def test_fizzbuzz(number, expected_result, globals_before): + """ + Programmatically generated test function for fizzbuzz() + """ + monkeypatch = MonkeyPatch() + for k, v in globals_before.items(): + monkeypatch.setattr(fizzbuzz, k, v) + result = fizzbuzz.fizzbuzz(number) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py b/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py index 1da82e6..93f100e 100644 --- a/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py +++ b/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py @@ -1,28 +1,33 @@ -""" -Programmatically generated test function for normalize_arg() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - - -# In sum, these tests covered 60.0% of normalize_arg's lines -# Line(s) not covered by ANY of the tests below: -# ['1721', '1723', '1726-1727'] -@pytest.mark.parametrize( - "arg, expected_result", - [ - ( - "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - ), - ], -) -def test_normalize_arg(arg, expected_result): - """ - Programmatically generated test function for normalize_arg() - """ - result = unit_test_generator.normalize_arg(arg) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for normalize_arg() +""" + +import pytest +from src import unit_test_generator + + +# In sum, these tests covered 60.0% of normalize_arg's lines +# Line(s) not covered by ANY of the tests below: +# ['1732', '1734', '1737-1738'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "arg, expected_result", + [ + ( + "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + ), + ], + ids=counter, +) +def test_normalize_arg(arg, expected_result): + """ + Programmatically generated test function for normalize_arg() + """ + result = unit_test_generator.normalize_arg(arg) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/fizzbuzz/test_update_global_fizzbuzz.py b/tests/fizzbuzz/test_update_global_fizzbuzz.py index 3e2ad21..8985317 100644 --- a/tests/fizzbuzz/test_update_global_fizzbuzz.py +++ b/tests/fizzbuzz/test_update_global_fizzbuzz.py @@ -1,65 +1,65 @@ -""" -Programmatically generated test function for update_global() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to update_global: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler -from src.unit_test_generator import CoverageInfo - - -# In sum, these tests covered 46.15% of update_global's lines -# Line(s) not covered by ANY of the tests below: -# ['1696', '1708-1709', '1691-1692', '1694-1695'] -@pytest.mark.parametrize( - "obj, this_global, phase, this_coverage_info, expected_result, args_after", - [ - ( - "fizzbuzz", - "mode", - "Before", - CoverageInfo( - args_before=["6"], - args_after={}, - kwargs={}, - kwargs_after={}, - globals_before={}, - globals_after={}, - expected_result="", - expected_type="", - coverage=[], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - testable=0.0, - ), - "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - { - "this_coverage_info": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - ), - ], -) -def test_update_global( - obj, this_global, phase, this_coverage_info, expected_result, args_after -): - """ - Programmatically generated test function for update_global() - """ - result = unit_test_generator.update_global( - obj, this_global, phase, this_coverage_info - ) - assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) +""" +Programmatically generated test function for update_global() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to update_global: +from src.unit_test_generator import CoverageInfo + + +# In sum, these tests covered 46.15% of update_global's lines +# Line(s) not covered by ANY of the tests below: +# ['1702-1703', '1705-1707', '1719-1720'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "obj, this_global, phase, this_coverage_info, expected_result, args_after", + [ + ( + "fizzbuzz", + "mode", + "Before", + CoverageInfo( + args_before=["6"], + args_after={}, + kwargs={}, + kwargs_after={}, + globals_before={}, + globals_after={}, + expected_result="", + expected_type="", + coverage=[], + exception_type="", + exception_message="", + constructor="", + cost=0.0, + testable=True, + ), + "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + { + "this_coverage_info": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + ), + ], + ids=counter, +) +def test_update_global( + obj, this_global, phase, this_coverage_info, expected_result, args_after +): + """ + Programmatically generated test function for update_global() + """ + result = unit_test_generator.update_global( + obj, this_global, phase, this_coverage_info + ) + assert result == expected_result or result == eval(expected_result) + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) diff --git a/tests/fizzbuzz/update_global.json b/tests/fizzbuzz/update_global.json index e7a5f89..a7a959d 100644 --- a/tests/fizzbuzz/update_global.json +++ b/tests/fizzbuzz/update_global.json @@ -1,94 +1,94 @@ -{ - "name": "update_global", - "parameter_names": [ - "obj", - "this_global", - "phase", - "this_coverage_info" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1690, - 1691, - 1692, - 1693, - 1694, - 1695, - 1696, - 1698, - 1706, - 1707, - 1708, - 1709, - 1710 - ], - "non_code_lines": [ - 1697, - 1699, - 1700, - 1701, - 1702, - 1703, - 1704, - 1705 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"fizzbuzz\"", - "\"mode\"", - "\"Before\"", - "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - ], - "args_after": { - "this_coverage_info": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "src.unit_test_generator.CoverageInfo", - "coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 46.15, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler", - "src.unit_test_generator.CoverageInfo" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "update_global", + "parameter_names": [ + "obj", + "this_global", + "phase", + "this_coverage_info" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1709, + 1717, + 1718, + 1719, + 1720, + 1721 + ], + "non_code_lines": [ + 1708, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716 + ], + "coverage_io": { + "0": { + "args_before": [ + "\"fizzbuzz\"", + "\"mode\"", + "\"Before\"", + "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + ], + "args_after": { + "this_coverage_info": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "src.unit_test_generator.CoverageInfo", + "coverage": [ + 1701, + 1704, + 1709, + 1717, + 1718, + 1721 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 46.15, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "src.unit_test_generator.CoverageInfo" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1701, + 1704, + 1709, + 1717, + 1718, + 1721 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/oo_car/Car.brake.json b/tests/oo_car/Car.brake.json index f2fd9a4..19869b0 100644 --- a/tests/oo_car/Car.brake.json +++ b/tests/oo_car/Car.brake.json @@ -1,72 +1,72 @@ -{ - "name": "Car.brake", - "parameter_names": [ - "self", - "rate", - "duration" - ], - "is_method": true, - "source_file": null, - "lines": [ - 51, - 52, - 53, - 54, - 55, - 56, - 57 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "-1", - "1" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "9", - "expected_type": "int", - "coverage": [ - 51, - 52, - 54, - 56, - 57 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"Red\", 10, 0)", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 71.43, - "types_in_use": [ - "car.Car", - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 51, - 52, - 54, - 56, - 57 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "brake": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - } +{ + "name": "Car.brake", + "parameter_names": [ + "self", + "rate", + "duration" + ], + "is_method": true, + "source_file": null, + "lines": [ + 53, + 54, + 55, + 56, + 57, + 58, + 59 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "-1", + "1" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "9", + "expected_type": "int", + "coverage": [ + 53, + 54, + 56, + 58, + 59 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"Red\", 10, 0)", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 71.43, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "tests.oo_car.car.Car" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 53, + 54, + 56, + 58, + 59 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "brake": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" + } } \ No newline at end of file diff --git a/tests/oo_car/Car.change_steer_angle.json b/tests/oo_car/Car.change_steer_angle.json index f0c8803..a2e4a2a 100644 --- a/tests/oo_car/Car.change_steer_angle.json +++ b/tests/oo_car/Car.change_steer_angle.json @@ -1,151 +1,151 @@ -{ - "name": "Car.change_steer_angle", - "parameter_names": [ - "self", - "angle" - ], - "is_method": true, - "source_file": null, - "lines": [ - 80, - 81, - 82, - 84, - 87, - 88, - 87, - 89, - 87, - 91 - ], - "non_code_lines": [ - 83, - 85, - 86, - 90 - ], - "coverage_io": { - "0": { - "args_before": [ - "-1080" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 80, - 81, - 82 - ], - "exception_type": "", - "exception_message": "angle=-1080 out of bounds!", - "constructor": "Car(\"Green\", 48, 90)", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "180" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "210", - "expected_type": "int", - "coverage": [ - 80, - 81, - 84, - 87, - 91 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"Blue\", 0.0, 30)", - "cost": 0.0, - "testable": true - }, - "2": { - "args_before": [ - "30" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "30", - "expected_type": "int", - "coverage": [ - 80, - 81, - 84, - 87, - 91 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"Red\", 9, 0)", - "cost": 0.0, - "testable": true - }, - "3": { - "args_before": [ - "90" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "60", - "expected_type": "int", - "coverage": [ - 80, - 81, - 84, - 87, - 91 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"White\", 20, -30)", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 60.0, - "types_in_use": [ - "car.Car", - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 80, - 81, - 82, - 84, - 87, - 91 - ], - "needs_pytest": true, - "exceptions_raised": [ - "" - ], - "callable_files": { - "change_steer_angle": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - } +{ + "name": "Car.change_steer_angle", + "parameter_names": [ + "self", + "angle" + ], + "is_method": true, + "source_file": null, + "lines": [ + 82, + 83, + 84, + 86, + 89, + 90, + 89, + 91, + 89, + 93 + ], + "non_code_lines": [ + 85, + 87, + 88, + 92 + ], + "coverage_io": { + "0": { + "args_before": [ + "-1080" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 82, + 83, + 84 + ], + "exception_type": "", + "exception_message": "angle=-1080 out of bounds!", + "constructor": "Car(\"Green\", 48, 90)", + "cost": 0.0, + "testable": true + }, + "1": { + "args_before": [ + "180" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "210", + "expected_type": "int", + "coverage": [ + 82, + 83, + 86, + 89, + 93 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"Blue\", 0.0, 30)", + "cost": 0.0, + "testable": true + }, + "2": { + "args_before": [ + "30" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "30", + "expected_type": "int", + "coverage": [ + 82, + 83, + 86, + 89, + 93 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"Red\", 9, 0)", + "cost": 0.0, + "testable": true + }, + "3": { + "args_before": [ + "90" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "60", + "expected_type": "int", + "coverage": [ + 82, + 83, + 86, + 89, + 93 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"White\", 20, -30)", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 60.0, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "tests.oo_car.car.Car" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 82, + 83, + 84, + 86, + 89, + 93 + ], + "needs_pytest": true, + "exceptions_raised": [ + "" + ], + "callable_files": { + "change_steer_angle": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" + } } \ No newline at end of file diff --git a/tests/oo_car/Car.constructor.json b/tests/oo_car/Car.constructor.json index 258f078..3bc69cf 100644 --- a/tests/oo_car/Car.constructor.json +++ b/tests/oo_car/Car.constructor.json @@ -1,57 +1,57 @@ -{ - "name": "Car.__init__", - "parameter_names": [ - "self", - "color", - "speed", - "steer_angle" - ], - "is_method": true, - "source_file": null, - "lines": [ - 42, - 43, - 44 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "\"Red\"", - "10", - "0" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 42, - 43, - 44 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 42, - 43, - 44 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "__init__": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - } +{ + "name": "Car.__init__", + "parameter_names": [ + "self", + "color", + "speed", + "steer_angle" + ], + "is_method": true, + "source_file": null, + "lines": [ + 44, + 45, + 46 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "\"Red\"", + "10", + "0" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 44, + 45, + 46 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 44, + 45, + 46 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "__init__": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" + } } \ No newline at end of file diff --git a/tests/oo_car/Car.gas.json b/tests/oo_car/Car.gas.json index d910fa7..96948d3 100644 --- a/tests/oo_car/Car.gas.json +++ b/tests/oo_car/Car.gas.json @@ -1,109 +1,109 @@ -{ - "name": "Car.gas", - "parameter_names": [ - "self", - "rate", - "duration" - ], - "is_method": true, - "source_file": null, - "lines": [ - 67, - 68, - 69, - 70, - 71, - 72 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "-1", - "1" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "method_call_counter": 0 - }, - "globals_after": { - "method_call_counter": 1 - }, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 67, - 68, - 69, - 70 - ], - "exception_type": "", - "exception_message": "Gas rate (m/s) must be positive.", - "constructor": "Car(\"Red\", 10, 0)", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "2", - "2" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "method_call_counter": 1 - }, - "globals_after": { - "method_call_counter": 2 - }, - "expected_result": "16", - "expected_type": "int", - "coverage": [ - 67, - 68, - 69, - 71, - 72 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"White\", 12, -30)", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [ - "car.Car", - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger", - "method_call_counter" - ], - "global_vars_written_to": [ - "method_call_counter" - ], - "unified_test_coverage": [ - 67, - 68, - 69, - 70, - 71, - 72 - ], - "needs_pytest": true, - "exceptions_raised": [ - "" - ], - "callable_files": { - "gas": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - } +{ + "name": "Car.gas", + "parameter_names": [ + "self", + "rate", + "duration" + ], + "is_method": true, + "source_file": null, + "lines": [ + 69, + 70, + 71, + 72, + 73, + 74 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "-1", + "1" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "method_call_counter": 0 + }, + "globals_after": { + "method_call_counter": 1 + }, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 69, + 70, + 71, + 72 + ], + "exception_type": "", + "exception_message": "Gas rate (m/s) must be positive.", + "constructor": "Car(\"Red\", 10, 0)", + "cost": 0.0, + "testable": true + }, + "1": { + "args_before": [ + "2", + "2" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "method_call_counter": 1 + }, + "globals_after": { + "method_call_counter": 2 + }, + "expected_result": "16", + "expected_type": "int", + "coverage": [ + 69, + 70, + 71, + 73, + 74 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"White\", 12, -30)", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "tests.oo_car.car.Car" + ], + "global_vars_read_from": [ + "logger", + "method_call_counter" + ], + "global_vars_written_to": [ + "method_call_counter" + ], + "unified_test_coverage": [ + 69, + 70, + 71, + 72, + 73, + 74 + ], + "needs_pytest": true, + "exceptions_raised": [ + "" + ], + "callable_files": { + "gas": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" + } } \ No newline at end of file diff --git a/tests/oo_car/Car.is_going_faster_than.json b/tests/oo_car/Car.is_going_faster_than.json index 026adb3..0cb637c 100644 --- a/tests/oo_car/Car.is_going_faster_than.json +++ b/tests/oo_car/Car.is_going_faster_than.json @@ -1,52 +1,52 @@ -{ - "name": "Car.is_going_faster_than", - "parameter_names": [ - "self", - "other_car" - ], - "is_method": true, - "source_file": null, - "lines": [ - 127 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "Car(\"White\", 19, 0)" - ], - "args_after": { - "other_car": "Car(\"White\", 19, 0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "True", - "expected_type": "bool", - "coverage": [ - 127 - ], - "exception_type": "", - "exception_message": "", - "constructor": "Car(\"Red\", 20, 0)", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [ - "__main__.Car", - "car.Car" - ], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 127 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "is_going_faster_than": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - } +{ + "name": "Car.is_going_faster_than", + "parameter_names": [ + "self", + "other_car" + ], + "is_method": true, + "source_file": null, + "lines": [ + 129 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "Car(\"White\", 19, 0)" + ], + "args_after": { + "other_car": "Car(\"White\", 19, 0)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "True", + "expected_type": "bool", + "coverage": [ + 129 + ], + "exception_type": "", + "exception_message": "", + "constructor": "Car(\"Red\", 20, 0)", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [ + "__main__.Car", + "tests.oo_car.car.Car" + ], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 129 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "is_going_faster_than": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" + } } \ No newline at end of file diff --git a/tests/oo_car/control_car.py b/tests/oo_car/control_car.py deleted file mode 100644 index db03bcc..0000000 --- a/tests/oo_car/control_car.py +++ /dev/null @@ -1,244 +0,0 @@ -""" -Object-oriented test sample -""" - -import argparse -import logging -import os -from pathlib import Path -import coverage - - -FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-25s:%(lineno)-4d:%(message)s' -logging.basicConfig(level=logging.INFO, format=FMT_STR) -logger = logging.getLogger(__name__) - -# The global below is simply so the update_global() function in -# unit_test_generator.py will be executed, without which that -# unit test will be empty and will raise an exception. -method_call_counter = 0 # pylint: disable=invalid-name - -class Car: - """ - A simple class with basic methods for testing the - unit_test_generator_decorator on class methods. - """ - MAX_ANGLE = 720 - MIN_ANGLE = -720 - def __init__( self, - color:str="black",# pylint: disable= used-before-assignment - speed:float=0.0, - steer_angle:int=0): - """ - Create a new Car class with car color, - initial speed and steering angle - """ - self.color = color - self.speed = speed - self.steer_angle = steer_angle - - def brake(self, rate:float, duration:int=1)-> float: - """ - Apply the brake pedal at some negative "rate" - (e.g. -N m/s for "duration" seconds) - """ - logger.debug("rate=%.2f duration=%d", rate, duration) - if rate > 0: - raise ValueError("Brake rate (m/s) must be negative.") - if duration < 0: - raise ValueError("Duration (s) must be positive.") - self.speed = max(0.0, self.speed+rate*duration) - return self.speed - - def gas(self, - rate:float, - duration:int=1): - """ - Apply the gas pedal at some positive "rate" - (e.g. +N m/s for "duration" seconds) - """ - global method_call_counter # pylint: disable=global-statement - method_call_counter +=1 - logger.debug("rate=%.2f duration=%d", rate, duration) - if rate < 0: - raise ValueError("Gas rate (m/s) must be positive.") - self.speed = max(0.0, self.speed+rate*duration) - return self.speed - - def change_steer_angle(self, angle:int): - """ - Add this new steer angle (could be a negative value) - to the current steer angle, and clamp to restrict - within the valid range. - """ - logger.debug("angle=%d", angle) - if angle > self.MAX_ANGLE or angle < self.MIN_ANGLE: - raise AssertionError(f"{angle=:<8} out of bounds!") - - self.steer_angle += angle - # Simple clamp from Sven Marnach - # https://stackoverflow.com/questions/9775731 - self.steer_angle = max(min(self.steer_angle, - self.MAX_ANGLE), - self.MIN_ANGLE - ) - return self.steer_angle - - - def str(self) -> str: - """ - Return a string representation of this Car object - Create string in a list and join it to keep the - line lengths short. - """ - result = [ - f"\'{self.color} car: {self.speed} m/s; ", - f"steer angle = {self.steer_angle} degrees\'" - ] - return ''.join(result) - - def __repr__(self, **kwargs): - """ - Return this objective as a valid Python string that can - be used to recreate this object. - """ - return f"Car(\"{self.color}\", {self.speed}, {self.steer_angle})" - - - def repr(self): - """ - Simply call the magic __repr__ method - """ - return self.__repr__() # pylint: disable=unnecessary-dunder-call - - - def is_going_faster_than(self, other_car): - """ - Return True if this car (self) has a higher value - in its "speed" property compared to other_car.speed; - else return False. - """ - return self.speed > other_car.speed - - def __eq__(self, other_car:object) -> bool: - """ - Return True if and only if the two Car classes - are identical, doesn't compare private variables. - """ - if self.color != other_car.color: - return False - if self.speed != other_car.speed: - return False - if self.steer_angle != other_car.steer_angle: - return False - return True -def first_test(): - """ - Create a bunch of cars to test all the Car class methods - except for is_going_faster_than() - """ - # Create a bunch of cars in a loop for testing: - colors = ["Red", "White", "Blue", "Green"] - init_speeds = [10,12,14,16] - init_angles = [0, -30, 30, 90 ] - change_angles = [30, 90, 180, -1080] - change_speed = [-1, 2, 3, 4] - durations = [1,2,-3,4] - lists = [ - colors, - init_speeds, - init_angles, - change_angles, - change_speed, - durations - ] - for i, (color, speed, angle, c_angle, c_speed, duration) in enumerate(zip(*lists)): - logger.info(f"Car #{i}".center(80, '-')) - this_car = Car(color, speed, angle) - if this_car is None or not this_car: - raise ValueError("this_car is None!") - - logger.info(this_car) - logger.info("Driving %s", {this_car.repr()}) - # Note the intentional bug here for the - # sake of demonstrating the ValueError: - try: - this_car.gas(c_speed, duration) - except ValueError as e: - logger.error("gas(%.2f,%d) raised %s", c_speed, duration, type(e)) - # Instead of a try/except we should do: - if c_speed >= 0: - this_car.gas(c_speed, duration) - else: - this_car.brake(c_speed, duration) - - #car.change_steer_angle(c_angle) - try: - this_car.change_steer_angle(c_angle) - except AssertionError as e: - logger.error("change_steer_angle(%s) raised %s", c_angle, type(e)) - - logger.info(this_car) - -def second_test(): - """ - Create two cars and determine which one is going faster - by using the is_going_faster_than() Car method - """ - logger.info("Test 2.1".center(80, '-')) - car_1 = Car("Red", 20, 0) - car_2 = Car("White", 19, 0) - - if car_1.is_going_faster_than(car_2): - logger.info("%s is going faster than %s", car_1, car_2) - else: - logger.info("%s's speed is less than or equal to %s's speed", car_1, car_2) - - logger.info("Test 2.2".center(80, '-')) - # The invocation below will also work, - # demonstrating that the unit_test_generator_decorator works on both - Car.is_going_faster_than(car_1, car_2) - -def main(): - """ - Call test functions for Car class, then generate test files for each - method. - """ - - first_test() - second_test() - generate_all_tests_and_metadata(Path('.'), Path('.')) - -if __name__ == "__main__": - - log_levels = { - 'critical': logging.CRITICAL, - 'error': logging.ERROR, - 'warn': logging.WARNING, - 'warning': logging.WARNING, - 'info': logging.INFO, - 'debug': logging.DEBUG - } - - # Create the parser and add argument(s) - parser = argparse.ArgumentParser() - parser.add_argument('--log-level', - "-l", - help='log level', - type=str, - choices=log_levels.keys(), - default='info') - parser.add_argument("--disable-unit-test-generation", "-d", - action="store_true", - help="Set this flag to deactivate unit test generation for this code") - args = parser.parse_args() - logger.info("args=%s", args) - - this_file = Path(__file__).absolute() - for file in this_file.parent.rglob("*"): - if file.suffix in (".py", ".json") and file.absolute() != this_file: - logger.debug("%s != %s", file.absolute().name, this_file.name) - logger.debug("Deleting %s to ensure clean start", file.name) - os.remove(file) - - main() diff --git a/tests/oo_car/coverage_str_helper.json b/tests/oo_car/coverage_str_helper.json index 562aa00..8da2a1a 100644 --- a/tests/oo_car/coverage_str_helper.json +++ b/tests/oo_car/coverage_str_helper.json @@ -1,144 +1,128 @@ -{ - "name": "coverage_str_helper", - "parameter_names": [ - "this_list", - "non_code_lines" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1748, - 1749, - 1750, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1775, - 1776, - 1778, - 1779, - 1780, - 1782, - 1784 - ], - "non_code_lines": [ - 1765, - 1774, - 1777, - 1781, - 1783 - ], - "coverage_io": { - "0": { - "args_before": [ - "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - ], - "args_after": { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "['1696', '1708-1709', '1691-1692', '1694-1695']", - "expected_type": "list", - "coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 78.12, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "coverage_str_helper", + "parameter_names": [ + "this_list", + "non_code_lines" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1759, + 1760, + 1761, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1773, + 1774, + 1775, + 1777, + 1778, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1786, + 1787, + 1789, + 1790, + 1791, + 1793, + 1795 + ], + "non_code_lines": [ + 1776, + 1785, + 1788, + 1792, + 1794 + ], + "coverage_io": { + "0": { + "args_before": [ + "[55, 57]", + "set()" + ], + "args_after": { + "this_list": "[55, 57]", + "non_code_lines": "set()" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "['55']", + "expected_type": "list", + "coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1771, + 1773, + 1777, + 1778, + 1779, + 1780, + 1781, + 1789, + 1795 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 53.12, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1771, + 1773, + 1777, + 1778, + 1779, + 1780, + 1781, + 1789, + 1795 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/oo_car/normalize_arg.json b/tests/oo_car/normalize_arg.json index c512b12..ec4c886 100644 --- a/tests/oo_car/normalize_arg.json +++ b/tests/oo_car/normalize_arg.json @@ -1,67 +1,67 @@ -{ - "name": "normalize_arg", - "parameter_names": [ - "arg" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1718, - 1719, - 1720, - 1721, - 1722, - 1723, - 1725, - 1726, - 1727, - 1728 - ], - "non_code_lines": [ - 1724 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"None\"" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "str", - "coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 60.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "normalize_arg", + "parameter_names": [ + "arg" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1729, + 1730, + 1731, + 1732, + 1733, + 1734, + 1736, + 1737, + 1738, + 1739 + ], + "non_code_lines": [ + 1735 + ], + "coverage_io": { + "0": { + "args_before": [ + "\"None\"" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "str", + "coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 60.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/oo_car/test_car_brake.py b/tests/oo_car/test_car_brake.py index 0f07625..7f9aa24 100644 --- a/tests/oo_car/test_car_brake.py +++ b/tests/oo_car/test_car_brake.py @@ -1,33 +1,32 @@ -""" -Programmatically generated test function for Car.brake() -""" - -import re -import pytest -from collections import OrderedDict -import car - -# Now import modules specific to Car.brake: -from car import Car -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 71.43% of Car.brake's lines -# Line(s) not covered by ANY of the tests below: -# ['53'] -@pytest.mark.parametrize( - "test_class_instance, rate, duration, expected_result", - [ - (Car("Red", 10, 0), -1, 1, "9"), - ], -) -def test_car_brake(test_class_instance, rate, duration, expected_result): - """ - Programmatically generated test function for Car.brake() - """ - result = test_class_instance.brake(rate, duration) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for Car.brake() +""" + +import pytest + +# Now import modules specific to Car.brake: +from tests.oo_car.car import Car + + +# In sum, these tests covered 71.43% of Car.brake's lines +# Line(s) not covered by ANY of the tests below: +# ['55'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "test_class_instance, rate, duration, expected_result", + [ + (Car("Red", 10, 0), -1, 1, "9"), + ], + ids=counter, +) +def test_car_brake(test_class_instance, rate, duration, expected_result): + """ + Programmatically generated test function for Car.brake() + """ + result = test_class_instance.brake(rate, duration) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/oo_car/test_car_change_steer_angle.py b/tests/oo_car/test_car_change_steer_angle.py index 2f9c6e2..d3f064d 100644 --- a/tests/oo_car/test_car_change_steer_angle.py +++ b/tests/oo_car/test_car_change_steer_angle.py @@ -1,48 +1,48 @@ -""" -Programmatically generated test function for Car.change_steer_angle() -""" - -import re -import pytest -from collections import OrderedDict -import car - -# Now import modules specific to Car.change_steer_angle: -from car import Car -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 60.0% of Car.change_steer_angle's lines -# Line(s) not covered by ANY of the tests below: -# ['88-89'] -@pytest.mark.parametrize( - "test_class_instance, angle, exception_type, exception_message, expected_result", - [ - ( - Car("Green", 48, 90), - -1080, - AssertionError, - "angle=-1080 out of bounds!", - "None", - ), - (Car("Blue", 0.0, 30), 180, "N/A", "N/A", "210"), - (Car("Red", 9, 0), 30, "N/A", "N/A", "30"), - (Car("White", 20, -30), 90, "N/A", "N/A", "60"), - ], -) -def test_car_change_steer_angle( - test_class_instance, angle, exception_type, exception_message, expected_result -): - """ - Programmatically generated test function for Car.change_steer_angle() - """ - if exception_type != "N/A": - with pytest.raises(exception_type, match=re.escape(exception_message)): - test_class_instance.change_steer_angle(angle) - else: - result = test_class_instance.change_steer_angle(angle) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for Car.change_steer_angle() +""" + +import re +import pytest + +# Now import modules specific to Car.change_steer_angle: +from tests.oo_car.car import Car + + +# In sum, these tests covered 60.0% of Car.change_steer_angle's lines +# Line(s) not covered by ANY of the tests below: +# ['90-91'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "test_class_instance, angle, exception_type, exception_message, expected_result", + [ + ( + Car("Green", 48, 90), + -1080, + AssertionError, + "angle=-1080 out of bounds!", + "None", + ), + (Car("Blue", 0.0, 30), 180, "N/A", "N/A", "210"), + (Car("Red", 9, 0), 30, "N/A", "N/A", "30"), + (Car("White", 20, -30), 90, "N/A", "N/A", "60"), + ], + ids=counter, +) +def test_car_change_steer_angle( + test_class_instance, angle, exception_type, exception_message, expected_result +): + """ + Programmatically generated test function for Car.change_steer_angle() + """ + if exception_type != "N/A": + with pytest.raises(exception_type, match=re.escape(exception_message)): + test_class_instance.change_steer_angle(angle) + else: + result = test_class_instance.change_steer_angle(angle) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/oo_car/test_car_constructor.py b/tests/oo_car/test_car_constructor.py index cb166d5..499eee7 100644 --- a/tests/oo_car/test_car_constructor.py +++ b/tests/oo_car/test_car_constructor.py @@ -1,26 +1,31 @@ -""" -Programmatically generated test function for Car.__init__() -""" - -import re -import pytest -from collections import OrderedDict -import car - - -# In sum, these tests covered 100.0% of Car.__init__'s lines -@pytest.mark.parametrize( - "color, speed, steer_angle, expected_result", - [ - ("Red", 10, 0, "None"), - ], -) -def test_car___init__(color, speed, steer_angle, expected_result): - """ - Programmatically generated test function for Car.__init__() - """ - result = car.Car(color, speed, steer_angle) - assert isinstance(result, car.Car) - assert result.color == color - assert result.speed == speed - assert result.steer_angle == steer_angle +""" +Programmatically generated test function for Car.__init__() +""" + +import pytest +from tests.oo_car import car + + +# In sum, these tests covered 100.0% of Car.__init__'s lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "color, speed, steer_angle, expected_result", + [ + ("Red", 10, 0, "None"), + ], + ids=counter, +) +def test_car___init__(color, speed, steer_angle, expected_result): + """ + Programmatically generated test function for Car.__init__() + """ + result = car.Car(color, speed, steer_angle) + assert isinstance(result, car.Car) + assert result.color == color + assert result.speed == speed + assert result.steer_angle == steer_angle diff --git a/tests/oo_car/test_car_gas.py b/tests/oo_car/test_car_gas.py index 0f38729..1ce4cf1 100644 --- a/tests/oo_car/test_car_gas.py +++ b/tests/oo_car/test_car_gas.py @@ -1,75 +1,76 @@ -""" -Programmatically generated test function for Car.gas() -""" - -import re -import pytest -from collections import OrderedDict -import car -from _pytest.monkeypatch import MonkeyPatch - -# Now import modules specific to Car.gas: -from car import Car -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 100.0% of Car.gas's lines -@pytest.mark.parametrize( - "test_class_instance, rate, duration, exception_type, exception_message, expected_result, globals_before, globals_after", - [ - ( - Car("Red", 10, 0), - -1, - 1, - ValueError, - "Gas rate (m/s) must be positive.", - "None", - {"method_call_counter": 0}, - {"method_call_counter": 1}, - ), - ( - Car("White", 12, -30), - 2, - 2, - "N/A", - "N/A", - "16", - {"method_call_counter": 1}, - {"method_call_counter": 2}, - ), - ], -) -def test_car_gas( - test_class_instance, - rate, - duration, - exception_type, - exception_message, - expected_result, - globals_before, - globals_after, -): - """ - Programmatically generated test function for Car.gas() - """ - monkeypatch = MonkeyPatch() - for k, v in globals_before.items(): - monkeypatch.setattr(car, k, v) - if exception_type != "N/A": - with pytest.raises(exception_type, match=re.escape(exception_message)): - test_class_instance.gas(rate, duration) - else: - result = test_class_instance.gas(rate, duration) - assert result == expected_result or result == eval(expected_result) - for global_var_written_to in ["method_call_counter"]: - if global_var_written_to in ["None", "[]", "{}"]: - assert not car.__dict__.get(global_var_written_to) - else: - assert ( - car.__dict__.get(global_var_written_to) - == globals_after[global_var_written_to] - ) +""" +Programmatically generated test function for Car.gas() +""" + +import re +import pytest +from tests.oo_car import car +from _pytest.monkeypatch import MonkeyPatch + +# Now import modules specific to Car.gas: +from tests.oo_car.car import Car + + +# In sum, these tests covered 100.0% of Car.gas's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "test_class_instance, rate, duration, exception_type, exception_message, expected_result, globals_before, globals_after", + [ + ( + Car("Red", 10, 0), + -1, + 1, + ValueError, + "Gas rate (m/s) must be positive.", + "None", + {"method_call_counter": 0}, + {"method_call_counter": 1}, + ), + ( + Car("White", 12, -30), + 2, + 2, + "N/A", + "N/A", + "16", + {"method_call_counter": 1}, + {"method_call_counter": 2}, + ), + ], + ids=counter, +) +def test_car_gas( + test_class_instance, + rate, + duration, + exception_type, + exception_message, + expected_result, + globals_before, + globals_after, +): + """ + Programmatically generated test function for Car.gas() + """ + monkeypatch = MonkeyPatch() + for k, v in globals_before.items(): + monkeypatch.setattr(car, k, v) + if exception_type != "N/A": + with pytest.raises(exception_type, match=re.escape(exception_message)): + test_class_instance.gas(rate, duration) + else: + result = test_class_instance.gas(rate, duration) + assert result == expected_result or result == eval(expected_result) + for global_var_written_to in ["method_call_counter"]: + if global_var_written_to in ["None", "[]", "{}"]: + assert not car.__dict__.get(global_var_written_to) + else: + assert ( + car.__dict__.get(global_var_written_to) + == globals_after[global_var_written_to] + ) diff --git a/tests/oo_car/test_car_is_going_faster_than.py b/tests/oo_car/test_car_is_going_faster_than.py index 8ea7bb3..178187a 100644 --- a/tests/oo_car/test_car_is_going_faster_than.py +++ b/tests/oo_car/test_car_is_going_faster_than.py @@ -1,37 +1,42 @@ -""" -Programmatically generated test function for Car.is_going_faster_than() -""" - -import re -import pytest -from collections import OrderedDict -import car - -# Now import modules specific to Car.is_going_faster_than: -from car import Car - - -# In sum, these tests covered 100.0% of Car.is_going_faster_than's lines -@pytest.mark.parametrize( - "test_class_instance, other_car, expected_result, args_after", - [ - ( - Car("Red", 20, 0), - Car("White", 19, 0), - "True", - {"other_car": 'Car("White", 19, 0)'}, - ), - ], -) -def test_car_is_going_faster_than( - test_class_instance, other_car, expected_result, args_after -): - """ - Programmatically generated test function for Car.is_going_faster_than() - """ - result = test_class_instance.is_going_faster_than(other_car) - assert result == expected_result or result == eval(expected_result) - assert ( - other_car == eval(args_after["other_car"]) - or args_after["other_car"] == other_car - ) +""" +Programmatically generated test function for Car.is_going_faster_than() +""" + +import pytest + +# Now import modules specific to Car.is_going_faster_than: +from car import Car +from tests.oo_car.car import Car + + +# In sum, these tests covered 100.0% of Car.is_going_faster_than's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "test_class_instance, other_car, expected_result, args_after", + [ + ( + Car("Red", 20, 0), + Car("White", 19, 0), + "True", + {"other_car": 'Car("White", 19, 0)'}, + ), + ], + ids=counter, +) +def test_car_is_going_faster_than( + test_class_instance, other_car, expected_result, args_after +): + """ + Programmatically generated test function for Car.is_going_faster_than() + """ + result = test_class_instance.is_going_faster_than(other_car) + assert result == expected_result or result == eval(expected_result) + assert ( + other_car == eval(args_after["other_car"]) + or args_after["other_car"] == other_car + ) diff --git a/tests/oo_car/test_coverage_str_helper_oo_car.py b/tests/oo_car/test_coverage_str_helper_oo_car.py index 27c9e7b..292d56c 100644 --- a/tests/oo_car/test_coverage_str_helper_oo_car.py +++ b/tests/oo_car/test_coverage_str_helper_oo_car.py @@ -1,48 +1,45 @@ -""" -Programmatically generated test function for coverage_str_helper() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to coverage_str_helper: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 78.12% of coverage_str_helper's lines -# Line(s) not covered by ANY of the tests below: -# ['1750', '1761', '1775-1776', '1779-1780'] -@pytest.mark.parametrize( - "this_list, non_code_lines, expected_result, args_after", - [ - ( - [1696, 1708, 1709, 1691, 1692, 1694, 1695], - {1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}, - "['1696', '1708-1709', '1691-1692', '1694-1695']", - { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}", - }, - ), - ], -) -def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): - """ - Programmatically generated test function for coverage_str_helper() - """ - result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) +""" +Programmatically generated test function for coverage_str_helper() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to coverage_str_helper: + + +# In sum, these tests covered 53.12% of coverage_str_helper's lines +# Line(s) not covered by ANY of the tests below: +# ['1793', '1761', '1768-1770', '1772', '1774-1775', '1782-1784', '1786-1787', '1790-1791'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, non_code_lines, expected_result, args_after", + [ + ( + [55, 57], + set(), + "['55']", + {"this_list": "[55, 57]", "non_code_lines": "set()"}, + ), + ], + ids=counter, +) +def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): + """ + Programmatically generated test function for coverage_str_helper() + """ + result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) diff --git a/tests/oo_car/test_normalize_arg_oo_car.py b/tests/oo_car/test_normalize_arg_oo_car.py index d1e26b7..d9dfdc3 100644 --- a/tests/oo_car/test_normalize_arg_oo_car.py +++ b/tests/oo_car/test_normalize_arg_oo_car.py @@ -1,25 +1,30 @@ -""" -Programmatically generated test function for normalize_arg() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - - -# In sum, these tests covered 60.0% of normalize_arg's lines -# Line(s) not covered by ANY of the tests below: -# ['1721', '1723', '1726-1727'] -@pytest.mark.parametrize( - "arg, expected_result", - [ - ("None", "None"), - ], -) -def test_normalize_arg(arg, expected_result): - """ - Programmatically generated test function for normalize_arg() - """ - result = unit_test_generator.normalize_arg(arg) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for normalize_arg() +""" + +import pytest +from src import unit_test_generator + + +# In sum, these tests covered 60.0% of normalize_arg's lines +# Line(s) not covered by ANY of the tests below: +# ['1732', '1734', '1737-1738'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "arg, expected_result", + [ + ("None", "None"), + ], + ids=counter, +) +def test_normalize_arg(arg, expected_result): + """ + Programmatically generated test function for normalize_arg() + """ + result = unit_test_generator.normalize_arg(arg) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/oo_car/test_update_global_oo_car.py b/tests/oo_car/test_update_global_oo_car.py index a63085b..53dfbc4 100644 --- a/tests/oo_car/test_update_global_oo_car.py +++ b/tests/oo_car/test_update_global_oo_car.py @@ -1,65 +1,3 @@ -""" -Programmatically generated test function for update_global() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to update_global: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler -from src.unit_test_generator import CoverageInfo - - -# In sum, these tests covered 46.15% of update_global's lines -# Line(s) not covered by ANY of the tests below: -# ['1696', '1708-1709', '1691-1692', '1694-1695'] -@pytest.mark.parametrize( - "obj, this_global, phase, this_coverage_info, expected_result, args_after", - [ - ( - 0, - "method_call_counter", - "Before", - CoverageInfo( - args_before=["-1", "1"], - args_after={}, - kwargs={}, - kwargs_after={}, - globals_before={}, - globals_after={}, - expected_result="", - expected_type="", - coverage=[], - exception_type="", - exception_message="", - constructor='Car("Red", 10, 0)', - cost=0.0, - testable=0.0, - ), - "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)", - { - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" - }, - ), - ], -) -def test_update_global( - obj, this_global, phase, this_coverage_info, expected_result, args_after -): - """ - Programmatically generated test function for update_global() - """ - result = unit_test_generator.update_global( - obj, this_global, phase, this_coverage_info - ) - assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) +""" +No testable inputs - see accompanying JSON file. +""" \ No newline at end of file diff --git a/tests/oo_car/update_global.json b/tests/oo_car/update_global.json index afb84fa..6213dd4 100644 --- a/tests/oo_car/update_global.json +++ b/tests/oo_car/update_global.json @@ -1,94 +1,89 @@ -{ - "name": "update_global", - "parameter_names": [ - "obj", - "this_global", - "phase", - "this_coverage_info" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1690, - 1691, - 1692, - 1693, - 1694, - 1695, - 1696, - 1698, - 1706, - 1707, - 1708, - 1709, - 1710 - ], - "non_code_lines": [ - 1697, - 1699, - 1700, - 1701, - 1702, - 1703, - 1704, - 1705 - ], - "coverage_io": { - "0": { - "args_before": [ - "0", - "\"method_call_counter\"", - "\"Before\"", - "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" - ], - "args_after": { - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=0.0)", - "expected_type": "src.unit_test_generator.CoverageInfo", - "coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 46.15, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler", - "src.unit_test_generator.CoverageInfo" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "update_global", + "parameter_names": [ + "obj", + "this_global", + "phase", + "this_coverage_info" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1709, + 1717, + 1718, + 1719, + 1720, + 1721 + ], + "non_code_lines": [ + 1708, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716 + ], + "coverage_io": { + "0": { + "args_before": [ + "", + "\"logger\"", + "\"Before\"", + "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" + ], + "args_after": { + "obj": "", + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", + "expected_type": "src.unit_test_generator.CoverageInfo", + "coverage": [ + 1701, + 1702, + 1703 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": false + } + }, + "coverage_percentage": 23.08, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "src.unit_test_generator.CoverageInfo" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1701, + 1702, + 1703 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/add_to_my_set_kwargs.json b/tests/pass_by_assignment/add_to_my_set_kwargs.json index 0cc75be..f920c4f 100644 --- a/tests/pass_by_assignment/add_to_my_set_kwargs.json +++ b/tests/pass_by_assignment/add_to_my_set_kwargs.json @@ -1,54 +1,59 @@ -{ - "name": "add_to_my_set_kwargs", - "parameter_names": [], - "is_method": false, - "source_file": null, - "lines": [ - 72, - 73, - 72 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [], - "args_after": {}, - "kwargs": { - "my_set": [ - 0, - 2, - 3 - ] - }, - "kwargs_after": { - "my_set": "{0, 1, 2, 3}" - }, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 72, - 73 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 66.67, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 72, - 73 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "add_to_my_set_kwargs": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" - } +{ + "name": "add_to_my_set_kwargs", + "parameter_names": [], + "is_method": false, + "source_file": null, + "lines": [ + 72, + 73, + 72 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [], + "args_after": {}, + "kwargs": { + "my_set": [ + 0, + 2, + 3 + ] + }, + "kwargs_after": { + "my_set": [ + 0, + 1, + 2, + 3 + ] + }, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 72, + 73 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 66.67, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 72, + 73 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "add_to_my_set_kwargs": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/append_list.json b/tests/pass_by_assignment/append_list.json index a662ebd..6800c6d 100644 --- a/tests/pass_by_assignment/append_list.json +++ b/tests/pass_by_assignment/append_list.json @@ -1,61 +1,61 @@ -{ - "name": "append_list", - "parameter_names": [ - "this_list", - "item" - ], - "is_method": false, - "source_file": null, - "lines": [ - 43, - 44 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "[1, 2, 3, 4]", - "6" - ], - "args_after": { - "this_list": "[1, 2, 3, 4, 6]" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 43, - 44 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 43, - 44 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "append_list": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" - } +{ + "name": "append_list", + "parameter_names": [ + "this_list", + "item" + ], + "is_method": false, + "source_file": null, + "lines": [ + 44, + 45 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "[1, 2, 3, 4]", + "6" + ], + "args_after": { + "this_list": "[1, 2, 3, 4, 6]" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 44, + 45 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 44, + 45 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "append_list": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/increment_my_list_kwargs.json b/tests/pass_by_assignment/increment_my_list_kwargs.json index ab3cef3..fe9c4f3 100644 --- a/tests/pass_by_assignment/increment_my_list_kwargs.json +++ b/tests/pass_by_assignment/increment_my_list_kwargs.json @@ -1,58 +1,57 @@ -{ - "name": "increment_my_list_kwargs", - "parameter_names": [], - "is_method": false, - "source_file": null, - "lines": [ - 62, - 63, - 64, - 62 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [], - "args_after": {}, - "kwargs": { - "my_list": [ - 0, - 3 - ] - }, - "kwargs_after": { - "my_list": "[0, 3, 1, ClassForTesting('test')]" - }, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 62, - 63, - 64 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 75.0, - "types_in_use": [ - "__main__.ClassForTesting" - ], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 62, - 63, - 64 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "increment_my_list_kwargs": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" - } +{ + "name": "increment_my_list_kwargs", + "parameter_names": [], + "is_method": false, + "source_file": null, + "lines": [ + 62, + 63, + 62 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [], + "args_after": {}, + "kwargs": { + "my_list": [ + 0, + 3 + ] + }, + "kwargs_after": { + "my_list": [ + 0, + 3, + 1 + ] + }, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 62, + 63 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 66.67, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 62, + 63 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "increment_my_list_kwargs": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/normalize_arg.json b/tests/pass_by_assignment/normalize_arg.json index c512b12..ec4c886 100644 --- a/tests/pass_by_assignment/normalize_arg.json +++ b/tests/pass_by_assignment/normalize_arg.json @@ -1,67 +1,67 @@ -{ - "name": "normalize_arg", - "parameter_names": [ - "arg" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1718, - 1719, - 1720, - 1721, - 1722, - 1723, - 1725, - 1726, - 1727, - 1728 - ], - "non_code_lines": [ - 1724 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"None\"" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "str", - "coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 60.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "normalize_arg", + "parameter_names": [ + "arg" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1729, + 1730, + 1731, + 1732, + 1733, + 1734, + 1736, + 1737, + 1738, + 1739 + ], + "non_code_lines": [ + 1735 + ], + "coverage_io": { + "0": { + "args_before": [ + "\"None\"" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "str", + "coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 60.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1729, + 1730, + 1731, + 1733, + 1736, + 1739 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/overwrite_list.json b/tests/pass_by_assignment/overwrite_list.json index 866e5a1..c8608ee 100644 --- a/tests/pass_by_assignment/overwrite_list.json +++ b/tests/pass_by_assignment/overwrite_list.json @@ -1,51 +1,51 @@ -{ - "name": "overwrite_list", - "parameter_names": [ - "this_list" - ], - "is_method": false, - "source_file": null, - "lines": [ - 53, - 54 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "[6, 4, 3, 2, 1]" - ], - "args_after": { - "this_list": "[6, 4, 3, 2, 1]" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 53, - 54 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 53, - 54 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "overwrite_list": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" - } +{ + "name": "overwrite_list", + "parameter_names": [ + "this_list" + ], + "is_method": false, + "source_file": null, + "lines": [ + 53, + 54 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "[6, 4, 3, 2, 1]" + ], + "args_after": { + "this_list": "[6, 4, 3, 2, 1]" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 53, + 54 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 53, + 54 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "overwrite_list": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\pass_by_assignment\\pass_by_assignment.py" + } } \ No newline at end of file diff --git a/tests/pass_by_assignment/pass_by_assignment.py b/tests/pass_by_assignment/pass_by_assignment.py index 4c6ae26..37d2788 100644 --- a/tests/pass_by_assignment/pass_by_assignment.py +++ b/tests/pass_by_assignment/pass_by_assignment.py @@ -48,8 +48,7 @@ def append_list(this_list:List[Any], item:Any)->None: @unit_test_generator_decorator(sample_count=6, keep_subsets=True, percent_coverage=0) def overwrite_list(this_list:List[Any])->None: """ - Given a list of items of the same type T and a separate item, - delete the local copy. + Given a list of items; overwrite the local copy. """ this_list = [0] print(this_list) @@ -62,7 +61,7 @@ def increment_my_list_kwargs(**kwargs): """ if "my_list" in kwargs and isinstance(kwargs["my_list"], list): kwargs["my_list"].append(1) - kwargs["my_list"].append(ClassForTesting("test")) + #kwargs["my_list"].append(ClassForTesting("test")) @unit_test_generator_decorator(sample_count=6, keep_subsets=True, percent_coverage=0) def add_to_my_set_kwargs(**kwargs): @@ -86,13 +85,15 @@ def main(): overwrite_list(my_list[::-1]) kwargs = {"my_list":[0,3]} - print(f"Before: {kwargs=}") + print(f"my_list Before increment_my_list_kwargs(): {kwargs=}") increment_my_list_kwargs(**kwargs) print(f"After: {kwargs=}") kwargs = {} kwargs["my_set"] = set([0,2,3]) + print(f"my_set Before: add_to_my_set_kwargs(): {kwargs=}") + add_to_my_set_kwargs(**kwargs) print(f"After: {kwargs=}") diff --git a/tests/pass_by_assignment/test_add_to_my_set_kwargs.py b/tests/pass_by_assignment/test_add_to_my_set_kwargs.py index a9fae88..eb1dc7a 100644 --- a/tests/pass_by_assignment/test_add_to_my_set_kwargs.py +++ b/tests/pass_by_assignment/test_add_to_my_set_kwargs.py @@ -1,29 +1,31 @@ -""" -Programmatically generated test function for add_to_my_set_kwargs() -""" - -import re -import pytest -from collections import OrderedDict -from tests.pass_by_assignment import pass_by_assignment - - -# In sum, these tests covered 66.67% of add_to_my_set_kwargs's lines -# Line(s) not covered by ANY of the tests below: -# set() -@pytest.mark.parametrize( - "kwargs, expected_result, kwargs_after", - [ - ({"my_set": {0, 2, 3}}, "None", {"my_set": "{0, 1, 2, 3}"}), - ], -) -def test_add_to_my_set_kwargs(kwargs, expected_result, kwargs_after): - """ - Programmatically generated test function for add_to_my_set_kwargs() - """ - result = pass_by_assignment.add_to_my_set_kwargs(**kwargs) - assert result == expected_result or result == eval(expected_result) - assert ( - kwargs["my_set"] == eval(kwargs_after["my_set"]) - or kwargs["my_set"] == kwargs_after["my_set"] - ) +""" +Programmatically generated test function for add_to_my_set_kwargs() +""" + +import pytest +import pass_by_assignment + + +# In sum, these tests covered 66.67% of add_to_my_set_kwargs's lines +# Line(s) not covered by ANY of the tests below: +# set() +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "kwargs, expected_result, kwargs_after", + [ + ({"my_set": {0, 2, 3}}, "None", {"my_set": {0, 1, 2, 3}}), + ], + ids=counter, +) +def test_add_to_my_set_kwargs(kwargs, expected_result, kwargs_after): + """ + Programmatically generated test function for add_to_my_set_kwargs() + """ + result = pass_by_assignment.add_to_my_set_kwargs(**kwargs) + assert result == expected_result or result == eval(expected_result) + kwargs["my_set"] == kwargs_after["my_set"] diff --git a/tests/pass_by_assignment/test_append_list.py b/tests/pass_by_assignment/test_append_list.py index 50508d4..07f590b 100644 --- a/tests/pass_by_assignment/test_append_list.py +++ b/tests/pass_by_assignment/test_append_list.py @@ -1,34 +1,34 @@ -""" -Programmatically generated test function for append_list() -""" - -import re -import pytest -from collections import OrderedDict -from tests.pass_by_assignment import pass_by_assignment - -# Now import modules specific to append_list: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 100.0% of append_list's lines -@pytest.mark.parametrize( - "this_list, item, expected_result, args_after", - [ - ([1, 2, 3, 4], 6, "None", {"this_list": "[1, 2, 3, 4, 6]"}), - ], -) -def test_append_list(this_list, item, expected_result, args_after): - """ - Programmatically generated test function for append_list() - """ - result = pass_by_assignment.append_list(this_list, item) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) +""" +Programmatically generated test function for append_list() +""" + +import pytest +import pass_by_assignment + +# Now import modules specific to append_list: + + +# In sum, these tests covered 100.0% of append_list's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, item, expected_result, args_after", + [ + ([1, 2, 3, 4], 6, "None", {"this_list": "[1, 2, 3, 4, 6]"}), + ], + ids=counter, +) +def test_append_list(this_list, item, expected_result, args_after): + """ + Programmatically generated test function for append_list() + """ + result = pass_by_assignment.append_list(this_list, item) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) diff --git a/tests/pass_by_assignment/test_increment_my_list_kwargs.py b/tests/pass_by_assignment/test_increment_my_list_kwargs.py index c9236c8..bdd0830 100644 --- a/tests/pass_by_assignment/test_increment_my_list_kwargs.py +++ b/tests/pass_by_assignment/test_increment_my_list_kwargs.py @@ -1,36 +1,31 @@ -""" -Programmatically generated test function for increment_my_list_kwargs() -""" - -import re -import pytest -from collections import OrderedDict -from tests.pass_by_assignment import pass_by_assignment - -# Now import modules specific to increment_my_list_kwargs: -from pass_by_assignment import ClassForTesting - - -# In sum, these tests covered 75.0% of increment_my_list_kwargs's lines -# Line(s) not covered by ANY of the tests below: -# set() -@pytest.mark.parametrize( - "kwargs, expected_result, kwargs_after", - [ - ( - {"my_list": [0, 3]}, - "None", - {"my_list": "[0, 3, 1, ClassForTesting('test')]"}, - ), - ], -) -def test_increment_my_list_kwargs(kwargs, expected_result, kwargs_after): - """ - Programmatically generated test function for increment_my_list_kwargs() - """ - result = pass_by_assignment.increment_my_list_kwargs(**kwargs) - assert result == expected_result or result == eval(expected_result) - assert ( - kwargs["my_list"] == eval(kwargs_after["my_list"]) - or kwargs["my_list"] == kwargs_after["my_list"] - ) +""" +Programmatically generated test function for increment_my_list_kwargs() +""" + +import pytest +import pass_by_assignment + + +# In sum, these tests covered 66.67% of increment_my_list_kwargs's lines +# Line(s) not covered by ANY of the tests below: +# set() +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "kwargs, expected_result, kwargs_after", + [ + ({"my_list": [0, 3]}, "None", {"my_list": [0, 3, 1]}), + ], + ids=counter, +) +def test_increment_my_list_kwargs(kwargs, expected_result, kwargs_after): + """ + Programmatically generated test function for increment_my_list_kwargs() + """ + result = pass_by_assignment.increment_my_list_kwargs(**kwargs) + assert result == expected_result or result == eval(expected_result) + kwargs["my_list"] == kwargs_after["my_list"] diff --git a/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py b/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py index d1e26b7..d9dfdc3 100644 --- a/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py +++ b/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py @@ -1,25 +1,30 @@ -""" -Programmatically generated test function for normalize_arg() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - - -# In sum, these tests covered 60.0% of normalize_arg's lines -# Line(s) not covered by ANY of the tests below: -# ['1721', '1723', '1726-1727'] -@pytest.mark.parametrize( - "arg, expected_result", - [ - ("None", "None"), - ], -) -def test_normalize_arg(arg, expected_result): - """ - Programmatically generated test function for normalize_arg() - """ - result = unit_test_generator.normalize_arg(arg) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for normalize_arg() +""" + +import pytest +from src import unit_test_generator + + +# In sum, these tests covered 60.0% of normalize_arg's lines +# Line(s) not covered by ANY of the tests below: +# ['1732', '1734', '1737-1738'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "arg, expected_result", + [ + ("None", "None"), + ], + ids=counter, +) +def test_normalize_arg(arg, expected_result): + """ + Programmatically generated test function for normalize_arg() + """ + result = unit_test_generator.normalize_arg(arg) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/pass_by_assignment/test_overwrite_list.py b/tests/pass_by_assignment/test_overwrite_list.py index 48f2850..8ecb005 100644 --- a/tests/pass_by_assignment/test_overwrite_list.py +++ b/tests/pass_by_assignment/test_overwrite_list.py @@ -1,27 +1,32 @@ -""" -Programmatically generated test function for overwrite_list() -""" - -import re -import pytest -from collections import OrderedDict -from tests.pass_by_assignment import pass_by_assignment - - -# In sum, these tests covered 100.0% of overwrite_list's lines -@pytest.mark.parametrize( - "this_list, expected_result, args_after", - [ - ([6, 4, 3, 2, 1], "None", {"this_list": "[6, 4, 3, 2, 1]"}), - ], -) -def test_overwrite_list(this_list, expected_result, args_after): - """ - Programmatically generated test function for overwrite_list() - """ - result = pass_by_assignment.overwrite_list(this_list) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) +""" +Programmatically generated test function for overwrite_list() +""" + +import pytest +import pass_by_assignment + + +# In sum, these tests covered 100.0% of overwrite_list's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, expected_result, args_after", + [ + ([6, 4, 3, 2, 1], "None", {"this_list": "[6, 4, 3, 2, 1]"}), + ], + ids=counter, +) +def test_overwrite_list(this_list, expected_result, args_after): + """ + Programmatically generated test function for overwrite_list() + """ + result = pass_by_assignment.overwrite_list(this_list) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) diff --git a/tests/pass_by_assignment/test_update_global_pass_by_assignment.py b/tests/pass_by_assignment/test_update_global_pass_by_assignment.py index e1c5f58..53dfbc4 100644 --- a/tests/pass_by_assignment/test_update_global_pass_by_assignment.py +++ b/tests/pass_by_assignment/test_update_global_pass_by_assignment.py @@ -1,2 +1,3 @@ -import warnings -warnings.warn("No testable samples!") \ No newline at end of file +""" +No testable inputs - see accompanying JSON file. +""" \ No newline at end of file diff --git a/tests/pass_by_assignment/update_global.json b/tests/pass_by_assignment/update_global.json index 2d9f568..dc74e0a 100644 --- a/tests/pass_by_assignment/update_global.json +++ b/tests/pass_by_assignment/update_global.json @@ -1,89 +1,89 @@ -{ - "name": "update_global", - "parameter_names": [ - "obj", - "this_global", - "phase", - "this_coverage_info" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1690, - 1691, - 1692, - 1693, - 1694, - 1695, - 1696, - 1698, - 1706, - 1707, - 1708, - 1709, - 1710 - ], - "non_code_lines": [ - 1697, - 1699, - 1700, - 1701, - 1702, - 1703, - 1704, - 1705 - ], - "coverage_io": { - "0": { - "args_before": [ - "", - "\"logger\"", - "\"Before\"", - "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - ], - "args_after": { - "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "src.unit_test_generator.CoverageInfo", - "coverage": [ - 1690, - 1691, - 1692 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": false - } - }, - "coverage_percentage": 23.08, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler", - "src.unit_test_generator.CoverageInfo" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1690, - 1691, - 1692 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "update_global", + "parameter_names": [ + "obj", + "this_global", + "phase", + "this_coverage_info" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1709, + 1717, + 1718, + 1719, + 1720, + 1721 + ], + "non_code_lines": [ + 1708, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716 + ], + "coverage_io": { + "0": { + "args_before": [ + "", + "\"logger\"", + "\"Before\"", + "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + ], + "args_after": { + "obj": "", + "this_coverage_info": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "src.unit_test_generator.CoverageInfo", + "coverage": [ + 1701, + 1702, + 1703 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": false + } + }, + "coverage_percentage": 23.08, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "src.unit_test_generator.CoverageInfo" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1701, + 1702, + 1703 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/procedural_division/coverage_str_helper.json b/tests/procedural_division/coverage_str_helper.json deleted file mode 100644 index 562aa00..0000000 --- a/tests/procedural_division/coverage_str_helper.json +++ /dev/null @@ -1,144 +0,0 @@ -{ - "name": "coverage_str_helper", - "parameter_names": [ - "this_list", - "non_code_lines" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1748, - 1749, - 1750, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1775, - 1776, - 1778, - 1779, - 1780, - 1782, - 1784 - ], - "non_code_lines": [ - 1765, - 1774, - 1777, - 1781, - 1783 - ], - "coverage_io": { - "0": { - "args_before": [ - "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - ], - "args_after": { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "['1696', '1708-1709', '1691-1692', '1694-1695']", - "expected_type": "list", - "coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 78.12, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1748, - 1749, - 1751, - 1752, - 1753, - 1754, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1762, - 1763, - 1764, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1778, - 1784 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } -} \ No newline at end of file diff --git a/tests/procedural_division/divide_ints.json b/tests/procedural_division/divide_ints.json index 48572ea..d02a9e3 100644 --- a/tests/procedural_division/divide_ints.json +++ b/tests/procedural_division/divide_ints.json @@ -1,179 +1,179 @@ -{ - "name": "divide_ints", - "parameter_names": [ - "a", - "b" - ], - "is_method": false, - "source_file": null, - "lines": [ - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 42, - 43, - 44 - ], - "non_code_lines": [], - "coverage_io": { - "0": { - "args_before": [ - "\"10\"", - "2" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "error_code": 0 - }, - "globals_after": { - "error_code": -1 - }, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 34, - 35, - 36, - 37 - ], - "exception_type": "", - "exception_message": "TypeError: Variable a='10' is not an int!", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "3", - "0" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "error_code": 0 - }, - "globals_after": { - "error_code": -3 - }, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 34, - 35, - 38, - 41, - 42, - 43 - ], - "exception_type": "", - "exception_message": "ValueError: Cannot divide by zero!", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "2": { - "args_before": [ - "6", - "2" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "error_code": 0 - }, - "globals_after": { - "error_code": 0 - }, - "expected_result": "6/2=3.0", - "expected_type": "str", - "coverage": [ - 34, - 35, - 38, - 41, - 44 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "3": { - "args_before": [ - "8", - "[]" - ], - "args_after": { - "b": "[]" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "error_code": 0 - }, - "globals_after": { - "error_code": -2 - }, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 34, - 35, - 38, - 39, - 40 - ], - "exception_type": "", - "exception_message": "TypeError: Variable b=[] is not an int!", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 100.0, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler" - ], - "global_vars_read_from": [ - "error_code", - "logger" - ], - "global_vars_written_to": [ - "error_code" - ], - "unified_test_coverage": [ - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 42, - 43, - 44 - ], - "needs_pytest": true, - "exceptions_raised": [ - "", - "" - ], - "callable_files": { - "divide_ints": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\procedural_division\\divide_ints.py" - } +{ + "name": "divide_ints", + "parameter_names": [ + "a", + "b" + ], + "is_method": false, + "source_file": null, + "lines": [ + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45 + ], + "non_code_lines": [], + "coverage_io": { + "0": { + "args_before": [ + "\"10\"", + "2" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "error_code": 0 + }, + "globals_after": { + "error_code": -1 + }, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 35, + 36, + 37, + 38 + ], + "exception_type": "", + "exception_message": "TypeError: Variable a='10' is not an int!", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "1": { + "args_before": [ + "3", + "0" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "error_code": 0 + }, + "globals_after": { + "error_code": -3 + }, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 35, + 36, + 39, + 42, + 43, + 44 + ], + "exception_type": "", + "exception_message": "ValueError: Cannot divide by zero!", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "2": { + "args_before": [ + "6", + "2" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "error_code": 0 + }, + "globals_after": { + "error_code": 0 + }, + "expected_result": "6/2=3.0", + "expected_type": "str", + "coverage": [ + 35, + 36, + 39, + 42, + 45 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "3": { + "args_before": [ + "8", + "[]" + ], + "args_after": { + "b": "[]" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "error_code": 0 + }, + "globals_after": { + "error_code": -2 + }, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 35, + 36, + 39, + 40, + 41 + ], + "exception_type": "", + "exception_message": "TypeError: Variable b=[] is not an int!", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 100.0, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "error_code", + "logger" + ], + "global_vars_written_to": [ + "error_code" + ], + "unified_test_coverage": [ + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45 + ], + "needs_pytest": true, + "exceptions_raised": [ + "", + "" + ], + "callable_files": { + "divide_ints": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\procedural_division\\divide_ints.py" + } } \ No newline at end of file diff --git a/tests/procedural_division/normalize_arg.json b/tests/procedural_division/normalize_arg.json index 8d3547e..bbc2c1b 100644 --- a/tests/procedural_division/normalize_arg.json +++ b/tests/procedural_division/normalize_arg.json @@ -1,67 +1,65 @@ -{ - "name": "normalize_arg", - "parameter_names": [ - "arg" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1718, - 1719, - 1720, - 1721, - 1722, - 1723, - 1725, - 1726, - 1727, - 1728 - ], - "non_code_lines": [ - 1724 - ], - "coverage_io": { - "0": { - "args_before": [ - "\"CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)\"" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "str", - "coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 60.0, - "types_in_use": [], - "global_vars_read_from": [], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1718, - 1719, - 1720, - 1722, - 1725, - 1728 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "normalize_arg", + "parameter_names": [ + "arg" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1729, + 1730, + 1731, + 1732, + 1733, + 1734, + 1736, + 1737, + 1738, + 1739 + ], + "non_code_lines": [ + 1735 + ], + "coverage_io": { + "0": { + "args_before": [ + "-1" + ], + "args_after": {}, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "-1", + "expected_type": "int", + "coverage": [ + 1729, + 1731, + 1733, + 1736, + 1739 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 50.0, + "types_in_use": [], + "global_vars_read_from": [], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1729, + 1731, + 1733, + 1736, + 1739 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "normalize_arg": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file diff --git a/tests/procedural_division/test_coverage_str_helper_procedural_division.py b/tests/procedural_division/test_coverage_str_helper_procedural_division.py deleted file mode 100644 index 27c9e7b..0000000 --- a/tests/procedural_division/test_coverage_str_helper_procedural_division.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Programmatically generated test function for coverage_str_helper() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to coverage_str_helper: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - - -# In sum, these tests covered 78.12% of coverage_str_helper's lines -# Line(s) not covered by ANY of the tests below: -# ['1750', '1761', '1775-1776', '1779-1780'] -@pytest.mark.parametrize( - "this_list, non_code_lines, expected_result, args_after", - [ - ( - [1696, 1708, 1709, 1691, 1692, 1694, 1695], - {1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}, - "['1696', '1708-1709', '1691-1692', '1694-1695']", - { - "this_list": "[1696, 1708, 1709, 1691, 1692, 1694, 1695]", - "non_code_lines": "{1697, 1699, 1700, 1701, 1702, 1703, 1704, 1705}", - }, - ), - ], -) -def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): - """ - Programmatically generated test function for coverage_str_helper() - """ - result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) - assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) diff --git a/tests/procedural_division/test_divide_ints.py b/tests/procedural_division/test_divide_ints.py index 1e64b66..a1f0d57 100644 --- a/tests/procedural_division/test_divide_ints.py +++ b/tests/procedural_division/test_divide_ints.py @@ -1,76 +1,77 @@ -""" -Programmatically generated test function for divide_ints() -""" - -import re -import pytest -from collections import OrderedDict -import divide_ints -from _pytest.monkeypatch import MonkeyPatch - -# Now import modules specific to divide_ints: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler - -ERROR_CODE = 0 - - -# In sum, these tests covered 100.0% of divide_ints's lines -@pytest.mark.parametrize( - "a, b, exception_type, exception_message, expected_result, args_after, globals_after", - [ - ( - "10", - 2, - TypeError, - "TypeError: Variable a='10' is not an int!", - "None", - {}, - {"error_code": -1}, - ), - ( - 3, - 0, - ValueError, - "ValueError: Cannot divide by zero!", - "None", - {}, - {"error_code": -3}, - ), - (6, 2, "N/A", "N/A", "6/2=3.0", {}, {"error_code": 0}), - ( - 8, - [], - TypeError, - "TypeError: Variable b=[] is not an int!", - "None", - {"b": "[]"}, - {"error_code": -2}, - ), - ], -) -def test_divide_ints( - a, b, exception_type, exception_message, expected_result, args_after, globals_after -): - """ - Programmatically generated test function for divide_ints() - """ - monkeypatch = MonkeyPatch() - monkeypatch.setattr(divide_ints, "error_code", ERROR_CODE) - if exception_type != "N/A": - with pytest.raises(exception_type, match=re.escape(exception_message)): - divide_ints.divide_ints(a, b) - else: - result = divide_ints.divide_ints(a, b) - assert result == expected_result or result == eval(expected_result) - for global_var_written_to in ["error_code"]: - if global_var_written_to in ["None", "[]", "{}"]: - assert not divide_ints.__dict__.get(global_var_written_to) - else: - assert ( - divide_ints.__dict__.get(global_var_written_to) - == globals_after[global_var_written_to] - ) +""" +Programmatically generated test function for divide_ints() +""" + +import re +import pytest +import divide_ints +from _pytest.monkeypatch import MonkeyPatch + +# Now import modules specific to divide_ints: + +ERROR_CODE = 0 + + +# In sum, these tests covered 100.0% of divide_ints's lines +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "a, b, exception_type, exception_message, expected_result, args_after, globals_after", + [ + ( + "10", + 2, + TypeError, + "TypeError: Variable a='10' is not an int!", + "None", + {}, + {"error_code": -1}, + ), + ( + 3, + 0, + ValueError, + "ValueError: Cannot divide by zero!", + "None", + {}, + {"error_code": -3}, + ), + (6, 2, "N/A", "N/A", "6/2=3.0", {}, {"error_code": 0}), + ( + 8, + [], + TypeError, + "TypeError: Variable b=[] is not an int!", + "None", + {"b": "[]"}, + {"error_code": -2}, + ), + ], + ids=counter, +) +def test_divide_ints( + a, b, exception_type, exception_message, expected_result, args_after, globals_after +): + """ + Programmatically generated test function for divide_ints() + """ + monkeypatch = MonkeyPatch() + monkeypatch.setattr(divide_ints, "error_code", ERROR_CODE) + if exception_type != "N/A": + with pytest.raises(exception_type, match=re.escape(exception_message)): + divide_ints.divide_ints(a, b) + else: + result = divide_ints.divide_ints(a, b) + assert result == expected_result or result == eval(expected_result) + for global_var_written_to in ["error_code"]: + if global_var_written_to in ["None", "[]", "{}"]: + assert not divide_ints.__dict__.get(global_var_written_to) + else: + assert ( + divide_ints.__dict__.get(global_var_written_to) + == globals_after[global_var_written_to] + ) diff --git a/tests/procedural_division/test_normalize_arg_procedural_division.py b/tests/procedural_division/test_normalize_arg_procedural_division.py index d520b7e..3e62aab 100644 --- a/tests/procedural_division/test_normalize_arg_procedural_division.py +++ b/tests/procedural_division/test_normalize_arg_procedural_division.py @@ -1,28 +1,30 @@ -""" -Programmatically generated test function for normalize_arg() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - - -# In sum, these tests covered 60.0% of normalize_arg's lines -# Line(s) not covered by ANY of the tests below: -# ['1721', '1723', '1726-1727'] -@pytest.mark.parametrize( - "arg, expected_result", - [ - ( - "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - ), - ], -) -def test_normalize_arg(arg, expected_result): - """ - Programmatically generated test function for normalize_arg() - """ - result = unit_test_generator.normalize_arg(arg) - assert result == expected_result or result == eval(expected_result) +""" +Programmatically generated test function for normalize_arg() +""" + +import pytest +from src import unit_test_generator + + +# In sum, these tests covered 50.0% of normalize_arg's lines +# Line(s) not covered by ANY of the tests below: +# ['1730', '1732', '1734', '1737-1738'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "arg, expected_result", + [ + (-1, "-1"), + ], + ids=counter, +) +def test_normalize_arg(arg, expected_result): + """ + Programmatically generated test function for normalize_arg() + """ + result = unit_test_generator.normalize_arg(arg) + assert result == expected_result or result == eval(expected_result) diff --git a/tests/procedural_division/test_update_global_procedural_division.py b/tests/procedural_division/test_update_global_procedural_division.py index fc070d2..53dfbc4 100644 --- a/tests/procedural_division/test_update_global_procedural_division.py +++ b/tests/procedural_division/test_update_global_procedural_division.py @@ -1,65 +1,3 @@ -""" -Programmatically generated test function for update_global() -""" - -import re -import pytest -from collections import OrderedDict -from src import unit_test_generator - -# Now import modules specific to update_global: -from logging import Logger -from logging import Manager -from logging import PlaceHolder -from logging import RootLogger -from logging import StreamHandler -from src.unit_test_generator import CoverageInfo - - -# In sum, these tests covered 46.15% of update_global's lines -# Line(s) not covered by ANY of the tests below: -# ['1696', '1708-1709', '1691-1692', '1694-1695'] -@pytest.mark.parametrize( - "obj, this_global, phase, this_coverage_info, expected_result, args_after", - [ - ( - 0, - "error_code", - "Before", - CoverageInfo( - args_before=["6", "2"], - args_after={}, - kwargs={}, - kwargs_after={}, - globals_before={}, - globals_after={}, - expected_result="", - expected_type="", - coverage=[], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - testable=0.0, - ), - "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - { - "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - ), - ], -) -def test_update_global( - obj, this_global, phase, this_coverage_info, expected_result, args_after -): - """ - Programmatically generated test function for update_global() - """ - result = unit_test_generator.update_global( - obj, this_global, phase, this_coverage_info - ) - assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) +""" +No testable inputs - see accompanying JSON file. +""" \ No newline at end of file diff --git a/tests/procedural_division/update_global.json b/tests/procedural_division/update_global.json index b113041..5f91d65 100644 --- a/tests/procedural_division/update_global.json +++ b/tests/procedural_division/update_global.json @@ -1,94 +1,89 @@ -{ - "name": "update_global", - "parameter_names": [ - "obj", - "this_global", - "phase", - "this_coverage_info" - ], - "is_method": false, - "source_file": null, - "lines": [ - 1690, - 1691, - 1692, - 1693, - 1694, - 1695, - 1696, - 1698, - 1706, - 1707, - 1708, - 1709, - 1710 - ], - "non_code_lines": [ - 1697, - 1699, - 1700, - 1701, - 1702, - 1703, - 1704, - 1705 - ], - "coverage_io": { - "0": { - "args_before": [ - "0", - "\"error_code\"", - "\"Before\"", - "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - ], - "args_after": { - "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": {}, - "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=0.0)", - "expected_type": "src.unit_test_generator.CoverageInfo", - "coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - } - }, - "coverage_percentage": 46.15, - "types_in_use": [ - "logging.Logger", - "logging.Manager", - "logging.PlaceHolder", - "logging.RootLogger", - "logging.StreamHandler", - "src.unit_test_generator.CoverageInfo" - ], - "global_vars_read_from": [ - "logger" - ], - "global_vars_written_to": [], - "unified_test_coverage": [ - 1690, - 1693, - 1698, - 1706, - 1707, - 1710 - ], - "needs_pytest": false, - "exceptions_raised": [], - "callable_files": { - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - } +{ + "name": "update_global", + "parameter_names": [ + "obj", + "this_global", + "phase", + "this_coverage_info" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1709, + 1717, + 1718, + 1719, + 1720, + 1721 + ], + "non_code_lines": [ + 1708, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716 + ], + "coverage_io": { + "0": { + "args_before": [ + "", + "\"logger\"", + "\"Before\"", + "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + ], + "args_after": { + "obj": "", + "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "src.unit_test_generator.CoverageInfo", + "coverage": [ + 1701, + 1702, + 1703 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": false + } + }, + "coverage_percentage": 23.08, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler", + "src.unit_test_generator.CoverageInfo" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1701, + 1702, + 1703 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } } \ No newline at end of file From 634234b6888122edaa7df01b0fbab28019a839e3 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 22:31:17 -0500 Subject: [PATCH 156/165] latest windows runner --- .github/workflows/python-app-windows.yml | 212 +++++++++++------------ 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index be80bd8..f43fa3d 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -1,107 +1,107 @@ -# Adapted from: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Test on Windows -run-name: ${{ github.actor }} is testing out DDT on Windows -on: # [push] - pull_request: - branches: [ "master" ] - workflow_dispatch: - -jobs: - lint-test-windows: - - defaults: - run: - shell: bash - runs-on: windows-2019 - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Set up python - id: setup-python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.7.1 - virtualenvs-create: true - virtualenvs-in-project: true - - - name: Load cached venv - id: cached-pip-wheels - uses: actions/cache@v4 - with: - path: ~/.cache - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - - name: Install dependencies - - run: | - set PATH=%PATH%;C:\\Users\\runneradmin\\.local\\bin\\poetry - poetry --version - poetry install --no-interaction --no-root - - - name: Install library - run: poetry install --no-interaction - - run: | - source $VENV - pytest --version - - #- name: Lint with pylint - # continue-on-error: true - # run: | - # # stop the build if there are Python syntax errors or undefined names - # poetry run pylint src\\unit_test_generator.py - - #- name: Typecheck with mypy - # continue-on-error: true - # run: | - # cd src - # poetry run mypy --version - # poetry run mypy unit_test_generator.py - - - name: pytest procedural_division - # continue-on-error: true - run: | - cd tests\\procedural_division - poetry run python divide_ints.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - - name: pytest fizzbuzz - # continue-on-error: true - run: | - cd tests\\fizzbuzz - poetry run python fizzbuzz.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - - name: pytest all_types - # continue-on-error: true - run: | - cd tests\\all_types - poetry run python all_types.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - - name: pytest oo_car - # continue-on-error: true - run: | - cd tests\\oo_car - poetry run python car.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - - name: pytest pass_by_assignment - # continue-on-error: true - run: | - cd tests\\pass_by_assignment - poetry run python pass_by_assignment.py - poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - - name: pytest helper functions - # continue-on-error: true - run: | - cd src - poetry run pytest --log-level=DEBUG -s -v . - +# Adapted from: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Test on Windows +run-name: ${{ github.actor }} is testing out DDT on Windows +on: # [push] + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + lint-test-windows: + + defaults: + run: + shell: bash + runs-on: windows-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.7.1 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-pip-wheels + uses: actions/cache@v4 + with: + path: ~/.cache + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + + run: | + set PATH=%PATH%;C:\\Users\\runneradmin\\.local\\bin\\poetry + poetry --version + poetry install --no-interaction --no-root + + - name: Install library + run: poetry install --no-interaction + - run: | + source $VENV + pytest --version + + #- name: Lint with pylint + # continue-on-error: true + # run: | + # # stop the build if there are Python syntax errors or undefined names + # poetry run pylint src\\unit_test_generator.py + + #- name: Typecheck with mypy + # continue-on-error: true + # run: | + # cd src + # poetry run mypy --version + # poetry run mypy unit_test_generator.py + + - name: pytest procedural_division + # continue-on-error: true + run: | + cd tests\\procedural_division + poetry run python divide_ints.py + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest fizzbuzz + # continue-on-error: true + run: | + cd tests\\fizzbuzz + poetry run python fizzbuzz.py + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest all_types + # continue-on-error: true + run: | + cd tests\\all_types + poetry run python all_types.py + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest oo_car + # continue-on-error: true + run: | + cd tests\\oo_car + poetry run python car.py + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest pass_by_assignment + # continue-on-error: true + run: | + cd tests\\pass_by_assignment + poetry run python pass_by_assignment.py + poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: pytest helper functions + # continue-on-error: true + run: | + cd src + poetry run pytest --log-level=DEBUG -s -v . + # TODO Get full coverage \ No newline at end of file From f7595ed1ce3ab26708c530819033f949bdeab9eb Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 23:19:41 -0500 Subject: [PATCH 157/165] new car --- tests/oo_car/example_car.py | 162 ++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 tests/oo_car/example_car.py diff --git a/tests/oo_car/example_car.py b/tests/oo_car/example_car.py new file mode 100644 index 0000000..eb0abf4 --- /dev/null +++ b/tests/oo_car/example_car.py @@ -0,0 +1,162 @@ +""" +Object-oriented test sample +""" + +import argparse +import logging +import os +from pathlib import Path +import coverage +import sys +import time + +from car import Car +from src import unit_test_generator +from src.unit_test_generator import ( + generate_all_tests_and_metadata, + unit_test_generator_decorator, +) + +FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-25s:%(lineno)-4d:%(message)s' +logging.basicConfig(level=logging.INFO, format=FMT_STR) +logger = logging.getLogger(__name__) +unit_test_generator.logger.setLevel(logging.CRITICAL) + +# The global below is simply so the update_global() function in +# unit_test_generator.py will be executed, without which that +# unit test will be empty and will raise an exception. +method_call_counter = 0 # pylint: disable=invalid-name + +def first_test(): + """ + Create a bunch of cars to test all the Car class methods + except for is_going_faster_than() + """ + # Create a bunch of cars in a loop for testing: + colors = ["Red", "White", "Blue", "Green"] + init_speeds = [10,12,14,16] + init_angles = [0, -30, 30, 90 ] + change_angles = [30, 90, 180, -1080] + change_speed = [-1, 2, 3, 4] + durations = [1,2,-3,4] + lists = [ + colors, + init_speeds, + init_angles, + change_angles, + change_speed, + durations + ] + for i, (color, speed, angle, c_angle, c_speed, duration) in enumerate(zip(*lists)): + logger.info(f"Car #{i}".center(80, '-')) + this_car = Car(color, speed, angle) + if this_car is None or not this_car: + raise ValueError("this_car is None!") + + logger.info(this_car) + logger.info("Driving %s", {this_car.repr()}) + # Note the intentional bug here for the + # sake of demonstrating the ValueError: + try: + this_car.gas(c_speed, duration) + except ValueError as e: + logger.error("gas(%.2f,%d) raised %s", c_speed, duration, type(e)) + # Instead of a try/except we should do: + if c_speed >= 0: + this_car.gas(c_speed, duration) + else: + this_car.brake(c_speed, duration) + + #car.change_steer_angle(c_angle) + try: + this_car.change_steer_angle(c_angle) + except AssertionError as e: + logger.error("change_steer_angle(%s) raised %s", c_angle, type(e)) + + logger.info(this_car) + +def second_test(): + """ + Create two cars and determine which one is going faster + by using the is_going_faster_than() Car method + """ + logger.info("Test 2.1".center(80, '-')) + car_1 = Car("Red", 20, 0) + car_2 = Car("White", 19, 0) + + if car_1.is_going_faster_than(car_2): + logger.info("%s is going faster than %s", car_1, car_2) + else: + logger.info("%s's speed is less than or equal to %s's speed", car_1, car_2) + + logger.info("Test 2.2".center(80, '-')) + # The invocation below will also work, + # demonstrating that the unit_test_generator_decorator works on both + Car.is_going_faster_than(car_1, car_2) + +def main(): + """ + Call test functions for Car class, then generate test files for each + method. + """ + + first_test() + second_test() + generate_all_tests_and_metadata(Path('.'), Path('.')) + +if __name__ == "__main__": + + log_levels = { + 'critical': logging.CRITICAL, + 'error': logging.ERROR, + 'warn': logging.WARNING, + 'warning': logging.WARNING, + 'info': logging.INFO, + 'debug': logging.DEBUG + } + + # Create the parser and add argument(s) + parser = argparse.ArgumentParser() + parser.add_argument('--log-level', + "-l", + help='log level', + type=str, + choices=log_levels.keys(), + default='info') + parser.add_argument("--disable-unit-test-generation", "-d", + action="store_true", + help="Set this flag to deactivate unit test generation for this code") + args = parser.parse_args() + logger.info("args=%s", args) + + this_file = Path(__file__).absolute() + for file in this_file.parent.rglob("*"): + if file.name == "car.py": + continue + if file.suffix in (".py", ".json") and file.absolute() != this_file: + logger.debug("%s != %s", file.absolute().name, this_file.name) + logger.debug("Deleting %s to ensure clean start", file.name) + logger.warning(f"Removing {file=}") + os.remove(file) + logger.info("Sleep 1 s...") + time.sleep(1) + if args.disable_unit_test_generation: + main() + sys.exit(0) + # The code below applies the CLI arg above to selectively enable/disable + # automatic unit test generation (Could not use the syntactic sugar method + # of applying decorators as the user's input isn't parsed until now.) + # Alternatively, move the argument parsing to the very top of this file. + # NOTE: + # Decorating all functions programmatically is left as an exercise to the reader: + # Hint: https://stackoverflow.com/questions/3467526/ + Car.brake = unit_test_generator_decorator(110, 100)(Car.brake) + Car.gas = unit_test_generator_decorator(110, 100)(Car.gas) + Car.change_steer_angle = unit_test_generator_decorator(110, 100, True)(Car.change_steer_angle) + Car.is_going_faster_than = unit_test_generator_decorator(110, 110)(Car.is_going_faster_than) + Car.__init__ = unit_test_generator_decorator(110, 110)(Car.__init__) + + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() From 82b62f0b3a2effade9ec8e0f12970b789eeb69db Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Thu, 13 Nov 2025 23:22:54 -0500 Subject: [PATCH 158/165] Should be ready for presentation --- .github/workflows/python-app-ubuntu.yml | 8 +- .github/workflows/python-app-windows.yml | 2 +- tests/all_types/test_get_item_at_index.py | 2 +- tests/delete_test_files.bat | 49 +++--- tests/oo_car/Car.is_going_faster_than.json | 2 +- tests/oo_car/car.py | 131 ---------------- tests/oo_car/example_car.py | 5 +- tests/oo_car/test_car_is_going_faster_than.py | 1 - tests/oo_car/update_global.json | 4 +- .../test_add_to_my_set_kwargs.py | 2 +- tests/pass_by_assignment/test_append_list.py | 2 +- .../test_increment_my_list_kwargs.py | 2 +- .../pass_by_assignment/test_overwrite_list.py | 2 +- .../coverage_str_helper.json | 140 ++++++++++++++++++ tests/procedural_division/normalize_arg.json | 10 +- ...coverage_str_helper_procedural_division.py | 48 ++++++ tests/procedural_division/test_divide_ints.py | 2 +- .../test_normalize_arg_procedural_division.py | 9 +- .../test_update_global_procedural_division.py | 66 ++++++++- tests/procedural_division/update_global.json | 27 ++-- tests/test_all_keep_files.bat | 46 +++--- tests/test_all_keep_files_keep_output.bat | 22 ++- 22 files changed, 359 insertions(+), 223 deletions(-) create mode 100644 tests/procedural_division/coverage_str_helper.json create mode 100644 tests/procedural_division/test_coverage_str_helper_procedural_division.py diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index e99abf6..c87e71b 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -157,10 +157,10 @@ jobs: # continue-on-error: true run: | cd tests/oo_car - # echo "car.py -d runtime:" - poetry run python car.py -d - #echo "car.py runtime:" - poetry run python car.py + # echo "example_car.py -d runtime:" + poetry run python example_car.py -d + #echo "example_car.py runtime:" + poetry run python example_car.py sleep 1 poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index f43fa3d..de52c31 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -88,7 +88,7 @@ jobs: # continue-on-error: true run: | cd tests\\oo_car - poetry run python car.py + poetry run python example_car.py poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index 2456493..c421d66 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -4,7 +4,7 @@ import re import pytest -import all_types +from tests.all_types import all_types # In sum, these tests covered 85.71% of get_item_at_index's lines diff --git a/tests/delete_test_files.bat b/tests/delete_test_files.bat index e7b8331..2f40ba7 100644 --- a/tests/delete_test_files.bat +++ b/tests/delete_test_files.bat @@ -1,24 +1,27 @@ -cd fizzbuzz -SET "keepfile=fizzbuzz.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" -cd .. - -cd all_types -SET "keepfile=all_types.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" -cd .. - -cd procedural_division -SET "keepfile=divide_ints.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" -cd .. - -cd oo_car -SET "keepfile=car.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" -cd .. - -cd pass_by_assignment -SET "keepfile=pass_by_assignment.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +cd fizzbuzz +SET "keepfile=fizzbuzz.py" +FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +cd .. + +cd all_types +SET "keepfile=all_types.py" +FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +cd .. + +cd procedural_division +SET "keepfile=divide_ints.py" +FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +cd .. + +cd oo_car +SET "keepfile=car.py" +SET "keepfile2=example_car.py" +FOR %%a IN (".\*") DO ( + IF /i NOT "%%~nxa"=="%keepfile%" IF /i NOT "%%~nxa"=="%keepfile2%" DEL "%%a" +) +cd .. + +cd pass_by_assignment +SET "keepfile=pass_by_assignment.py" +FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" cd .. \ No newline at end of file diff --git a/tests/oo_car/Car.is_going_faster_than.json b/tests/oo_car/Car.is_going_faster_than.json index 0cb637c..7d729c7 100644 --- a/tests/oo_car/Car.is_going_faster_than.json +++ b/tests/oo_car/Car.is_going_faster_than.json @@ -36,7 +36,7 @@ }, "coverage_percentage": 100.0, "types_in_use": [ - "__main__.Car", + "car.Car", "tests.oo_car.car.Car" ], "global_vars_read_from": [], diff --git a/tests/oo_car/car.py b/tests/oo_car/car.py index 4f0e47a..2f4250b 100644 --- a/tests/oo_car/car.py +++ b/tests/oo_car/car.py @@ -140,134 +140,3 @@ def __eq__(self, other_car:object) -> bool: if self.steer_angle != other_car.steer_angle: return False return True -def first_test(): - """ - Create a bunch of cars to test all the Car class methods - except for is_going_faster_than() - """ - # Create a bunch of cars in a loop for testing: - colors = ["Red", "White", "Blue", "Green"] - init_speeds = [10,12,14,16] - init_angles = [0, -30, 30, 90 ] - change_angles = [30, 90, 180, -1080] - change_speed = [-1, 2, 3, 4] - durations = [1,2,-3,4] - lists = [ - colors, - init_speeds, - init_angles, - change_angles, - change_speed, - durations - ] - for i, (color, speed, angle, c_angle, c_speed, duration) in enumerate(zip(*lists)): - logger.info(f"Car #{i}".center(80, '-')) - this_car = Car(color, speed, angle) - if this_car is None or not this_car: - raise ValueError("this_car is None!") - - logger.info(this_car) - logger.info("Driving %s", {this_car.repr()}) - # Note the intentional bug here for the - # sake of demonstrating the ValueError: - try: - this_car.gas(c_speed, duration) - except ValueError as e: - logger.error("gas(%.2f,%d) raised %s", c_speed, duration, type(e)) - # Instead of a try/except we should do: - if c_speed >= 0: - this_car.gas(c_speed, duration) - else: - this_car.brake(c_speed, duration) - - #car.change_steer_angle(c_angle) - try: - this_car.change_steer_angle(c_angle) - except AssertionError as e: - logger.error("change_steer_angle(%s) raised %s", c_angle, type(e)) - - logger.info(this_car) - -def second_test(): - """ - Create two cars and determine which one is going faster - by using the is_going_faster_than() Car method - """ - logger.info("Test 2.1".center(80, '-')) - car_1 = Car("Red", 20, 0) - car_2 = Car("White", 19, 0) - - if car_1.is_going_faster_than(car_2): - logger.info("%s is going faster than %s", car_1, car_2) - else: - logger.info("%s's speed is less than or equal to %s's speed", car_1, car_2) - - logger.info("Test 2.2".center(80, '-')) - # The invocation below will also work, - # demonstrating that the unit_test_generator_decorator works on both - Car.is_going_faster_than(car_1, car_2) - -def main(): - """ - Call test functions for Car class, then generate test files for each - method. - """ - - first_test() - second_test() - generate_all_tests_and_metadata(Path('.'), Path('.')) - -if __name__ == "__main__": - - log_levels = { - 'critical': logging.CRITICAL, - 'error': logging.ERROR, - 'warn': logging.WARNING, - 'warning': logging.WARNING, - 'info': logging.INFO, - 'debug': logging.DEBUG - } - - # Create the parser and add argument(s) - parser = argparse.ArgumentParser() - parser.add_argument('--log-level', - "-l", - help='log level', - type=str, - choices=log_levels.keys(), - default='info') - parser.add_argument("--disable-unit-test-generation", "-d", - action="store_true", - help="Set this flag to deactivate unit test generation for this code") - args = parser.parse_args() - logger.info("args=%s", args) - - this_file = Path(__file__).absolute() - for file in this_file.parent.rglob("*"): - if file.suffix in (".py", ".json") and file.absolute() != this_file: - logger.debug("%s != %s", file.absolute().name, this_file.name) - logger.debug("Deleting %s to ensure clean start", file.name) - logger.warning(f"Removing {file=}") - os.remove(file) - logger.info("Sleep 1 s...") - time.sleep(1) - if args.disable_unit_test_generation: - main() - sys.exit(0) - # The code below applies the CLI arg above to selectively enable/disable - # automatic unit test generation (Could not use the syntactic sugar method - # of applying decorators as the user's input isn't parsed until now.) - # Alternatively, move the argument parsing to the very top of this file. - # NOTE: - # Decorating all functions programmatically is left as an exercise to the reader: - # Hint: https://stackoverflow.com/questions/3467526/ - Car.brake = unit_test_generator_decorator(110, 100)(Car.brake) - Car.gas = unit_test_generator_decorator(110, 100)(Car.gas) - Car.change_steer_angle = unit_test_generator_decorator(110, 100, True)(Car.change_steer_angle) - Car.is_going_faster_than = unit_test_generator_decorator(110, 110)(Car.is_going_faster_than) - Car.__init__ = unit_test_generator_decorator(110, 110)(Car.__init__) - - cov = coverage.Coverage() - with cov.collect(): - main() - cov.save() diff --git a/tests/oo_car/example_car.py b/tests/oo_car/example_car.py index eb0abf4..b64c6e3 100644 --- a/tests/oo_car/example_car.py +++ b/tests/oo_car/example_car.py @@ -136,10 +136,9 @@ def main(): if file.suffix in (".py", ".json") and file.absolute() != this_file: logger.debug("%s != %s", file.absolute().name, this_file.name) logger.debug("Deleting %s to ensure clean start", file.name) - logger.warning(f"Removing {file=}") + logger.warning("Removing file: %s", file) os.remove(file) - logger.info("Sleep 1 s...") - time.sleep(1) + if args.disable_unit_test_generation: main() sys.exit(0) diff --git a/tests/oo_car/test_car_is_going_faster_than.py b/tests/oo_car/test_car_is_going_faster_than.py index 178187a..e3f2e20 100644 --- a/tests/oo_car/test_car_is_going_faster_than.py +++ b/tests/oo_car/test_car_is_going_faster_than.py @@ -5,7 +5,6 @@ import pytest # Now import modules specific to Car.is_going_faster_than: -from car import Car from tests.oo_car.car import Car diff --git a/tests/oo_car/update_global.json b/tests/oo_car/update_global.json index 6213dd4..f346a1b 100644 --- a/tests/oo_car/update_global.json +++ b/tests/oo_car/update_global.json @@ -36,13 +36,13 @@ "coverage_io": { "0": { "args_before": [ - "", + "", "\"logger\"", "\"Before\"", "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" ], "args_after": { - "obj": "", + "obj": "", "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" }, "kwargs": {}, diff --git a/tests/pass_by_assignment/test_add_to_my_set_kwargs.py b/tests/pass_by_assignment/test_add_to_my_set_kwargs.py index eb1dc7a..39b7bb7 100644 --- a/tests/pass_by_assignment/test_add_to_my_set_kwargs.py +++ b/tests/pass_by_assignment/test_add_to_my_set_kwargs.py @@ -3,7 +3,7 @@ """ import pytest -import pass_by_assignment +from tests.pass_by_assignment import pass_by_assignment # In sum, these tests covered 66.67% of add_to_my_set_kwargs's lines diff --git a/tests/pass_by_assignment/test_append_list.py b/tests/pass_by_assignment/test_append_list.py index 07f590b..91875d1 100644 --- a/tests/pass_by_assignment/test_append_list.py +++ b/tests/pass_by_assignment/test_append_list.py @@ -3,7 +3,7 @@ """ import pytest -import pass_by_assignment +from tests.pass_by_assignment import pass_by_assignment # Now import modules specific to append_list: diff --git a/tests/pass_by_assignment/test_increment_my_list_kwargs.py b/tests/pass_by_assignment/test_increment_my_list_kwargs.py index bdd0830..0767ce7 100644 --- a/tests/pass_by_assignment/test_increment_my_list_kwargs.py +++ b/tests/pass_by_assignment/test_increment_my_list_kwargs.py @@ -3,7 +3,7 @@ """ import pytest -import pass_by_assignment +from tests.pass_by_assignment import pass_by_assignment # In sum, these tests covered 66.67% of increment_my_list_kwargs's lines diff --git a/tests/pass_by_assignment/test_overwrite_list.py b/tests/pass_by_assignment/test_overwrite_list.py index 8ecb005..aa6c150 100644 --- a/tests/pass_by_assignment/test_overwrite_list.py +++ b/tests/pass_by_assignment/test_overwrite_list.py @@ -3,7 +3,7 @@ """ import pytest -import pass_by_assignment +from tests.pass_by_assignment import pass_by_assignment # In sum, these tests covered 100.0% of overwrite_list's lines diff --git a/tests/procedural_division/coverage_str_helper.json b/tests/procedural_division/coverage_str_helper.json new file mode 100644 index 0000000..d66660a --- /dev/null +++ b/tests/procedural_division/coverage_str_helper.json @@ -0,0 +1,140 @@ +{ + "name": "coverage_str_helper", + "parameter_names": [ + "this_list", + "non_code_lines" + ], + "is_method": false, + "source_file": null, + "lines": [ + 1759, + 1760, + 1761, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1773, + 1774, + 1775, + 1777, + 1778, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1786, + 1787, + 1789, + 1790, + 1791, + 1793, + 1795 + ], + "non_code_lines": [ + 1776, + 1785, + 1788, + 1792, + 1794 + ], + "coverage_io": { + "0": { + "args_before": [ + "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + ], + "args_after": { + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": {}, + "globals_after": {}, + "expected_result": "['1702-1703', '1705-1707', '1719-1720']", + "expected_type": "list", + "coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1773, + 1774, + 1775, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1789, + 1795 + ], + "exception_type": "", + "exception_message": "", + "constructor": "", + "cost": 0.0, + "testable": true + } + }, + "coverage_percentage": 71.88, + "types_in_use": [ + "logging.Logger", + "logging.Manager", + "logging.PlaceHolder", + "logging.RootLogger", + "logging.StreamHandler" + ], + "global_vars_read_from": [ + "logger" + ], + "global_vars_written_to": [], + "unified_test_coverage": [ + 1759, + 1760, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1773, + 1774, + 1775, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1789, + 1795 + ], + "needs_pytest": false, + "exceptions_raised": [], + "callable_files": { + "coverage_str_helper": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" + } +} \ No newline at end of file diff --git a/tests/procedural_division/normalize_arg.json b/tests/procedural_division/normalize_arg.json index bbc2c1b..ae162e9 100644 --- a/tests/procedural_division/normalize_arg.json +++ b/tests/procedural_division/normalize_arg.json @@ -23,17 +23,18 @@ "coverage_io": { "0": { "args_before": [ - "-1" + "\"CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)\"" ], "args_after": {}, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "-1", - "expected_type": "int", + "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_type": "str", "coverage": [ 1729, + 1730, 1731, 1733, 1736, @@ -46,12 +47,13 @@ "testable": true } }, - "coverage_percentage": 50.0, + "coverage_percentage": 60.0, "types_in_use": [], "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ 1729, + 1730, 1731, 1733, 1736, diff --git a/tests/procedural_division/test_coverage_str_helper_procedural_division.py b/tests/procedural_division/test_coverage_str_helper_procedural_division.py new file mode 100644 index 0000000..6e329d3 --- /dev/null +++ b/tests/procedural_division/test_coverage_str_helper_procedural_division.py @@ -0,0 +1,48 @@ +""" +Programmatically generated test function for coverage_str_helper() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to coverage_str_helper: + + +# In sum, these tests covered 71.88% of coverage_str_helper's lines +# Line(s) not covered by ANY of the tests below: +# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "this_list, non_code_lines, expected_result, args_after", + [ + ( + [1702, 1703, 1705, 1706, 1707, 1719, 1720], + {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, + "['1702-1703', '1705-1707', '1719-1720']", + { + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", + }, + ), + ], + ids=counter, +) +def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_after): + """ + Programmatically generated test function for coverage_str_helper() + """ + result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) + assert result == expected_result or result == eval(expected_result) + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) diff --git a/tests/procedural_division/test_divide_ints.py b/tests/procedural_division/test_divide_ints.py index a1f0d57..1415e95 100644 --- a/tests/procedural_division/test_divide_ints.py +++ b/tests/procedural_division/test_divide_ints.py @@ -4,7 +4,7 @@ import re import pytest -import divide_ints +from tests.procedural_division import divide_ints from _pytest.monkeypatch import MonkeyPatch # Now import modules specific to divide_ints: diff --git a/tests/procedural_division/test_normalize_arg_procedural_division.py b/tests/procedural_division/test_normalize_arg_procedural_division.py index 3e62aab..fcc0228 100644 --- a/tests/procedural_division/test_normalize_arg_procedural_division.py +++ b/tests/procedural_division/test_normalize_arg_procedural_division.py @@ -6,9 +6,9 @@ from src import unit_test_generator -# In sum, these tests covered 50.0% of normalize_arg's lines +# In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1730', '1732', '1734', '1737-1738'] +# ['1732', '1734', '1737-1738'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -18,7 +18,10 @@ def counter(start=0) -> str: @pytest.mark.parametrize( "arg, expected_result", [ - (-1, "-1"), + ( + "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + ), ], ids=counter, ) diff --git a/tests/procedural_division/test_update_global_procedural_division.py b/tests/procedural_division/test_update_global_procedural_division.py index 53dfbc4..b04d224 100644 --- a/tests/procedural_division/test_update_global_procedural_division.py +++ b/tests/procedural_division/test_update_global_procedural_division.py @@ -1,3 +1,65 @@ """ -No testable inputs - see accompanying JSON file. -""" \ No newline at end of file +Programmatically generated test function for update_global() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to update_global: +from src.unit_test_generator import CoverageInfo + + +# In sum, these tests covered 46.15% of update_global's lines +# Line(s) not covered by ANY of the tests below: +# ['1702-1703', '1705-1707', '1719-1720'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "obj, this_global, phase, this_coverage_info, expected_result, args_after", + [ + ( + 0, + "error_code", + "Before", + CoverageInfo( + args_before=["6", "2"], + args_after={}, + kwargs={}, + kwargs_after={}, + globals_before={}, + globals_after={}, + expected_result="", + expected_type="", + coverage=[], + exception_type="", + exception_message="", + constructor="", + cost=0.0, + testable=True, + ), + "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + { + "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + }, + ), + ], + ids=counter, +) +def test_update_global( + obj, this_global, phase, this_coverage_info, expected_result, args_after +): + """ + Programmatically generated test function for update_global() + """ + result = unit_test_generator.update_global( + obj, this_global, phase, this_coverage_info + ) + assert result == expected_result or result == eval(expected_result) + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) diff --git a/tests/procedural_division/update_global.json b/tests/procedural_division/update_global.json index 5f91d65..417452e 100644 --- a/tests/procedural_division/update_global.json +++ b/tests/procedural_division/update_global.json @@ -36,34 +36,36 @@ "coverage_io": { "0": { "args_before": [ - "", - "\"logger\"", + "0", + "\"error_code\"", "\"Before\"", "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" ], "args_after": { - "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" + "this_coverage_info": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", + "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ 1701, - 1702, - 1703 + 1704, + 1709, + 1717, + 1718, + 1721 ], "exception_type": "", "exception_message": "", "constructor": "", "cost": 0.0, - "testable": false + "testable": true } }, - "coverage_percentage": 23.08, + "coverage_percentage": 46.15, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -78,8 +80,11 @@ "global_vars_written_to": [], "unified_test_coverage": [ 1701, - 1702, - 1703 + 1704, + 1709, + 1717, + 1718, + 1721 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/test_all_keep_files.bat b/tests/test_all_keep_files.bat index 0d6e330..40917a5 100644 --- a/tests/test_all_keep_files.bat +++ b/tests/test_all_keep_files.bat @@ -1,24 +1,24 @@ -cd fizzbuzz -python fizzbuzz.py >NUL 2>NUL -pytest -s -vv . -cd .. - -cd all_types -python all_types.py >NUL 2>NUL -pytest -s -vv . -cd .. - -cd procedural_division -python divide_ints.py >NUL 2>NUL -pytest -s -vv . -cd .. - -cd oo_car -python car.py >NUL 2>NUL -pytest -s -vv . -cd .. - -cd pass_by_assignment -python pass_by_assignment.py >NUL 2>NUL -pytest -s -vv . +cd fizzbuzz +python fizzbuzz.py >NUL 2>NUL +pytest -s -vv . +cd .. + +cd all_types +python all_types.py >NUL 2>NUL +pytest -s -vv . +cd .. + +cd procedural_division +python divide_ints.py >NUL 2>NUL +pytest -s -vv . +cd .. + +cd oo_car +python example_car.py >NUL 2>NUL +pytest -s -vv . +cd .. + +cd pass_by_assignment +python pass_by_assignment.py >NUL 2>NUL +pytest -s -vv . cd .. \ No newline at end of file diff --git a/tests/test_all_keep_files_keep_output.bat b/tests/test_all_keep_files_keep_output.bat index 61b0427..ee33cb2 100644 --- a/tests/test_all_keep_files_keep_output.bat +++ b/tests/test_all_keep_files_keep_output.bat @@ -1,21 +1,25 @@ cd fizzbuzz python fizzbuzz.py -pytest -s -vv . +coverage run -m pytest +::pytest -s -vv . cd .. cd all_types python all_types.py -pytest -s -vv . +coverage run -m pytest +::pytest -s -vv . cd .. cd procedural_division python divide_ints.py -pytest -s -vv . +coverage run -m pytest +::pytest -s -vv . cd .. cd oo_car -python car.py -pytest -s -vv . +python example_car.py +coverage run -m pytest +::pytest -s -vv . cd .. cd pass_by_assignment @@ -24,8 +28,10 @@ pytest -s -vv . cd .. cd ..\src -pytest . -cd ..\tests +:: pytest . +coverage run -m pytest +cd .. coverage combine tests\fizzbuzz\.coverage tests\oo_car\.coverage tests\all_types\.coverage tests\all_types\.coverage tests\procedural_division\.coverage src\.coverage -coverage report -m \ No newline at end of file +coverage report -m +coverage html \ No newline at end of file From e9d8e12418f498472000af61892bd4309897dd2b Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 00:11:58 -0500 Subject: [PATCH 159/165] done --- tests/all_types/test_get_item_at_index.py | 2 +- tests/delete_test_files.bat | 15 +- tests/fizzbuzz/example_fizzbuzz.py | 104 ++++++++++++++ tests/fizzbuzz/fizzbuzz.json | 129 +++++------------- tests/fizzbuzz/fizzbuzz.py | 90 +----------- tests/fizzbuzz/test_fizzbuzz.py | 19 +-- tests/oo_car/coverage_str_helper.json | 32 +++-- .../oo_car/test_coverage_str_helper_oo_car.py | 15 +- tests/oo_car/test_update_global_oo_car.py | 66 ++++++++- tests/oo_car/update_global.json | 27 ++-- .../add_to_my_set_kwargs.json | 14 +- tests/pass_by_assignment/append_list.json | 12 +- .../example_pass_by_assignment.py | 115 ++++++++++++++++ .../increment_my_list_kwargs.json | 14 +- tests/pass_by_assignment/overwrite_list.json | 12 +- .../pass_by_assignment/pass_by_assignment.py | 105 +------------- tests/pass_by_assignment/update_global.json | 4 +- tests/procedural_division/divide_ints.json | 68 ++++----- tests/procedural_division/divide_ints.py | 75 ---------- .../example_divide_ints.py | 99 ++++++++++++++ tests/procedural_division/test_divide_ints.py | 42 +++--- tests/test_all_keep_files.bat | 6 +- tests/test_all_keep_files_keep_output.bat | 13 +- 23 files changed, 585 insertions(+), 493 deletions(-) create mode 100644 tests/fizzbuzz/example_fizzbuzz.py create mode 100644 tests/pass_by_assignment/example_pass_by_assignment.py create mode 100644 tests/procedural_division/example_divide_ints.py diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index c421d66..2456493 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -4,7 +4,7 @@ import re import pytest -from tests.all_types import all_types +import all_types # In sum, these tests covered 85.71% of get_item_at_index's lines diff --git a/tests/delete_test_files.bat b/tests/delete_test_files.bat index 2f40ba7..50e761a 100644 --- a/tests/delete_test_files.bat +++ b/tests/delete_test_files.bat @@ -1,6 +1,9 @@ cd fizzbuzz SET "keepfile=fizzbuzz.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +SET "keepfile2=example_fizzbuzz.py" +FOR %%a IN (".\*") DO ( + IF /i NOT "%%~nxa"=="%keepfile%" IF /i NOT "%%~nxa"=="%keepfile2%" DEL "%%a" +) cd .. cd all_types @@ -10,7 +13,10 @@ cd .. cd procedural_division SET "keepfile=divide_ints.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +SET "keepfile2=example_divide_ints.py" +FOR %%a IN (".\*") DO ( + IF /i NOT "%%~nxa"=="%keepfile%" IF /i NOT "%%~nxa"=="%keepfile2%" DEL "%%a" +) cd .. cd oo_car @@ -23,5 +29,8 @@ cd .. cd pass_by_assignment SET "keepfile=pass_by_assignment.py" -FOR %%a IN (".\*") DO IF /i NOT "%%~nxa"=="%keepfile%" DEL "%%a" +SET "keepfile2=example_pass_by_assignment.py" +FOR %%a IN (".\*") DO ( + IF /i NOT "%%~nxa"=="%keepfile%" IF /i NOT "%%~nxa"=="%keepfile2%" DEL "%%a" +) cd .. \ No newline at end of file diff --git a/tests/fizzbuzz/example_fizzbuzz.py b/tests/fizzbuzz/example_fizzbuzz.py new file mode 100644 index 0000000..f70911f --- /dev/null +++ b/tests/fizzbuzz/example_fizzbuzz.py @@ -0,0 +1,104 @@ +""" +Test case to demonstrate the DDT concept on a variant of the fizzbuzz problem. +Includes a global variable. +""" +import argparse +import logging +import os +import sys +from pathlib import Path +import coverage +import json + +from fizzbuzz import fizzbuzz, mode +from src import unit_test_generator +from src.unit_test_generator import ( + generate_all_tests_and_metadata, + unit_test_generator_decorator, + Capturing +) + +FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s' +logging.basicConfig(level=logging.INFO, format=FMT_STR) +logger = logging.getLogger(__name__) +unit_test_generator.logger.setLevel(logging.WARNING) + + +def main(): + """ + Begin ad hoc tests + """ + global mode # pylint: disable=global-statement + + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = 'buzzfizz' + print(fizzbuzz(6)) + print(fizzbuzz(30)) + mode = "a_test" + print(fizzbuzz(6)) + + ''' + with Capturing() as stdout_lines: + cov.json_report(outfile='-') + # result will not exist if the function threw an exception + cov_report_ = json.loads(stdout_lines[0]) + logger.critical(cov_report_) + ''' + + # The generate_all_tests_and_metadata() function takes 2 Paths: + # 1. The output directory for the unit tests (.py) + # 2. The output directory for the .json files (I/O for each test) + + generate_all_tests_and_metadata(Path('.'), Path('.')) + +if __name__ == "__main__": + + log_levels = { + 'critical': logging.CRITICAL, + 'error': logging.ERROR, + 'warn': logging.WARNING, + 'warning': logging.WARNING, + 'info': logging.INFO, + 'debug': logging.DEBUG + } + + # Create the parser and add argument(s) + parser = argparse.ArgumentParser() + parser.add_argument('--log-level', + "-l", + help='log level', + type=str, + choices=log_levels.keys(), + default='info') + parser.add_argument("--disable-unit-test-generation", "-d", + action="store_true", + help="Set this flag to deactivate unit test generation for this code") + args = parser.parse_args() + print(f"{args=}") + + this_file = Path(__file__).absolute() + for file in this_file.parent.rglob("*"): + if file.name == "fizzbuzz.py": + continue + if file.suffix in (".py", ".json") and file.absolute() != this_file: + logger.debug("Deleting %s to ensure clean start", this_file) + os.remove(file) + + + if args.disable_unit_test_generation: + main() + sys.exit(0) + + # The code below applies the CLI arg above to selectively enable/disable + # automatic unit test generation (Could not use the syntactic sugar method + # of applying decorators as the user's input isn't parsed until now.) + # Alternatively, move the argument parsing to the very top of this file. + # NOTE: + # Decorating all functions programmatically is left as an exercise to the reader: + # Hint: https://stackoverflow.com/questions/3467526/ + #fizzbuzz = unit_test_generator_decorator(not args.disable_unit_test_generation)(fizzbuzz) + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file diff --git a/tests/fizzbuzz/fizzbuzz.json b/tests/fizzbuzz/fizzbuzz.json index a487d0a..6d8a000 100644 --- a/tests/fizzbuzz/fizzbuzz.json +++ b/tests/fizzbuzz/fizzbuzz.json @@ -6,86 +6,29 @@ "is_method": false, "source_file": null, "lines": [ + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, 44, 45, 46, 47, - 48, 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 60, - 61 + 50 ], "non_code_lines": [ - 59 + 48 ], "coverage_io": { "0": { - "args_before": [ - "6" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "mode": "a_test" - }, - "globals_after": {}, - "expected_result": "Mode 'a_test' invalid for fizzbuzz()", - "expected_type": "str", - "coverage": [ - 44, - 45, - 52, - 60, - 61 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "1": { - "args_before": [ - "30" - ], - "args_after": {}, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "mode": "buzzfizz" - }, - "globals_after": {}, - "expected_result": "30 with mode='buzzfizz' yields 'buzzfizz'", - "expected_type": "str", - "coverage": [ - 44, - 45, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 61 - ], - "exception_type": "", - "exception_message": "", - "constructor": "", - "cost": 0.0, - "testable": true - }, - "2": { "args_before": [ "30" ], @@ -99,15 +42,15 @@ "expected_result": "30 with mode='fizzbuzz' yields 'fizzbuzz'", "expected_type": "str", "coverage": [ - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 61 + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 50 ], "exception_type": "", "exception_message": "", @@ -116,30 +59,22 @@ "testable": true } }, - "coverage_percentage": 100.0, + "coverage_percentage": 52.94, "types_in_use": [], "global_vars_read_from": [ "mode" ], "global_vars_written_to": [], "unified_test_coverage": [ - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 60, - 61 + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 50 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/fizzbuzz/fizzbuzz.py b/tests/fizzbuzz/fizzbuzz.py index 4313ae5..8c76771 100644 --- a/tests/fizzbuzz/fizzbuzz.py +++ b/tests/fizzbuzz/fizzbuzz.py @@ -2,13 +2,6 @@ Test case to demonstrate the DDT concept on a variant of the fizzbuzz problem. Includes a global variable. """ -import argparse -import logging -import os -import sys -from pathlib import Path -import coverage -import json from src import unit_test_generator from src.unit_test_generator import ( @@ -17,13 +10,9 @@ Capturing ) -FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s' -logging.basicConfig(level=logging.INFO, format=FMT_STR) -logger = logging.getLogger(__name__) -unit_test_generator.logger.setLevel(logging.WARNING) - mode = 'fizzbuzz' # pylint: disable=invalid-name + @unit_test_generator_decorator(110,100) def fizzbuzz(number: int): """ @@ -59,80 +48,3 @@ def fizzbuzz(number: int): else: result = f"Mode '{mode}' invalid for fizzbuzz()" return result - -def main(): - """ - Begin ad hoc tests - """ - global mode # pylint: disable=global-statement - - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = 'buzzfizz' - print(fizzbuzz(6)) - print(fizzbuzz(30)) - mode = "a_test" - print(fizzbuzz(6)) - - ''' - with Capturing() as stdout_lines: - cov.json_report(outfile='-') - # result will not exist if the function threw an exception - cov_report_ = json.loads(stdout_lines[0]) - logger.critical(cov_report_) - ''' - - # The generate_all_tests_and_metadata() function takes 2 Paths: - # 1. The output directory for the unit tests (.py) - # 2. The output directory for the .json files (I/O for each test) - - generate_all_tests_and_metadata(Path('.'), Path('.')) - -if __name__ == "__main__": - - log_levels = { - 'critical': logging.CRITICAL, - 'error': logging.ERROR, - 'warn': logging.WARNING, - 'warning': logging.WARNING, - 'info': logging.INFO, - 'debug': logging.DEBUG - } - - # Create the parser and add argument(s) - parser = argparse.ArgumentParser() - parser.add_argument('--log-level', - "-l", - help='log level', - type=str, - choices=log_levels.keys(), - default='info') - parser.add_argument("--disable-unit-test-generation", "-d", - action="store_true", - help="Set this flag to deactivate unit test generation for this code") - args = parser.parse_args() - print(f"{args=}") - - this_file = Path(__file__).absolute() - for file in this_file.parent.rglob("*"): - if file.suffix in (".py", ".json") and file.absolute() != this_file: - logger.debug("Deleting %s to ensure clean start", this_file) - os.remove(file) - - - if args.disable_unit_test_generation: - main() - sys.exit(0) - - # The code below applies the CLI arg above to selectively enable/disable - # automatic unit test generation (Could not use the syntactic sugar method - # of applying decorators as the user's input isn't parsed until now.) - # Alternatively, move the argument parsing to the very top of this file. - # NOTE: - # Decorating all functions programmatically is left as an exercise to the reader: - # Hint: https://stackoverflow.com/questions/3467526/ - #fizzbuzz = unit_test_generator_decorator(not args.disable_unit_test_generation)(fizzbuzz) - cov = coverage.Coverage() - with cov.collect(): - main() - cov.save() \ No newline at end of file diff --git a/tests/fizzbuzz/test_fizzbuzz.py b/tests/fizzbuzz/test_fizzbuzz.py index a51e286..a8c2e7f 100644 --- a/tests/fizzbuzz/test_fizzbuzz.py +++ b/tests/fizzbuzz/test_fizzbuzz.py @@ -3,11 +3,15 @@ """ import pytest -from tests.fizzbuzz import fizzbuzz +import fizzbuzz from _pytest.monkeypatch import MonkeyPatch +MODE = "fizzbuzz" -# In sum, these tests covered 100.0% of fizzbuzz's lines + +# In sum, these tests covered 52.94% of fizzbuzz's lines +# Line(s) not covered by ANY of the tests below: +# ['41-47'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -15,20 +19,17 @@ def counter(start=0) -> str: @pytest.mark.parametrize( - "number, expected_result, globals_before", + "number, expected_result", [ - (6, "Mode 'a_test' invalid for fizzbuzz()", {"mode": "a_test"}), - (30, "30 with mode='buzzfizz' yields 'buzzfizz'", {"mode": "buzzfizz"}), - (30, "30 with mode='fizzbuzz' yields 'fizzbuzz'", {"mode": "fizzbuzz"}), + (30, "30 with mode='fizzbuzz' yields 'fizzbuzz'"), ], ids=counter, ) -def test_fizzbuzz(number, expected_result, globals_before): +def test_fizzbuzz(number, expected_result): """ Programmatically generated test function for fizzbuzz() """ monkeypatch = MonkeyPatch() - for k, v in globals_before.items(): - monkeypatch.setattr(fizzbuzz, k, v) + monkeypatch.setattr(fizzbuzz, "mode", MODE) result = fizzbuzz.fizzbuzz(number) assert result == expected_result or result == eval(expected_result) diff --git a/tests/oo_car/coverage_str_helper.json b/tests/oo_car/coverage_str_helper.json index 8da2a1a..d66660a 100644 --- a/tests/oo_car/coverage_str_helper.json +++ b/tests/oo_car/coverage_str_helper.json @@ -50,18 +50,18 @@ "coverage_io": { "0": { "args_before": [ - "[55, 57]", - "set()" + "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" ], "args_after": { - "this_list": "[55, 57]", - "non_code_lines": "set()" + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['55']", + "expected_result": "['1702-1703', '1705-1707', '1719-1720']", "expected_type": "list", "coverage": [ 1759, @@ -72,13 +72,19 @@ 1765, 1766, 1767, + 1768, + 1769, + 1770, 1771, 1773, - 1777, - 1778, + 1774, + 1775, 1779, 1780, 1781, + 1782, + 1783, + 1784, 1789, 1795 ], @@ -89,7 +95,7 @@ "testable": true } }, - "coverage_percentage": 53.12, + "coverage_percentage": 71.88, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -110,13 +116,19 @@ 1765, 1766, 1767, + 1768, + 1769, + 1770, 1771, 1773, - 1777, - 1778, + 1774, + 1775, 1779, 1780, 1781, + 1782, + 1783, + 1784, 1789, 1795 ], diff --git a/tests/oo_car/test_coverage_str_helper_oo_car.py b/tests/oo_car/test_coverage_str_helper_oo_car.py index 292d56c..6e329d3 100644 --- a/tests/oo_car/test_coverage_str_helper_oo_car.py +++ b/tests/oo_car/test_coverage_str_helper_oo_car.py @@ -8,9 +8,9 @@ # Now import modules specific to coverage_str_helper: -# In sum, these tests covered 53.12% of coverage_str_helper's lines +# In sum, these tests covered 71.88% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1793', '1761', '1768-1770', '1772', '1774-1775', '1782-1784', '1786-1787', '1790-1791'] +# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -21,10 +21,13 @@ def counter(start=0) -> str: "this_list, non_code_lines, expected_result, args_after", [ ( - [55, 57], - set(), - "['55']", - {"this_list": "[55, 57]", "non_code_lines": "set()"}, + [1702, 1703, 1705, 1706, 1707, 1719, 1720], + {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, + "['1702-1703', '1705-1707', '1719-1720']", + { + "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", + "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", + }, ), ], ids=counter, diff --git a/tests/oo_car/test_update_global_oo_car.py b/tests/oo_car/test_update_global_oo_car.py index 53dfbc4..c8670f5 100644 --- a/tests/oo_car/test_update_global_oo_car.py +++ b/tests/oo_car/test_update_global_oo_car.py @@ -1,3 +1,65 @@ """ -No testable inputs - see accompanying JSON file. -""" \ No newline at end of file +Programmatically generated test function for update_global() +""" + +import pytest +from src import unit_test_generator + +# Now import modules specific to update_global: +from src.unit_test_generator import CoverageInfo + + +# In sum, these tests covered 46.15% of update_global's lines +# Line(s) not covered by ANY of the tests below: +# ['1702-1703', '1705-1707', '1719-1720'] +def counter(start=0) -> str: + while True: + yield f"test#-{start}" + start += 1 + + +@pytest.mark.parametrize( + "obj, this_global, phase, this_coverage_info, expected_result, args_after", + [ + ( + 0, + "method_call_counter", + "Before", + CoverageInfo( + args_before=["-1", "1"], + args_after={}, + kwargs={}, + kwargs_after={}, + globals_before={}, + globals_after={}, + expected_result="", + expected_type="", + coverage=[], + exception_type="", + exception_message="", + constructor='Car("Red", 10, 0)', + cost=0.0, + testable=True, + ), + "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", + { + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" + }, + ), + ], + ids=counter, +) +def test_update_global( + obj, this_global, phase, this_coverage_info, expected_result, args_after +): + """ + Programmatically generated test function for update_global() + """ + result = unit_test_generator.update_global( + obj, this_global, phase, this_coverage_info + ) + assert result == expected_result or result == eval(expected_result) + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) diff --git a/tests/oo_car/update_global.json b/tests/oo_car/update_global.json index f346a1b..7e38e2c 100644 --- a/tests/oo_car/update_global.json +++ b/tests/oo_car/update_global.json @@ -36,34 +36,36 @@ "coverage_io": { "0": { "args_before": [ - "", - "\"logger\"", + "0", + "\"method_call_counter\"", "\"Before\"", "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" ], "args_after": { - "obj": "", - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", + "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ 1701, - 1702, - 1703 + 1704, + 1709, + 1717, + 1718, + 1721 ], "exception_type": "", "exception_message": "", "constructor": "", "cost": 0.0, - "testable": false + "testable": true } }, - "coverage_percentage": 23.08, + "coverage_percentage": 46.15, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -78,8 +80,11 @@ "global_vars_written_to": [], "unified_test_coverage": [ 1701, - 1702, - 1703 + 1704, + 1709, + 1717, + 1718, + 1721 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/add_to_my_set_kwargs.json b/tests/pass_by_assignment/add_to_my_set_kwargs.json index f920c4f..30bbd54 100644 --- a/tests/pass_by_assignment/add_to_my_set_kwargs.json +++ b/tests/pass_by_assignment/add_to_my_set_kwargs.json @@ -4,9 +4,9 @@ "is_method": false, "source_file": null, "lines": [ - 72, - 73, - 72 + 53, + 54, + 53 ], "non_code_lines": [], "coverage_io": { @@ -33,8 +33,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 72, - 73 + 53, + 54 ], "exception_type": "", "exception_message": "", @@ -48,8 +48,8 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 72, - 73 + 53, + 54 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/append_list.json b/tests/pass_by_assignment/append_list.json index 6800c6d..a39e137 100644 --- a/tests/pass_by_assignment/append_list.json +++ b/tests/pass_by_assignment/append_list.json @@ -7,8 +7,8 @@ "is_method": false, "source_file": null, "lines": [ - 44, - 45 + 26, + 27 ], "non_code_lines": [], "coverage_io": { @@ -27,8 +27,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 44, - 45 + 26, + 27 ], "exception_type": "", "exception_message": "", @@ -50,8 +50,8 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 44, - 45 + 26, + 27 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/example_pass_by_assignment.py b/tests/pass_by_assignment/example_pass_by_assignment.py new file mode 100644 index 0000000..e47a411 --- /dev/null +++ b/tests/pass_by_assignment/example_pass_by_assignment.py @@ -0,0 +1,115 @@ +""" +Test case to demonstrate tests for pass by assignment. +""" + +import argparse +import logging +import os +import sys +from pathlib import Path +from typing import TypeVar + +import coverage +from pass_by_assignment import ( + append_list, + overwrite_list, + increment_my_list_kwargs, + add_to_my_set_kwargs +) +from src import unit_test_generator +from src.unit_test_generator import ( + generate_all_tests_and_metadata, + unit_test_generator_decorator, +) + +T = TypeVar('T') + +FMT_STR = "%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s" +logging.basicConfig(level=logging.INFO, format=FMT_STR) +logger = logging.getLogger(__name__) +unit_test_generator.logger.setLevel(logging.CRITICAL) + +def main(): + """ + Execute the functions above. + """ + # Begin ad hoc tests + # Test append_list + + my_list = [1,2,3,4] + append_list(my_list, 6) + overwrite_list(my_list[::-1]) + + kwargs = {"my_list":[0,3]} + print(f"my_list Before increment_my_list_kwargs(): {kwargs=}") + increment_my_list_kwargs(**kwargs) + print(f"After: {kwargs=}") + + + kwargs = {} + kwargs["my_set"] = set([0,2,3]) + print(f"my_set Before: add_to_my_set_kwargs(): {kwargs=}") + + add_to_my_set_kwargs(**kwargs) + print(f"After: {kwargs=}") + + generate_all_tests_and_metadata(Path("."), Path(".")) + +if __name__ == "__main__": + log_levels = { + "critical": logging.CRITICAL, + "error": logging.ERROR, + "warn": logging.WARNING, + "warning": logging.WARNING, + "info": logging.INFO, + "debug": logging.DEBUG, + } + # Create the parser and add argument(s) + parser = argparse.ArgumentParser() + parser.add_argument( + "--log-level", + "-l", + help="log level", + type=str, + choices=log_levels.keys(), + default="info", + ) + parser.add_argument( + "--disable-unit-test-generation", + "-d", + action="store_true", + help="Set this flag to deactivate unit test generation for this code", + ) + args = parser.parse_args() + logger.setLevel(log_levels[args.log_level]) + logger.info("args=%s", args) + + this_file = Path(__file__).absolute() + for file in this_file.parent.rglob("*"): + if file.name == "pass_by_assignment.py": + continue + if file.suffix in (".py", ".json") and file.absolute() != this_file: + logger.debug("Deleting %s to ensure clean start", this_file) + os.remove(file) + + logger.info("%s", __file__) + + + if args.disable_unit_test_generation: + main() + sys.exit(0) + + # The code below applies the CLI arg above to selectively enable/disable + # automatic unit test generation (Could not use the syntactic sugar method + # of applying decorators as the user's input isn't parsed until now.) + # Alternatively, move the argument parsing to the very top of this file. + # NOTE: + # Decorating all functions programmatically is left as an exercise to the reader: + # Hint: https://stackoverflow.com/questions/3467526/ + # get_key_to_set_with_highest_value = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_key_to_set_with_highest_value) # pylint: disable=line-too-long + # get_item_at_index = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_item_at_index) # pylint: disable=line-too-long + + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file diff --git a/tests/pass_by_assignment/increment_my_list_kwargs.json b/tests/pass_by_assignment/increment_my_list_kwargs.json index fe9c4f3..d0df873 100644 --- a/tests/pass_by_assignment/increment_my_list_kwargs.json +++ b/tests/pass_by_assignment/increment_my_list_kwargs.json @@ -4,9 +4,9 @@ "is_method": false, "source_file": null, "lines": [ - 62, - 63, - 62 + 44, + 45, + 44 ], "non_code_lines": [], "coverage_io": { @@ -31,8 +31,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 62, - 63 + 44, + 45 ], "exception_type": "", "exception_message": "", @@ -46,8 +46,8 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 62, - 63 + 44, + 45 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/overwrite_list.json b/tests/pass_by_assignment/overwrite_list.json index c8608ee..fae6bff 100644 --- a/tests/pass_by_assignment/overwrite_list.json +++ b/tests/pass_by_assignment/overwrite_list.json @@ -6,8 +6,8 @@ "is_method": false, "source_file": null, "lines": [ - 53, - 54 + 35, + 36 ], "non_code_lines": [], "coverage_io": { @@ -25,8 +25,8 @@ "expected_result": "None", "expected_type": "NoneType", "coverage": [ - 53, - 54 + 35, + 36 ], "exception_type": "", "exception_message": "", @@ -40,8 +40,8 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 53, - 54 + 35, + 36 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/pass_by_assignment.py b/tests/pass_by_assignment/pass_by_assignment.py index 37d2788..4cd78a9 100644 --- a/tests/pass_by_assignment/pass_by_assignment.py +++ b/tests/pass_by_assignment/pass_by_assignment.py @@ -2,34 +2,16 @@ Test case to demonstrate tests for pass by assignment. """ -import argparse import logging -import os -import sys -from pathlib import Path from typing import Any, List, TypeVar -import coverage - from src import unit_test_generator from src.unit_test_generator import ( - generate_all_tests_and_metadata, unit_test_generator_decorator, ) T = TypeVar('T') - -class ClassForTesting(): - def __init__(self, name): - self.name = name - - def __repr__(self): - return f"ClassForTesting('{self.name}')" - - def __eq__(self, __value: Any) -> bool: - return self.name == __value.name - FMT_STR = "%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s" logging.basicConfig(level=logging.INFO, format=FMT_STR) logger = logging.getLogger(__name__) @@ -61,7 +43,6 @@ def increment_my_list_kwargs(**kwargs): """ if "my_list" in kwargs and isinstance(kwargs["my_list"], list): kwargs["my_list"].append(1) - #kwargs["my_list"].append(ClassForTesting("test")) @unit_test_generator_decorator(sample_count=6, keep_subsets=True, percent_coverage=0) def add_to_my_set_kwargs(**kwargs): @@ -70,88 +51,4 @@ def add_to_my_set_kwargs(**kwargs): append a 1 to it. """ if "my_set" in kwargs and isinstance(kwargs["my_set"], set): - kwargs["my_set"].add(1) - - -def main(): - """ - Execute the functions above. - """ - # Begin ad hoc tests - # Test append_list - - my_list = [1,2,3,4] - append_list(my_list, 6) - overwrite_list(my_list[::-1]) - - kwargs = {"my_list":[0,3]} - print(f"my_list Before increment_my_list_kwargs(): {kwargs=}") - increment_my_list_kwargs(**kwargs) - print(f"After: {kwargs=}") - - - kwargs = {} - kwargs["my_set"] = set([0,2,3]) - print(f"my_set Before: add_to_my_set_kwargs(): {kwargs=}") - - add_to_my_set_kwargs(**kwargs) - print(f"After: {kwargs=}") - - generate_all_tests_and_metadata(Path("."), Path(".")) - -if __name__ == "__main__": - log_levels = { - "critical": logging.CRITICAL, - "error": logging.ERROR, - "warn": logging.WARNING, - "warning": logging.WARNING, - "info": logging.INFO, - "debug": logging.DEBUG, - } - # Create the parser and add argument(s) - parser = argparse.ArgumentParser() - parser.add_argument( - "--log-level", - "-l", - help="log level", - type=str, - choices=log_levels.keys(), - default="info", - ) - parser.add_argument( - "--disable-unit-test-generation", - "-d", - action="store_true", - help="Set this flag to deactivate unit test generation for this code", - ) - args = parser.parse_args() - logger.setLevel(log_levels[args.log_level]) - logger.info("args=%s", args) - - this_file = Path(__file__).absolute() - for file in this_file.parent.rglob("*"): - if file.suffix in (".py", ".json") and file.absolute() != this_file: - logger.debug("Deleting %s to ensure clean start", this_file) - os.remove(file) - - logger.info("%s", __file__) - - - if args.disable_unit_test_generation: - main() - sys.exit(0) - - # The code below applies the CLI arg above to selectively enable/disable - # automatic unit test generation (Could not use the syntactic sugar method - # of applying decorators as the user's input isn't parsed until now.) - # Alternatively, move the argument parsing to the very top of this file. - # NOTE: - # Decorating all functions programmatically is left as an exercise to the reader: - # Hint: https://stackoverflow.com/questions/3467526/ - # get_key_to_set_with_highest_value = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_key_to_set_with_highest_value) # pylint: disable=line-too-long - # get_item_at_index = unit_test_generator_decorator(not args.disable_unit_test_generation)(get_item_at_index) # pylint: disable=line-too-long - - cov = coverage.Coverage() - with cov.collect(): - main() - cov.save() \ No newline at end of file + kwargs["my_set"].add(1) \ No newline at end of file diff --git a/tests/pass_by_assignment/update_global.json b/tests/pass_by_assignment/update_global.json index dc74e0a..4e5b7f6 100644 --- a/tests/pass_by_assignment/update_global.json +++ b/tests/pass_by_assignment/update_global.json @@ -36,13 +36,13 @@ "coverage_io": { "0": { "args_before": [ - "", + "", "\"logger\"", "\"Before\"", "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" ], "args_after": { - "obj": "", + "obj": "", "this_coverage_info": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)" }, "kwargs": {}, diff --git a/tests/procedural_division/divide_ints.json b/tests/procedural_division/divide_ints.json index d02a9e3..69a3319 100644 --- a/tests/procedural_division/divide_ints.json +++ b/tests/procedural_division/divide_ints.json @@ -22,6 +22,37 @@ "non_code_lines": [], "coverage_io": { "0": { + "args_before": [ + "8", + "[]" + ], + "args_after": { + "b": "[]" + }, + "kwargs": {}, + "kwargs_after": {}, + "globals_before": { + "error_code": -1 + }, + "globals_after": { + "error_code": -2 + }, + "expected_result": "None", + "expected_type": "NoneType", + "coverage": [ + 35, + 36, + 39, + 40, + 41 + ], + "exception_type": "", + "exception_message": "TypeError: Variable b=[] is not an int!", + "constructor": "", + "cost": 0.0, + "testable": true + }, + "1": { "args_before": [ "\"10\"", "2" @@ -30,7 +61,7 @@ "kwargs": {}, "kwargs_after": {}, "globals_before": { - "error_code": 0 + "error_code": -3 }, "globals_after": { "error_code": -1 @@ -49,7 +80,7 @@ "cost": 0.0, "testable": true }, - "1": { + "2": { "args_before": [ "3", "0" @@ -79,7 +110,7 @@ "cost": 0.0, "testable": true }, - "2": { + "3": { "args_before": [ "6", "2" @@ -107,37 +138,6 @@ "constructor": "", "cost": 0.0, "testable": true - }, - "3": { - "args_before": [ - "8", - "[]" - ], - "args_after": { - "b": "[]" - }, - "kwargs": {}, - "kwargs_after": {}, - "globals_before": { - "error_code": 0 - }, - "globals_after": { - "error_code": -2 - }, - "expected_result": "None", - "expected_type": "NoneType", - "coverage": [ - 35, - 36, - 39, - 40, - 41 - ], - "exception_type": "", - "exception_message": "TypeError: Variable b=[] is not an int!", - "constructor": "", - "cost": 0.0, - "testable": true } }, "coverage_percentage": 100.0, diff --git a/tests/procedural_division/divide_ints.py b/tests/procedural_division/divide_ints.py index 7ac3d4d..df41959 100644 --- a/tests/procedural_division/divide_ints.py +++ b/tests/procedural_division/divide_ints.py @@ -43,78 +43,3 @@ def divide_ints(a: int, b: int)->str: error_code = -3 raise ValueError("ValueError: Cannot divide by zero!") return f"{a}/{b}={a/b}" - -def main(): - """ - Call division function - """ - start = time.perf_counter() - a_list = [6, 3,"10", 8, [], {}, 4] - b_list = [2, 0, 2, [], 2, 3, set()] - global error_code # pylint: disable=global-statement - for a, b in zip(a_list, b_list): - try: - logger.info("-"*80) - error_code = 0 - try: - logger.info("Trying divide_ints(%s, %s)", repr(a), repr(b)) - except TypeError as e: - logger.info(e) - print(f"divide_ints({a}, {b})={divide_ints(a, b)}") - except (ValueError, TypeError) as e: - logger.error("%s: %s", type(e),str(e)) - logger.info("error_code=%d", error_code) - - generate_all_tests_and_metadata(Path('.'), Path('.')) - print(f"Took {time.perf_counter()-start} seconds") - -if __name__ == "__main__": - - log_levels = { - 'critical': logging.CRITICAL, - 'error': logging.ERROR, - 'warn': logging.WARNING, - 'warning': logging.WARNING, - 'info': logging.INFO, - 'debug': logging.DEBUG - } - - # Create the parser and add argument(s) - parser = argparse.ArgumentParser() - parser.add_argument('--log-level', - "-l", - help='log level', - type=str, - choices=log_levels.keys(), - default='info') - parser.add_argument("--disable-unit-test-generation", "-d", - action="store_true", - help="Set this flag to deactivate unit test generation for this code") - args = parser.parse_args() - print(f"{args=}") - - this_file = Path(__file__).absolute() - for file in this_file.parent.rglob("*"): - if file.suffix in (".py", ".json") and file.absolute() != this_file: - logger.debug("Deleting %s to ensure clean start", this_file) - os.remove(file) - - - if args.disable_unit_test_generation: - main() - sys.exit(0) - - - # The code below applies the CLI arg above to selectively enable/disable - # automatic unit test generation (Could not use the syntactic sugar method - # of applying decorators as the user's input isn't parsed until now.) - # Alternatively, move the argument parsing to the very top of this file. - # NOTE: - # Decorating all functions programmatically is left as an exercise to the reader: - # Hint: https://stackoverflow.com/questions/3467526/ - divide_ints = unit_test_generator_decorator(percent_coverage=110)(divide_ints) - - cov = coverage.Coverage() - with cov.collect(): - main() - cov.save() \ No newline at end of file diff --git a/tests/procedural_division/example_divide_ints.py b/tests/procedural_division/example_divide_ints.py new file mode 100644 index 0000000..d2ca5e4 --- /dev/null +++ b/tests/procedural_division/example_divide_ints.py @@ -0,0 +1,99 @@ +""" +Trivial example to demonstrate DDT concept +""" + +import argparse +import logging +import os +import sys +import time +from pathlib import Path + +import coverage +from divide_ints import divide_ints, error_code +from src import unit_test_generator +from src.unit_test_generator import ( + generate_all_tests_and_metadata, + unit_test_generator_decorator, +) + +FMT_STR = '%(levelname)-8s|%(module)-16s|%(funcName)-20s:%(lineno)-4d:%(message)s' +logging.basicConfig(level=logging.INFO, format=FMT_STR) +logger = logging.getLogger(__name__) +unit_test_generator.logger.setLevel(logging.CRITICAL) + +def main(): + """ + Call division function + """ + start = time.perf_counter() + a_list = [6, 3,"10", 8, [], {}, 4] + b_list = [2, 0, 2, [], 2, 3, set()] + for a, b in zip(a_list, b_list): + try: + logger.info("-"*80) + error_code = 0 + try: + logger.info("Trying divide_ints(%s, %s)", repr(a), repr(b)) + except TypeError as e: + logger.info(e) + print(f"divide_ints({a}, {b})={divide_ints(a, b)}") + except (ValueError, TypeError) as e: + logger.error("%s: %s", type(e),str(e)) + logger.info("error_code=%d", error_code) + + generate_all_tests_and_metadata(Path('.'), Path('.')) + print(f"Took {time.perf_counter()-start} seconds") + +if __name__ == "__main__": + + log_levels = { + 'critical': logging.CRITICAL, + 'error': logging.ERROR, + 'warn': logging.WARNING, + 'warning': logging.WARNING, + 'info': logging.INFO, + 'debug': logging.DEBUG + } + + # Create the parser and add argument(s) + parser = argparse.ArgumentParser() + parser.add_argument('--log-level', + "-l", + help='log level', + type=str, + choices=log_levels.keys(), + default='info') + parser.add_argument("--disable-unit-test-generation", "-d", + action="store_true", + help="Set this flag to deactivate unit test generation for this code") + args = parser.parse_args() + print(f"{args=}") + + this_file = Path(__file__).absolute() + for file in this_file.parent.rglob("*"): + if file.name == "divide_ints.py": + continue + if file.suffix in (".py", ".json") and file.absolute() != this_file: + logger.debug("Deleting %s to ensure clean start", this_file) + os.remove(file) + + + if args.disable_unit_test_generation: + main() + sys.exit(0) + + + # The code below applies the CLI arg above to selectively enable/disable + # automatic unit test generation (Could not use the syntactic sugar method + # of applying decorators as the user's input isn't parsed until now.) + # Alternatively, move the argument parsing to the very top of this file. + # NOTE: + # Decorating all functions programmatically is left as an exercise to the reader: + # Hint: https://stackoverflow.com/questions/3467526/ + divide_ints = unit_test_generator_decorator(percent_coverage=110)(divide_ints) + + cov = coverage.Coverage() + with cov.collect(): + main() + cov.save() \ No newline at end of file diff --git a/tests/procedural_division/test_divide_ints.py b/tests/procedural_division/test_divide_ints.py index 1415e95..48a7f2c 100644 --- a/tests/procedural_division/test_divide_ints.py +++ b/tests/procedural_division/test_divide_ints.py @@ -4,13 +4,11 @@ import re import pytest -from tests.procedural_division import divide_ints +import divide_ints from _pytest.monkeypatch import MonkeyPatch # Now import modules specific to divide_ints: -ERROR_CODE = 0 - # In sum, these tests covered 100.0% of divide_ints's lines def counter(start=0) -> str: @@ -20,8 +18,18 @@ def counter(start=0) -> str: @pytest.mark.parametrize( - "a, b, exception_type, exception_message, expected_result, args_after, globals_after", + "a, b, exception_type, exception_message, expected_result, args_after, globals_before, globals_after", [ + ( + 8, + [], + TypeError, + "TypeError: Variable b=[] is not an int!", + "None", + {"b": "[]"}, + {"error_code": -1}, + {"error_code": -2}, + ), ( "10", 2, @@ -29,6 +37,7 @@ def counter(start=0) -> str: "TypeError: Variable a='10' is not an int!", "None", {}, + {"error_code": -3}, {"error_code": -1}, ), ( @@ -38,35 +47,36 @@ def counter(start=0) -> str: "ValueError: Cannot divide by zero!", "None", {}, + {"error_code": 0}, {"error_code": -3}, ), - (6, 2, "N/A", "N/A", "6/2=3.0", {}, {"error_code": 0}), - ( - 8, - [], - TypeError, - "TypeError: Variable b=[] is not an int!", - "None", - {"b": "[]"}, - {"error_code": -2}, - ), + (6, 2, "N/A", "N/A", "6/2=3.0", {}, {"error_code": 0}, {"error_code": 0}), ], ids=counter, ) def test_divide_ints( - a, b, exception_type, exception_message, expected_result, args_after, globals_after + a, + b, + exception_type, + exception_message, + expected_result, + args_after, + globals_before, + globals_after, ): """ Programmatically generated test function for divide_ints() """ monkeypatch = MonkeyPatch() - monkeypatch.setattr(divide_ints, "error_code", ERROR_CODE) + for k, v in globals_before.items(): + monkeypatch.setattr(divide_ints, k, v) if exception_type != "N/A": with pytest.raises(exception_type, match=re.escape(exception_message)): divide_ints.divide_ints(a, b) else: result = divide_ints.divide_ints(a, b) assert result == expected_result or result == eval(expected_result) + assert b == eval(args_after["b"]) or args_after["b"] == b for global_var_written_to in ["error_code"]: if global_var_written_to in ["None", "[]", "{}"]: assert not divide_ints.__dict__.get(global_var_written_to) diff --git a/tests/test_all_keep_files.bat b/tests/test_all_keep_files.bat index 40917a5..92e1026 100644 --- a/tests/test_all_keep_files.bat +++ b/tests/test_all_keep_files.bat @@ -1,5 +1,5 @@ cd fizzbuzz -python fizzbuzz.py >NUL 2>NUL +python example_fizzbuzz.py >NUL 2>NUL pytest -s -vv . cd .. @@ -9,7 +9,7 @@ pytest -s -vv . cd .. cd procedural_division -python divide_ints.py >NUL 2>NUL +python example_divide_ints.py >NUL 2>NUL pytest -s -vv . cd .. @@ -19,6 +19,6 @@ pytest -s -vv . cd .. cd pass_by_assignment -python pass_by_assignment.py >NUL 2>NUL +python example_pass_by_assignment.py >NUL 2>NUL pytest -s -vv . cd .. \ No newline at end of file diff --git a/tests/test_all_keep_files_keep_output.bat b/tests/test_all_keep_files_keep_output.bat index ee33cb2..4210ea7 100644 --- a/tests/test_all_keep_files_keep_output.bat +++ b/tests/test_all_keep_files_keep_output.bat @@ -1,7 +1,8 @@ cd fizzbuzz -python fizzbuzz.py +python example_fizzbuzz.py coverage run -m pytest ::pytest -s -vv . +timeout 1 cd .. cd all_types @@ -11,7 +12,7 @@ coverage run -m pytest cd .. cd procedural_division -python divide_ints.py +python example_divide_ints.py coverage run -m pytest ::pytest -s -vv . cd .. @@ -23,8 +24,8 @@ coverage run -m pytest cd .. cd pass_by_assignment -python pass_by_assignment.py -pytest -s -vv . +python example_pass_by_assignment.py +coverage run -m pytest cd .. cd ..\src @@ -32,6 +33,8 @@ cd ..\src coverage run -m pytest cd .. -coverage combine tests\fizzbuzz\.coverage tests\oo_car\.coverage tests\all_types\.coverage tests\all_types\.coverage tests\procedural_division\.coverage src\.coverage +: Give time for .coverage files to hit disk + +coverage combine --keep tests\fizzbuzz\.coverage tests\oo_car\.coverage tests\all_types\.coverage tests\pass_by_assignment\.coverage tests\procedural_division\.coverage src\.coverage coverage report -m coverage html \ No newline at end of file From 7631fbad00229ea0e4bad8acd3ed7b964a502213 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 14 Nov 2025 00:39:46 -0500 Subject: [PATCH 160/165] Update python-app-ubuntu.yml Examples --- .github/workflows/python-app-ubuntu.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index c87e71b..bdc1ba1 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -121,10 +121,10 @@ jobs: # continue-on-error: true run: | cd tests/procedural_division - echo "divide_ints.py -d runtime:" - time poetry run python divide_ints.py -d - echo "divide_ints.py runtime:" - time poetry run python divide_ints.py + echo "example_divide_ints.py -d runtime:" + time poetry run python example_divide_ints.py -d + echo "example_divide_ints.py runtime:" + time poetry run python example_divide_ints.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest fizzbuzz @@ -133,10 +133,10 @@ jobs: # continue-on-error: true run: | cd tests/fizzbuzz - echo "fizzbuzz.py -d runtime:" - time poetry run python fizzbuzz.py -d - echo "fizzbuzz.py runtime:" - time poetry run python fizzbuzz.py + echo "example_fizzbuzz.py -d runtime:" + time poetry run python example_fizzbuzz.py -d + echo "example_fizzbuzz.py runtime:" + time poetry run python example_fizzbuzz.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest all_types @@ -170,10 +170,10 @@ jobs: # continue-on-error: true run: | cd tests/pass_by_assignment - echo "pass_by_assignment -d runtime:" - time poetry run python pass_by_assignment.py - echo "pass_by_assignment runtime:" - poetry run python pass_by_assignment.py + echo "example_pass_by_assignment.py -d runtime:" + time poetry run python example_pass_by_assignment.py + echo "example_pass_by_assignment.py runtime:" + poetry run python example_pass_by_assignment.py #poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html From 52ea588cca12b1bc42d41d3c5c8717aa133db49e Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 09:36:37 -0500 Subject: [PATCH 161/165] This should fix the args_after bug --- src/unit_test_generator.py | 50 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/unit_test_generator.py b/src/unit_test_generator.py index 8861e23..320d6b2 100644 --- a/src/unit_test_generator.py +++ b/src/unit_test_generator.py @@ -340,7 +340,44 @@ def get_all_uncovered_line_str(self): return result def __str__(self)->str: - return f"{self.name}:\n{self.lines=}\n" + """ name:str, + parameter_names:List[str], + is_method:bool, + source_file:Path, + lines:Optional[List[int]] = None, + non_code_lines:Optional[Set[int]] = None, + global_vars_read_from:Optional[set] = None, + global_vars_written_to:Optional[set] = None, + coverage_io:Optional[dict[str, CoverageInfo]] = None, + coverage_percentage:float=0.0, + types_in_use:Optional[set] = None, + unified_test_coverage:Optional[set] = None, + needs_pytest:bool = False, + exceptions_raised:Optional[set] = None, + callable_files: Optional[dict[str, str]] = None + + Returns: + str: _description_ + """ + result = ["FunctionMetaData("] + result.append("name="+repr(self.name)) + result.append(" parameter_names="+repr(self.parameter_names)) + result.append(" is_method="+repr(self.is_method)) + result.append(" source_file="+repr(self.source_file)) + result.append(" lines="+repr(self.lines)) + result.append(" non_code_lines="+repr(self.non_code_lines)) + result.append(" global_vars_read_from="+repr(self.global_vars_read_from)) + result.append(" global_vars_written_to="+repr(self.global_vars_written_to)) + result.append(" coverage_io="+repr(self.coverage_io)) + result.append(" coverage_percentage="+repr(self.coverage_percentage)) + result.append(" types_in_use="+repr(self.types_in_use)) + result.append(" unified_test_coverage="+repr(self.unified_test_coverage)) + result.append(" needs_pytest="+repr(self.needs_pytest)) + result.append(" exceptions_raised="+repr(self.exceptions_raised)) + result.append(" callable_files="+repr(self.callable_files)) + result_str = ','.join(result) + logger.debug("result=%s", result_str) + return result_str def return_non_code_lines(self)->Set[int]: """ @@ -1257,6 +1294,7 @@ def do_the_decorator_thing(func: Callable, function_name:str, end_time = time.perf_counter() with Capturing() as stdout_lines: cov.json_report(outfile='-') + # result will not exist if the function threw an exception cov_report_ = json.loads(stdout_lines[0]) expected_type = str(type(result)) @@ -1963,10 +2001,18 @@ def meta_program_function_call( this_state:CoverageInfo, #indent += tab line = f"{indent}assert result == expected_result or result == eval(expected_result)\n" list_of_lines.append(line) + try: + if isinstance(this_state, OrderedDict) and 'this_coverage_info' in this_state.args_after: + this_state.args_after['this_coverage_info']['args_after'] + except KeyError as e: + logger.warning(e) # TODO Why is this_state.args_after sometimes a tuple?? if isinstance(this_state.args_after, dict) and this_state.args_after.keys(): + list_of_lines.append(f"{indent}try:\n") for arg_after in this_state.args_after.keys(): - list_of_lines.append(f"{indent}assert {arg_after} == eval(args_after[\"{arg_after}\"]) or args_after[\"{arg_after}\"] == {arg_after}\n") + list_of_lines.append(f"{indent*2}assert {arg_after} == eval(args_after[\"{arg_after}\"]) or args_after[\"{arg_after}\"] == {arg_after}\n") + list_of_lines.append(f"{indent}except KeyError as e:\n") + list_of_lines.append(f"{indent*2}print(f\"Got Key Error in test, likely false positive: {{e=}}\")\n") if isinstance(this_state.kwargs_after, dict) and this_state.kwargs_after.keys(): for arg_after in this_state.kwargs_after.keys(): list_of_lines.append(f"{indent}kwargs[\"{arg_after}\"] == kwargs_after['{arg_after}']\n") From 083c2280c5134352a5728f48f62e4b0eb53431c2 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 09:38:32 -0500 Subject: [PATCH 162/165] Results of fixing the args_after bug --- .../coverage_str_helper.json | 176 +++++++++--------- tests/procedural_division/normalize_arg.json | 46 ++--- ...coverage_str_helper_procedural_division.py | 31 +-- tests/procedural_division/test_divide_ints.py | 5 +- .../test_normalize_arg_procedural_division.py | 2 +- .../test_update_global_procedural_division.py | 13 +- tests/procedural_division/update_global.json | 66 +++---- 7 files changed, 174 insertions(+), 165 deletions(-) diff --git a/tests/procedural_division/coverage_str_helper.json b/tests/procedural_division/coverage_str_helper.json index d66660a..7385c93 100644 --- a/tests/procedural_division/coverage_str_helper.json +++ b/tests/procedural_division/coverage_str_helper.json @@ -7,86 +7,86 @@ "is_method": false, "source_file": null, "lines": [ - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1774, - 1775, - 1777, - 1778, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1786, - 1787, - 1789, - 1790, - 1791, - 1793, - 1795 + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1814, + 1815, + 1816, + 1817, + 1818, + 1819, + 1820, + 1822, + 1823, + 1824, + 1825, + 1826, + 1827, + 1828, + 1829, + 1831, + 1832, + 1834, + 1835, + 1836, + 1838, + 1840 ], "non_code_lines": [ - 1776, - 1785, - 1788, - 1792, - 1794 + 1821, + 1830, + 1833, + 1837, + 1839 ], "coverage_io": { "0": { "args_before": [ - "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", + "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}" ], "args_after": { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "this_list": "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", + "non_code_lines": "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['1702-1703', '1705-1707', '1719-1720']", + "expected_result": "['1764-1765', '1747-1748', '1750-1752']", "expected_type": "list", "coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1804, + 1805, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1814, + 1815, + 1816, + 1818, + 1819, + 1820, + 1824, + 1825, + 1826, + 1827, + 1828, + 1829, + 1834, + 1840 ], "exception_type": "", "exception_message": "", @@ -108,29 +108,29 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1804, + 1805, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1814, + 1815, + 1816, + 1818, + 1819, + 1820, + 1824, + 1825, + 1826, + 1827, + 1828, + 1829, + 1834, + 1840 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/normalize_arg.json b/tests/procedural_division/normalize_arg.json index ae162e9..fd8e60e 100644 --- a/tests/procedural_division/normalize_arg.json +++ b/tests/procedural_division/normalize_arg.json @@ -6,19 +6,19 @@ "is_method": false, "source_file": null, "lines": [ - 1729, - 1730, - 1731, - 1732, - 1733, - 1734, - 1736, - 1737, - 1738, - 1739 + 1774, + 1775, + 1776, + 1777, + 1778, + 1779, + 1781, + 1782, + 1783, + 1784 ], "non_code_lines": [ - 1735 + 1780 ], "coverage_io": { "0": { @@ -33,12 +33,12 @@ "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "str", "coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1774, + 1775, + 1776, + 1778, + 1781, + 1784 ], "exception_type": "", "exception_message": "", @@ -52,12 +52,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1774, + 1775, + 1776, + 1778, + 1781, + 1784 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/test_coverage_str_helper_procedural_division.py b/tests/procedural_division/test_coverage_str_helper_procedural_division.py index 6e329d3..1aac2df 100644 --- a/tests/procedural_division/test_coverage_str_helper_procedural_division.py +++ b/tests/procedural_division/test_coverage_str_helper_procedural_division.py @@ -10,7 +10,7 @@ # In sum, these tests covered 71.88% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] +# ['1806', '1817', '1822-1823', '1831-1832', '1835-1836'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -21,12 +21,12 @@ def counter(start=0) -> str: "this_list, non_code_lines, expected_result, args_after", [ ( - [1702, 1703, 1705, 1706, 1707, 1719, 1720], - {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, - "['1702-1703', '1705-1707', '1719-1720']", + [1764, 1765, 1747, 1748, 1750, 1751, 1752], + {1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}, + "['1764-1765', '1747-1748', '1750-1752']", { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", + "this_list": "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", + "non_code_lines": "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}", }, ), ], @@ -38,11 +38,14 @@ def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_af """ result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/procedural_division/test_divide_ints.py b/tests/procedural_division/test_divide_ints.py index 48a7f2c..37cc45c 100644 --- a/tests/procedural_division/test_divide_ints.py +++ b/tests/procedural_division/test_divide_ints.py @@ -76,7 +76,10 @@ def test_divide_ints( else: result = divide_ints.divide_ints(a, b) assert result == expected_result or result == eval(expected_result) - assert b == eval(args_after["b"]) or args_after["b"] == b + try: + assert b == eval(args_after["b"]) or args_after["b"] == b + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") for global_var_written_to in ["error_code"]: if global_var_written_to in ["None", "[]", "{}"]: assert not divide_ints.__dict__.get(global_var_written_to) diff --git a/tests/procedural_division/test_normalize_arg_procedural_division.py b/tests/procedural_division/test_normalize_arg_procedural_division.py index fcc0228..f2e826e 100644 --- a/tests/procedural_division/test_normalize_arg_procedural_division.py +++ b/tests/procedural_division/test_normalize_arg_procedural_division.py @@ -8,7 +8,7 @@ # In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1732', '1734', '1737-1738'] +# ['1777', '1779', '1782-1783'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/procedural_division/test_update_global_procedural_division.py b/tests/procedural_division/test_update_global_procedural_division.py index b04d224..252017b 100644 --- a/tests/procedural_division/test_update_global_procedural_division.py +++ b/tests/procedural_division/test_update_global_procedural_division.py @@ -11,7 +11,7 @@ # In sum, these tests covered 46.15% of update_global's lines # Line(s) not covered by ANY of the tests below: -# ['1702-1703', '1705-1707', '1719-1720'] +# ['1764-1765', '1747-1748', '1750-1752'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -59,7 +59,10 @@ def test_update_global( obj, this_global, phase, this_coverage_info ) assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) + try: + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/procedural_division/update_global.json b/tests/procedural_division/update_global.json index 417452e..72d0b11 100644 --- a/tests/procedural_division/update_global.json +++ b/tests/procedural_division/update_global.json @@ -9,29 +9,29 @@ "is_method": false, "source_file": null, "lines": [ - 1701, - 1702, - 1703, - 1704, - 1705, - 1706, - 1707, - 1709, - 1717, - 1718, - 1719, - 1720, - 1721 + 1746, + 1747, + 1748, + 1749, + 1750, + 1751, + 1752, + 1754, + 1762, + 1763, + 1764, + 1765, + 1766 ], "non_code_lines": [ - 1708, - 1710, - 1711, - 1712, - 1713, - 1714, - 1715, - 1716 + 1753, + 1755, + 1756, + 1757, + 1758, + 1759, + 1760, + 1761 ], "coverage_io": { "0": { @@ -51,12 +51,12 @@ "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1746, + 1749, + 1754, + 1762, + 1763, + 1766 ], "exception_type": "", "exception_message": "", @@ -79,12 +79,12 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1746, + 1749, + 1754, + 1762, + 1763, + 1766 ], "needs_pytest": false, "exceptions_raised": [], From 00d2b1c925794eade4f3e7c8ca6a0e6d082e103d Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 10:42:02 -0500 Subject: [PATCH 163/165] Removed auto_test_generation test --- src/test_auto_generate_tests copy.py | 666 ------------------ tests/all_types/coverage_str_helper.json | 122 ++-- .../test_coverage_str_helper_all_types.py | 21 +- tests/all_types/test_get_item_at_index.py | 2 +- tests/all_types/update_global.json | 54 +- tests/fizzbuzz/coverage_str_helper.json | 176 ++--- tests/fizzbuzz/normalize_arg.json | 46 +- .../test_coverage_str_helper_fizzbuzz.py | 31 +- tests/fizzbuzz/test_fizzbuzz.py | 2 +- tests/fizzbuzz/test_normalize_arg_fizzbuzz.py | 2 +- tests/fizzbuzz/test_update_global_fizzbuzz.py | 13 +- tests/fizzbuzz/update_global.json | 66 +- tests/oo_car/coverage_str_helper.json | 166 ++--- tests/oo_car/normalize_arg.json | 46 +- tests/oo_car/test_car_is_going_faster_than.py | 11 +- .../oo_car/test_coverage_str_helper_oo_car.py | 34 +- tests/oo_car/test_normalize_arg_oo_car.py | 2 +- tests/oo_car/test_update_global_oo_car.py | 66 +- tests/oo_car/update_global.json | 73 +- tests/pass_by_assignment/normalize_arg.json | 46 +- tests/pass_by_assignment/test_append_list.py | 11 +- .../test_normalize_arg_pass_by_assignment.py | 2 +- .../pass_by_assignment/test_overwrite_list.py | 11 +- tests/pass_by_assignment/update_global.json | 54 +- .../coverage_str_helper.json | 80 +-- tests/procedural_division/normalize_arg.json | 36 +- ...coverage_str_helper_procedural_division.py | 12 +- .../test_normalize_arg_procedural_division.py | 2 +- .../test_update_global_procedural_division.py | 2 +- tests/procedural_division/update_global.json | 56 +- 30 files changed, 592 insertions(+), 1319 deletions(-) delete mode 100644 src/test_auto_generate_tests copy.py diff --git a/src/test_auto_generate_tests copy.py b/src/test_auto_generate_tests copy.py deleted file mode 100644 index 385dcbe..0000000 --- a/src/test_auto_generate_tests copy.py +++ /dev/null @@ -1,666 +0,0 @@ -""" -Programmatically generated test function for auto_generate_tests() -""" - -import re -import pytest -from src import unit_test_generator -from _pytest.monkeypatch import MonkeyPatch - -# Now import modules specific to auto_generate_tests: -from _io import TextIOWrapper -from logging import PlaceHolder -from logging import StreamHandler -from src.unit_test_generator import FunctionMetaData -from logging import Manager -from src.unit_test_generator import CoverageInfo -from pprint import PrettyPrinter -from collections import OrderedDict -from collections import defaultdict -from logging import RootLogger -from logging import Logger -from pathlib import Path - -ALL_METADATA = defaultdict( - FunctionMetaData, - { - "update_global": FunctionMetaData( - name="update_global", - parameter_names=["obj", "this_global", "phase", "this_coverage_info"], - is_method=False, - lines=[ - 1599, - 1600, - 1601, - 1602, - 1603, - 1604, - 1605, - 1607, - 1615, - 1616, - 1617, - 1618, - 1619, - ], - non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, - global_vars_read_from={"logger"}, - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" - ), - coverage_io={ - "bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9": CoverageInfo( - args_before=[ - "0", - '"method_call_counter"', - '"Before"', - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ], - args_after=OrderedDict( - [ - ( - "this_coverage_info", - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ) - ] - ), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - expected_type="src.unit_test_generator.CoverageInfo", - coverage=[1599, 1602, 1607, 1615, 1616, 1619], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - ) - }, - coverage_percentage=46.15, - types_in_use={ - "logging.Manager", - "logging.StreamHandler", - "logging.Logger", - "logging.RootLogger", - "src.unit_test_generator.CoverageInfo", - "logging.PlaceHolder", - }, - unified_test_coverage={1602, 1607, 1615, 1616, 1619, 1599}, - needs_pytest=False, - callable_files={ - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - }, - ), - "update_metadata": FunctionMetaData( - name="update_metadata", - parameter_names=["f", "this_metadata"], - is_method=False, - lines=[ - 1423, - 1424, - 1425, - 1427, - 1428, - 1429, - 1430, - 1431, - 1432, - 1433, - 1435, - 1436, - 1437, - 1438, - 1439, - 1440, - 1441, - 1442, - 1443, - 1445, - 1447, - 1448, - 1449, - 1450, - 1451, - 1452, - 1453, - 1454, - 1452, - 1447, - 1455, - 1456, - 1457, - 1458, - 1459, - 1460, - 1461, - 1462, - 1461, - ], - non_code_lines={1426, 1444, 1446, 1434}, - global_vars_read_from={"logger"}, - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" - ), - coverage_io={ - "a957a0aed8423c01c38d1111e384806112a73d4876a082ea2ca1421a6a95602a": CoverageInfo( - args_before=[ - 'X', - "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={})", - ], - args_after=OrderedDict( - [ - ( - "this_metadata", - "FunctionMetaData(name='Car.__init__', parameter_names=['self', 'color', 'speed', 'steer_angle'], is_method=True, lines=[41, 42, 43], non_code_lines=set(), global_vars_read_from=set(), global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py'), coverage_io={}, coverage_percentage=0.0, types_in_use=set(), unified_test_coverage=set(), needs_pytest=False, callable_files={'__init__': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\tests\\\\oo_car\\\\car.py'})", - ) - ] - ), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="None", - expected_type="NoneType", - coverage=[ - 1423, - 1425, - 1427, - 1428, - 1429, - 1430, - 1431, - 1432, - 1433, - 1435, - 1437, - 1438, - 1439, - 1440, - 1441, - 1447, - 1455, - 1456, - 1457, - 1458, - 1459, - 1460, - ], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - ) - }, - coverage_percentage=56.41, - types_in_use={ - "logging.Manager", - "pathlib.Path", - "logging.Logger", - "logging.StreamHandler", - "src.unit_test_generator.FunctionMetaData", - "logging.RootLogger", - "car.Car", - "logging.PlaceHolder", - }, - unified_test_coverage={ - 1423, - 1425, - 1427, - 1428, - 1429, - 1430, - 1431, - 1432, - 1433, - 1435, - 1437, - 1438, - 1439, - 1440, - 1441, - 1447, - 1455, - 1456, - 1457, - 1458, - 1459, - 1460, - }, - needs_pytest=False, - callable_files={ - "update_metadata": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - }, - ), - "Car.__init__": FunctionMetaData( - name="Car.__init__", - parameter_names=["self", "color", "speed", "steer_angle"], - is_method=True, - lines=[41, 42, 43], - non_code_lines=set(), - global_vars_read_from=set(), - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" - ), - coverage_io={ - "c878113de933bc35ec08d5024d0aae800d76ba42b32be7f1075b8a7586805a2c": CoverageInfo( - args_before=['"Red"', "10", "0"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="None", - expected_type="NoneType", - coverage=[41, 42, 43], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - ) - }, - coverage_percentage=100.0, - types_in_use=set(), - unified_test_coverage={41, 42, 43}, - needs_pytest=False, - callable_files={ - "__init__": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - }, - ), - "Car.gas": FunctionMetaData( - name="Car.gas", - parameter_names=["self", "rate", "duration"], - is_method=True, - lines=[66, 67, 68, 69, 70, 71], - non_code_lines=set(), - global_vars_read_from={"method_call_counter", "logger"}, - global_vars_written_to={"method_call_counter"}, - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" - ), - coverage_io={ - "78e4f6e57c2f532c43747e020340acf548111ebba3a4dfbb9b7a12af2d0fa659": CoverageInfo( - args_before=["-1", "1"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={"method_call_counter": 0}, - globals_after={"method_call_counter": 1}, - expected_result="None", - expected_type="NoneType", - coverage=[66, 67, 68, 69], - exception_type="", - exception_message="Gas rate (m/s) must be positive.", - constructor='Car("Red", 10, 0)', - cost=0.0, - ), - "6489cc7d9835b1fc422a9e25a2d99a7374cf0a90d0450a9435df3167635e432a": CoverageInfo( - args_before=["2", "2"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={"method_call_counter": 1}, - globals_after={"method_call_counter": 2}, - expected_result="16", - expected_type="int", - coverage=[66, 67, 68, 70, 71], - exception_type="", - exception_message="", - constructor='Car("White", 12, -30)', - cost=0.0, - ), - }, - coverage_percentage=100.0, - types_in_use={ - "tests.oo_car.car.Car", - "logging.Manager", - "logging.StreamHandler", - "logging.Logger", - "logging.RootLogger", - "logging.PlaceHolder", - }, - unified_test_coverage={66, 67, 68, 69, 70, 71}, - needs_pytest=True, - callable_files={ - "gas": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - }, - ), - "Car.brake": FunctionMetaData( - name="Car.brake", - parameter_names=["self", "rate", "duration"], - is_method=True, - lines=[50, 51, 52, 53, 54, 55, 56], - non_code_lines=set(), - global_vars_read_from={"logger"}, - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" - ), - coverage_io={ - "79d14ba2847338fe6989a7d3640887679f88b2cfadee250647df044fe4abc0b9": CoverageInfo( - args_before=["-1", "1"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="9", - expected_type="int", - coverage=[50, 51, 53, 55, 56], - exception_type="", - exception_message="", - constructor='Car("Red", 10, 0)', - cost=0.0, - ) - }, - coverage_percentage=71.43, - types_in_use={ - "tests.oo_car.car.Car", - "logging.Manager", - "logging.StreamHandler", - "logging.Logger", - "logging.RootLogger", - "logging.PlaceHolder", - }, - unified_test_coverage={50, 51, 53, 55, 56}, - needs_pytest=False, - callable_files={ - "brake": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - }, - ), - "Car.change_steer_angle": FunctionMetaData( - name="Car.change_steer_angle", - parameter_names=["self", "angle"], - is_method=True, - lines=[79, 80, 81, 83, 86, 87, 86, 88, 86, 90], - non_code_lines={89, 82, 84, 85}, - global_vars_read_from={"logger"}, - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" - ), - coverage_io={ - "9e5729283fb4205cc004e81e18786a627d2eb0f21140111b0a77b56ac7ded037": CoverageInfo( - args_before=["30"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="30", - expected_type="int", - coverage=[79, 80, 83, 86, 90], - exception_type="", - exception_message="", - constructor='Car("Red", 9, 0)', - cost=0.0, - ), - "78fd5f6e8e8bd7118d1ec9602907dd07a7495e42f6814cd047a8057a96388cd7": CoverageInfo( - args_before=["90"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="60", - expected_type="int", - coverage=[79, 80, 83, 86, 90], - exception_type="", - exception_message="", - constructor='Car("White", 20, -30)', - cost=0.0, - ), - "4e6967deeb4e51bab447208d79037a8bca61cdf648fb62d21885290b177313f6": CoverageInfo( - args_before=["180"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="210", - expected_type="int", - coverage=[79, 80, 83, 86, 90], - exception_type="", - exception_message="", - constructor='Car("Blue", 0.0, 30)', - cost=0.0, - ), - "9da25bda4c0856a5b359c8df1d926a3ed762a3d8f6f58108d234a201cb75d875": CoverageInfo( - args_before=["-1080"], - args_after=OrderedDict(), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="None", - expected_type="NoneType", - coverage=[79, 80, 81], - exception_type="", - exception_message="angle=-1080 out of bounds!", - constructor='Car("Green", 48, 90)', - cost=0.0, - ), - }, - coverage_percentage=60.0, - types_in_use={ - "tests.oo_car.car.Car", - "logging.Manager", - "logging.StreamHandler", - "logging.Logger", - "logging.RootLogger", - "logging.PlaceHolder", - }, - unified_test_coverage={79, 80, 81, 83, 86, 90}, - needs_pytest=True, - callable_files={ - "change_steer_angle": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - }, - ), - "Car.is_going_faster_than": FunctionMetaData( - name="Car.is_going_faster_than", - parameter_names=["self", "other_car"], - is_method=True, - lines=[126], - non_code_lines=set(), - global_vars_read_from=set(), - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/tests/oo_car/car.py" - ), - coverage_io={ - "797ee52405b6b24f04cee9d62d992fd2a5592ed30653401b854ee509666247fc": CoverageInfo( - args_before=['Car("White", 19, 0)'], - args_after=OrderedDict([("other_car", 'Car("White", 19, 0)')]), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="True", - expected_type="bool", - coverage=[126], - exception_type="", - exception_message="", - constructor='Car("Red", 20, 0)', - cost=0.0, - ) - }, - coverage_percentage=100.0, - types_in_use={"__main__.Car", "tests.oo_car.car.Car"}, - unified_test_coverage={126}, - needs_pytest=False, - callable_files={ - "is_going_faster_than": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\tests\\oo_car\\car.py" - }, - ), - }, -) - - -# In sum, these tests covered 49.4% of auto_generate_tests's lines -# Line(s) not covered by ANY of the tests below: -# ['2048-2049', '2051-2052', '2054', '2056-2057', '2059-2061', '2063', '2068', '2070', '2074', '2086-2087', '2091-2094', '2096', '2098', '2104-2110', '2121', '2125', '2127-2128', '2130-2135', '2137', '2139-2140', '2142-2144', '2147', '2149', '2154', '2156', '2158-2159', '2163-2165', '2169-2180', '2190', '2194', '2209', '2219-2220', '2222', '2227-2228', '2230-2231', '2251-2253', '2271-2272', '2274-2279', '2285-2286', '2288-2293', '1899', '1918-1923', '1925-1926', '1928-1929', '1939-1942', '1944-1949', '1951-1953', '1963-1964', '1977-1978', '1980', '1998', '2002-2003', '2005-2006', '2012-2013', '2015-2016', '2018-2019', '2026', '2029-2030', '2037', '2041-2047'] -@pytest.mark.parametrize( - "function_metadata, state, function_name, source_file, tests_dir, outdir, indent_size, expected_result, args_after, globals_before", - [ - ( - FunctionMetaData( - name="update_global", - parameter_names=["obj", "this_global", "phase", "this_coverage_info"], - is_method=False, - lines=[ - 1599, - 1600, - 1601, - 1602, - 1603, - 1604, - 1605, - 1607, - 1615, - 1616, - 1617, - 1618, - 1619, - ], - non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, - global_vars_read_from={"logger"}, - global_vars_written_to=set(), - source_file=Path( - "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" - ), - coverage_io={ - "bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9": CoverageInfo( - args_before=[ - "0", - '"method_call_counter"', - '"Before"', - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ], - args_after=OrderedDict( - [ - ( - "this_coverage_info", - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ) - ] - ), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - expected_type="src.unit_test_generator.CoverageInfo", - coverage=[1599, 1602, 1607, 1615, 1616, 1619], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - ) - }, - coverage_percentage=46.15, - types_in_use={ - "logging.Manager", - "logging.RootLogger", - "logging.StreamHandler", - "logging.Logger", - "src.unit_test_generator.CoverageInfo", - "logging.PlaceHolder", - }, - unified_test_coverage={1602, 1607, 1615, 1616, 1619, 1599}, - needs_pytest=False, - callable_files={ - "update_global": "C:\\Users\\James\\Documents\\CyberResources\\ddt\\src\\unit_test_generator.py" - }, - ), - { - "bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9": CoverageInfo( - args_before=[ - "0", - '"method_call_counter"', - '"Before"', - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ], - args_after=OrderedDict( - [ - ( - "this_coverage_info", - "CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - ) - ] - ), - kwargs={}, - kwargs_after=OrderedDict(), - globals_before={}, - globals_after={}, - expected_result="CoverageInfo(args_before=['-1', '1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0)", - expected_type="src.unit_test_generator.CoverageInfo", - coverage=[1599, 1602, 1607, 1615, 1616, 1619], - exception_type="", - exception_message="", - constructor="", - cost=0.0, - ) - }, - "update_global", - Path( - "C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py" - ), - Path("."), - Path("."), - 2, - "252acc6c11e8af0020608482027ff01a094facec4dddd6c5b97a134d630b6692", - { - "function_metadata": "FunctionMetaData(name='update_global', parameter_names=['obj', 'this_global', 'phase', 'this_coverage_info'], is_method=False, lines=[1599, 1600, 1601, 1602, 1603, 1604, 1605, 1607, 1615, 1616, 1617, 1618, 1619], non_code_lines={1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614}, global_vars_read_from={'logger'}, global_vars_written_to=set(), source_file=Path('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py'), coverage_io={'bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9': CoverageInfo(args_before=['0', '\"method_call_counter\"', '\"Before\"', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'], args_after=OrderedDict([('this_coverage_info', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)')]), kwargs={}, kwargs_after=OrderedDict(), globals_before={}, globals_after={}, expected_result='CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)', expected_type='src.unit_test_generator.CoverageInfo', coverage=[1599, 1602, 1607, 1615, 1616, 1619], exception_type='', exception_message='', constructor='', cost=0.0)}, coverage_percentage=46.15, types_in_use={'logging.Manager', 'logging.RootLogger', 'logging.StreamHandler', 'logging.Logger', 'src.unit_test_generator.CoverageInfo', 'logging.PlaceHolder'}, unified_test_coverage={1602, 1607, 1615, 1616, 1619, 1599}, needs_pytest=False, callable_files={'update_global': 'C:\\\\Users\\\\James\\\\Documents\\\\CyberResources\\\\ddt\\\\src\\\\unit_test_generator.py'})", - "state": "{'bc219f43158bcf9bd56390fd2488dcf6143970ff6002221e94e29f0d72d381d9': CoverageInfo(args_before=['0', '\"method_call_counter\"', '\"Before\"', 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'], args_after={'this_coverage_info': 'CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)'}, kwargs={}, kwargs_after=OrderedDict(), globals_before={}, globals_after={}, expected_result='CoverageInfo(args_before=[\\'-1\\', \\'1\\'], args_after={}, kwargs={}, kwargs_after={}, globals_before={\\'method_call_counter\\': 0}, globals_after={}, expected_result=\\'\\', expected_type=\\'\\', coverage=[], exception_type=\\'\\', exception_message=\\'\\', constructor=\\'Car(\"Red\", 10, 0)\\', cost=0.0)', expected_type='src.unit_test_generator.CoverageInfo', coverage=[1599, 1602, 1607, 1615, 1616, 1619], exception_type='', exception_message='', constructor='', cost=0.0)}", - "source_file": "Path('C:/Users/James/Documents/CyberResources/ddt/src/unit_test_generator.py')", - "tests_dir": "Path('.')", - "outdir": "Path('.')", - }, - {}, - ), - ], -) -def test_auto_generate_tests( - function_metadata, - state, - function_name, - source_file, - tests_dir, - outdir, - indent_size, - expected_result, - args_after, - globals_before, -): - """ - Programmatically generated test function for auto_generate_tests() - """ - monkeypatch = MonkeyPatch() - monkeypatch.setattr(unit_test_generator, "all_metadata", ALL_METADATA) - result = unit_test_generator.auto_generate_tests( - function_metadata, - state, - function_name, - source_file, - tests_dir, - outdir, - indent_size, - ) - assert result == expected_result or result == eval(expected_result) - assert ( - function_metadata == eval(args_after["function_metadata"]) - or args_after["function_metadata"] == function_metadata - ) - assert state == eval(args_after["state"]) or args_after["state"] == state - assert ( - source_file == eval(args_after["source_file"]) - or args_after["source_file"] == source_file - ) - assert ( - tests_dir == eval(args_after["tests_dir"]) - or args_after["tests_dir"] == tests_dir - ) - assert outdir == eval(args_after["outdir"]) or args_after["outdir"] == outdir diff --git a/tests/all_types/coverage_str_helper.json b/tests/all_types/coverage_str_helper.json index 2d354a0..3320da8 100644 --- a/tests/all_types/coverage_str_helper.json +++ b/tests/all_types/coverage_str_helper.json @@ -7,45 +7,45 @@ "is_method": false, "source_file": null, "lines": [ - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1774, - 1775, - 1777, - 1778, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1786, - 1787, - 1789, - 1790, - 1791, - 1793, - 1795 + 1797, + 1798, + 1799, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1815, + 1816, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1824, + 1825, + 1827, + 1828, + 1829, + 1831, + 1833 ], "non_code_lines": [ - 1776, - 1785, - 1788, - 1792, - 1794 + 1814, + 1823, + 1826, + 1830, + 1832 ], "coverage_io": { "0": { @@ -64,18 +64,18 @@ "expected_result": "[33]", "expected_type": "list", "coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1781, - 1789, - 1790, - 1791, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1819, + 1827, + 1828, + 1829, + 1833 ], "exception_type": "", "exception_message": "", @@ -97,18 +97,18 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1781, - 1789, - 1790, - 1791, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1819, + 1827, + 1828, + 1829, + 1833 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/all_types/test_coverage_str_helper_all_types.py b/tests/all_types/test_coverage_str_helper_all_types.py index ac0f852..a77723c 100644 --- a/tests/all_types/test_coverage_str_helper_all_types.py +++ b/tests/all_types/test_coverage_str_helper_all_types.py @@ -10,7 +10,7 @@ # In sum, these tests covered 37.5% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1793', '1761', '1767-1775', '1777-1780', '1782-1784', '1786-1787'] +# ['1799', '1805-1813', '1815-1818', '1820-1822', '1824-1825'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -30,11 +30,14 @@ def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_af """ result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index 2456493..c421d66 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -4,7 +4,7 @@ import re import pytest -import all_types +from tests.all_types import all_types # In sum, these tests covered 85.71% of get_item_at_index's lines diff --git a/tests/all_types/update_global.json b/tests/all_types/update_global.json index 7236818..0233bec 100644 --- a/tests/all_types/update_global.json +++ b/tests/all_types/update_global.json @@ -9,29 +9,29 @@ "is_method": false, "source_file": null, "lines": [ - 1701, - 1702, - 1703, - 1704, - 1705, - 1706, - 1707, - 1709, - 1717, - 1718, - 1719, - 1720, - 1721 + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, + 1747, + 1755, + 1756, + 1757, + 1758, + 1759 ], "non_code_lines": [ - 1708, - 1710, - 1711, - 1712, - 1713, - 1714, - 1715, - 1716 + 1746, + 1748, + 1749, + 1750, + 1751, + 1752, + 1753, + 1754 ], "coverage_io": { "0": { @@ -52,9 +52,9 @@ "expected_result": "CoverageInfo(args_before=['[33]','{38}'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1701, - 1702, - 1703 + 1739, + 1740, + 1741 ], "exception_type": "", "exception_message": "", @@ -77,9 +77,9 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1701, - 1702, - 1703 + 1739, + 1740, + 1741 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/fizzbuzz/coverage_str_helper.json b/tests/fizzbuzz/coverage_str_helper.json index d66660a..9a17c6b 100644 --- a/tests/fizzbuzz/coverage_str_helper.json +++ b/tests/fizzbuzz/coverage_str_helper.json @@ -7,86 +7,86 @@ "is_method": false, "source_file": null, "lines": [ - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1774, - 1775, - 1777, - 1778, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1786, - 1787, - 1789, - 1790, - 1791, - 1793, - 1795 + 1797, + 1798, + 1799, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1815, + 1816, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1824, + 1825, + 1827, + 1828, + 1829, + 1831, + 1833 ], "non_code_lines": [ - 1776, - 1785, - 1788, - 1792, - 1794 + 1814, + 1823, + 1826, + 1830, + 1832 ], "coverage_io": { "0": { "args_before": [ - "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}" ], "args_after": { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "this_list": "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "non_code_lines": "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['1702-1703', '1705-1707', '1719-1720']", + "expected_result": "['1740-1741', '1743-1745', '1757-1758']", "expected_type": "list", "coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1811, + 1812, + 1813, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1827, + 1833 ], "exception_type": "", "exception_message": "", @@ -108,29 +108,29 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1811, + 1812, + 1813, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1827, + 1833 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/fizzbuzz/normalize_arg.json b/tests/fizzbuzz/normalize_arg.json index aac86a8..2f89fde 100644 --- a/tests/fizzbuzz/normalize_arg.json +++ b/tests/fizzbuzz/normalize_arg.json @@ -6,19 +6,19 @@ "is_method": false, "source_file": null, "lines": [ - 1729, - 1730, - 1731, - 1732, - 1733, - 1734, - 1736, - 1737, - 1738, - 1739 + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1774, + 1775, + 1776, + 1777 ], "non_code_lines": [ - 1735 + 1773 ], "coverage_io": { "0": { @@ -33,12 +33,12 @@ "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "str", "coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "exception_type": "", "exception_message": "", @@ -52,12 +52,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py b/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py index 6e329d3..8606f4c 100644 --- a/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py +++ b/tests/fizzbuzz/test_coverage_str_helper_fizzbuzz.py @@ -10,7 +10,7 @@ # In sum, these tests covered 71.88% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] +# ['1799', '1810', '1815-1816', '1824-1825', '1828-1829'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -21,12 +21,12 @@ def counter(start=0) -> str: "this_list, non_code_lines, expected_result, args_after", [ ( - [1702, 1703, 1705, 1706, 1707, 1719, 1720], - {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, - "['1702-1703', '1705-1707', '1719-1720']", + [1740, 1741, 1743, 1744, 1745, 1757, 1758], + {1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}, + "['1740-1741', '1743-1745', '1757-1758']", { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", + "this_list": "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "non_code_lines": "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}", }, ), ], @@ -38,11 +38,14 @@ def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_af """ result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/fizzbuzz/test_fizzbuzz.py b/tests/fizzbuzz/test_fizzbuzz.py index a8c2e7f..4673445 100644 --- a/tests/fizzbuzz/test_fizzbuzz.py +++ b/tests/fizzbuzz/test_fizzbuzz.py @@ -3,7 +3,7 @@ """ import pytest -import fizzbuzz +from tests.fizzbuzz import fizzbuzz from _pytest.monkeypatch import MonkeyPatch MODE = "fizzbuzz" diff --git a/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py b/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py index 93f100e..1cbf21f 100644 --- a/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py +++ b/tests/fizzbuzz/test_normalize_arg_fizzbuzz.py @@ -8,7 +8,7 @@ # In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1732', '1734', '1737-1738'] +# ['1770', '1772', '1775-1776'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/fizzbuzz/test_update_global_fizzbuzz.py b/tests/fizzbuzz/test_update_global_fizzbuzz.py index 8985317..4aebff7 100644 --- a/tests/fizzbuzz/test_update_global_fizzbuzz.py +++ b/tests/fizzbuzz/test_update_global_fizzbuzz.py @@ -11,7 +11,7 @@ # In sum, these tests covered 46.15% of update_global's lines # Line(s) not covered by ANY of the tests below: -# ['1702-1703', '1705-1707', '1719-1720'] +# ['1740-1741', '1743-1745', '1757-1758'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -59,7 +59,10 @@ def test_update_global( obj, this_global, phase, this_coverage_info ) assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) + try: + assert ( + this_coverage_info == eval(args_after["this_coverage_info"]) + or args_after["this_coverage_info"] == this_coverage_info + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/fizzbuzz/update_global.json b/tests/fizzbuzz/update_global.json index a7a959d..7744ae6 100644 --- a/tests/fizzbuzz/update_global.json +++ b/tests/fizzbuzz/update_global.json @@ -9,29 +9,29 @@ "is_method": false, "source_file": null, "lines": [ - 1701, - 1702, - 1703, - 1704, - 1705, - 1706, - 1707, - 1709, - 1717, - 1718, - 1719, - 1720, - 1721 + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, + 1747, + 1755, + 1756, + 1757, + 1758, + 1759 ], "non_code_lines": [ - 1708, - 1710, - 1711, - 1712, - 1713, - 1714, - 1715, - 1716 + 1746, + 1748, + 1749, + 1750, + 1751, + 1752, + 1753, + 1754 ], "coverage_io": { "0": { @@ -51,12 +51,12 @@ "expected_result": "CoverageInfo(args_before=['6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'mode': 'fizzbuzz'}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1739, + 1742, + 1747, + 1755, + 1756, + 1759 ], "exception_type": "", "exception_message": "", @@ -79,12 +79,12 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1739, + 1742, + 1747, + 1755, + 1756, + 1759 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/coverage_str_helper.json b/tests/oo_car/coverage_str_helper.json index d66660a..eeb2339 100644 --- a/tests/oo_car/coverage_str_helper.json +++ b/tests/oo_car/coverage_str_helper.json @@ -7,86 +7,80 @@ "is_method": false, "source_file": null, "lines": [ - 1759, - 1760, - 1761, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1772, - 1773, - 1774, - 1775, - 1777, - 1778, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1786, - 1787, - 1789, - 1790, - 1791, - 1793, - 1795 + 1797, + 1798, + 1799, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1815, + 1816, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1824, + 1825, + 1827, + 1828, + 1829, + 1831, + 1833 ], "non_code_lines": [ - 1776, - 1785, - 1788, - 1792, - 1794 + 1814, + 1823, + 1826, + 1830, + 1832 ], "coverage_io": { "0": { "args_before": [ - "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "[55, 57]", + "set()" ], "args_after": { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}" + "this_list": "[55, 57]", + "non_code_lines": "set()" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['1702-1703', '1705-1707', '1719-1720']", + "expected_result": "['55']", "expected_type": "list", "coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1809, + 1811, + 1815, + 1816, + 1817, + 1818, + 1819, + 1827, + 1833 ], "exception_type": "", "exception_message": "", @@ -95,7 +89,7 @@ "testable": true } }, - "coverage_percentage": 71.88, + "coverage_percentage": 53.12, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -108,29 +102,23 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1759, - 1760, - 1762, - 1763, - 1764, - 1765, - 1766, - 1767, - 1768, - 1769, - 1770, - 1771, - 1773, - 1774, - 1775, - 1779, - 1780, - 1781, - 1782, - 1783, - 1784, - 1789, - 1795 + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1809, + 1811, + 1815, + 1816, + 1817, + 1818, + 1819, + 1827, + 1833 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/normalize_arg.json b/tests/oo_car/normalize_arg.json index ec4c886..6b3d1f2 100644 --- a/tests/oo_car/normalize_arg.json +++ b/tests/oo_car/normalize_arg.json @@ -6,19 +6,19 @@ "is_method": false, "source_file": null, "lines": [ - 1729, - 1730, - 1731, - 1732, - 1733, - 1734, - 1736, - 1737, - 1738, - 1739 + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1774, + 1775, + 1776, + 1777 ], "non_code_lines": [ - 1735 + 1773 ], "coverage_io": { "0": { @@ -33,12 +33,12 @@ "expected_result": "None", "expected_type": "str", "coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "exception_type": "", "exception_message": "", @@ -52,12 +52,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/oo_car/test_car_is_going_faster_than.py b/tests/oo_car/test_car_is_going_faster_than.py index e3f2e20..68d36ee 100644 --- a/tests/oo_car/test_car_is_going_faster_than.py +++ b/tests/oo_car/test_car_is_going_faster_than.py @@ -35,7 +35,10 @@ def test_car_is_going_faster_than( """ result = test_class_instance.is_going_faster_than(other_car) assert result == expected_result or result == eval(expected_result) - assert ( - other_car == eval(args_after["other_car"]) - or args_after["other_car"] == other_car - ) + try: + assert ( + other_car == eval(args_after["other_car"]) + or args_after["other_car"] == other_car + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/oo_car/test_coverage_str_helper_oo_car.py b/tests/oo_car/test_coverage_str_helper_oo_car.py index 6e329d3..6a08687 100644 --- a/tests/oo_car/test_coverage_str_helper_oo_car.py +++ b/tests/oo_car/test_coverage_str_helper_oo_car.py @@ -8,9 +8,9 @@ # Now import modules specific to coverage_str_helper: -# In sum, these tests covered 71.88% of coverage_str_helper's lines +# In sum, these tests covered 53.12% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1793', '1761', '1772', '1777-1778', '1786-1787', '1790-1791'] +# ['1799', '1806-1808', '1810', '1812-1813', '1820-1822', '1824-1825', '1828-1829'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -21,13 +21,10 @@ def counter(start=0) -> str: "this_list, non_code_lines, expected_result, args_after", [ ( - [1702, 1703, 1705, 1706, 1707, 1719, 1720], - {1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}, - "['1702-1703', '1705-1707', '1719-1720']", - { - "this_list": "[1702, 1703, 1705, 1706, 1707, 1719, 1720]", - "non_code_lines": "{1708, 1710, 1711, 1712, 1713, 1714, 1715, 1716}", - }, + [55, 57], + set(), + "['55']", + {"this_list": "[55, 57]", "non_code_lines": "set()"}, ), ], ids=counter, @@ -38,11 +35,14 @@ def test_coverage_str_helper(this_list, non_code_lines, expected_result, args_af """ result = unit_test_generator.coverage_str_helper(this_list, non_code_lines) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) - assert ( - non_code_lines == eval(args_after["non_code_lines"]) - or args_after["non_code_lines"] == non_code_lines - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + assert ( + non_code_lines == eval(args_after["non_code_lines"]) + or args_after["non_code_lines"] == non_code_lines + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/oo_car/test_normalize_arg_oo_car.py b/tests/oo_car/test_normalize_arg_oo_car.py index d9dfdc3..a1f7ffa 100644 --- a/tests/oo_car/test_normalize_arg_oo_car.py +++ b/tests/oo_car/test_normalize_arg_oo_car.py @@ -8,7 +8,7 @@ # In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1732', '1734', '1737-1738'] +# ['1770', '1772', '1775-1776'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/oo_car/test_update_global_oo_car.py b/tests/oo_car/test_update_global_oo_car.py index c8670f5..53dfbc4 100644 --- a/tests/oo_car/test_update_global_oo_car.py +++ b/tests/oo_car/test_update_global_oo_car.py @@ -1,65 +1,3 @@ """ -Programmatically generated test function for update_global() -""" - -import pytest -from src import unit_test_generator - -# Now import modules specific to update_global: -from src.unit_test_generator import CoverageInfo - - -# In sum, these tests covered 46.15% of update_global's lines -# Line(s) not covered by ANY of the tests below: -# ['1702-1703', '1705-1707', '1719-1720'] -def counter(start=0) -> str: - while True: - yield f"test#-{start}" - start += 1 - - -@pytest.mark.parametrize( - "obj, this_global, phase, this_coverage_info, expected_result, args_after", - [ - ( - 0, - "method_call_counter", - "Before", - CoverageInfo( - args_before=["-1", "1"], - args_after={}, - kwargs={}, - kwargs_after={}, - globals_before={}, - globals_after={}, - expected_result="", - expected_type="", - coverage=[], - exception_type="", - exception_message="", - constructor='Car("Red", 10, 0)', - cost=0.0, - testable=True, - ), - "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", - { - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" - }, - ), - ], - ids=counter, -) -def test_update_global( - obj, this_global, phase, this_coverage_info, expected_result, args_after -): - """ - Programmatically generated test function for update_global() - """ - result = unit_test_generator.update_global( - obj, this_global, phase, this_coverage_info - ) - assert result == expected_result or result == eval(expected_result) - assert ( - this_coverage_info == eval(args_after["this_coverage_info"]) - or args_after["this_coverage_info"] == this_coverage_info - ) +No testable inputs - see accompanying JSON file. +""" \ No newline at end of file diff --git a/tests/oo_car/update_global.json b/tests/oo_car/update_global.json index 7e38e2c..f63e091 100644 --- a/tests/oo_car/update_global.json +++ b/tests/oo_car/update_global.json @@ -9,63 +9,61 @@ "is_method": false, "source_file": null, "lines": [ - 1701, - 1702, - 1703, - 1704, - 1705, - 1706, - 1707, - 1709, - 1717, - 1718, - 1719, - 1720, - 1721 + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, + 1747, + 1755, + 1756, + 1757, + 1758, + 1759 ], "non_code_lines": [ - 1708, - 1710, - 1711, - 1712, - 1713, - 1714, - 1715, - 1716 + 1746, + 1748, + 1749, + 1750, + 1751, + 1752, + 1753, + 1754 ], "coverage_io": { "0": { "args_before": [ - "0", - "\"method_call_counter\"", + "", + "\"logger\"", "\"Before\"", "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" ], "args_after": { - "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" + "obj": "", + "this_coverage_info": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'method_call_counter': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", + "expected_result": "CoverageInfo(args_before=['-1','1'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='Car(\"Red\", 10, 0)', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1739, + 1740, + 1741 ], "exception_type": "", "exception_message": "", "constructor": "", "cost": 0.0, - "testable": true + "testable": false } }, - "coverage_percentage": 46.15, + "coverage_percentage": 23.08, "types_in_use": [ "logging.Logger", "logging.Manager", @@ -79,12 +77,9 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1701, - 1704, - 1709, - 1717, - 1718, - 1721 + 1739, + 1740, + 1741 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/normalize_arg.json b/tests/pass_by_assignment/normalize_arg.json index ec4c886..6b3d1f2 100644 --- a/tests/pass_by_assignment/normalize_arg.json +++ b/tests/pass_by_assignment/normalize_arg.json @@ -6,19 +6,19 @@ "is_method": false, "source_file": null, "lines": [ - 1729, - 1730, - 1731, - 1732, - 1733, - 1734, - 1736, - 1737, - 1738, - 1739 + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1774, + 1775, + 1776, + 1777 ], "non_code_lines": [ - 1735 + 1773 ], "coverage_io": { "0": { @@ -33,12 +33,12 @@ "expected_result": "None", "expected_type": "str", "coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "exception_type": "", "exception_message": "", @@ -52,12 +52,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ - 1729, - 1730, - 1731, - 1733, - 1736, - 1739 + 1767, + 1768, + 1769, + 1771, + 1774, + 1777 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/pass_by_assignment/test_append_list.py b/tests/pass_by_assignment/test_append_list.py index 91875d1..381bade 100644 --- a/tests/pass_by_assignment/test_append_list.py +++ b/tests/pass_by_assignment/test_append_list.py @@ -28,7 +28,10 @@ def test_append_list(this_list, item, expected_result, args_after): """ result = pass_by_assignment.append_list(this_list, item) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py b/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py index d9dfdc3..a1f7ffa 100644 --- a/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py +++ b/tests/pass_by_assignment/test_normalize_arg_pass_by_assignment.py @@ -8,7 +8,7 @@ # In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1732', '1734', '1737-1738'] +# ['1770', '1772', '1775-1776'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/pass_by_assignment/test_overwrite_list.py b/tests/pass_by_assignment/test_overwrite_list.py index aa6c150..1d54981 100644 --- a/tests/pass_by_assignment/test_overwrite_list.py +++ b/tests/pass_by_assignment/test_overwrite_list.py @@ -26,7 +26,10 @@ def test_overwrite_list(this_list, expected_result, args_after): """ result = pass_by_assignment.overwrite_list(this_list) assert result == expected_result or result == eval(expected_result) - assert ( - this_list == eval(args_after["this_list"]) - or args_after["this_list"] == this_list - ) + try: + assert ( + this_list == eval(args_after["this_list"]) + or args_after["this_list"] == this_list + ) + except KeyError as e: + print(f"Got Key Error in test, likely false positive: {e=}") diff --git a/tests/pass_by_assignment/update_global.json b/tests/pass_by_assignment/update_global.json index 4e5b7f6..30d1400 100644 --- a/tests/pass_by_assignment/update_global.json +++ b/tests/pass_by_assignment/update_global.json @@ -9,29 +9,29 @@ "is_method": false, "source_file": null, "lines": [ - 1701, - 1702, - 1703, - 1704, - 1705, - 1706, - 1707, - 1709, - 1717, - 1718, - 1719, - 1720, - 1721 + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, + 1747, + 1755, + 1756, + 1757, + 1758, + 1759 ], "non_code_lines": [ - 1708, - 1710, - 1711, - 1712, - 1713, - 1714, - 1715, - 1716 + 1746, + 1748, + 1749, + 1750, + 1751, + 1752, + 1753, + 1754 ], "coverage_io": { "0": { @@ -52,9 +52,9 @@ "expected_result": "CoverageInfo(args_before=['[1, 2, 3, 4]','6'], args_after={}, kwargs={}, kwargs_after={}, globals_before={}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1701, - 1702, - 1703 + 1739, + 1740, + 1741 ], "exception_type": "", "exception_message": "", @@ -77,9 +77,9 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1701, - 1702, - 1703 + 1739, + 1740, + 1741 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/coverage_str_helper.json b/tests/procedural_division/coverage_str_helper.json index 7385c93..9a17c6b 100644 --- a/tests/procedural_division/coverage_str_helper.json +++ b/tests/procedural_division/coverage_str_helper.json @@ -7,6 +7,13 @@ "is_method": false, "source_file": null, "lines": [ + 1797, + 1798, + 1799, + 1800, + 1801, + 1802, + 1803, 1804, 1805, 1806, @@ -17,76 +24,69 @@ 1811, 1812, 1813, - 1814, 1815, 1816, 1817, 1818, 1819, 1820, + 1821, 1822, - 1823, 1824, 1825, - 1826, 1827, 1828, 1829, 1831, - 1832, - 1834, - 1835, - 1836, - 1838, - 1840 + 1833 ], "non_code_lines": [ - 1821, + 1814, + 1823, + 1826, 1830, - 1833, - 1837, - 1839 + 1832 ], "coverage_io": { "0": { "args_before": [ - "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", - "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}" + "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}" ], "args_after": { - "this_list": "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", - "non_code_lines": "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}" + "this_list": "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "non_code_lines": "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}" }, "kwargs": {}, "kwargs_after": {}, "globals_before": {}, "globals_after": {}, - "expected_result": "['1764-1765', '1747-1748', '1750-1752']", + "expected_result": "['1740-1741', '1743-1745', '1757-1758']", "expected_type": "list", "coverage": [ + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, 1804, 1805, + 1806, 1807, 1808, 1809, - 1810, 1811, 1812, 1813, - 1814, - 1815, - 1816, + 1817, 1818, 1819, 1820, - 1824, - 1825, - 1826, + 1821, + 1822, 1827, - 1828, - 1829, - 1834, - 1840 + 1833 ], "exception_type": "", "exception_message": "", @@ -108,29 +108,29 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ + 1797, + 1798, + 1800, + 1801, + 1802, + 1803, 1804, 1805, + 1806, 1807, 1808, 1809, - 1810, 1811, 1812, 1813, - 1814, - 1815, - 1816, + 1817, 1818, 1819, 1820, - 1824, - 1825, - 1826, + 1821, + 1822, 1827, - 1828, - 1829, - 1834, - 1840 + 1833 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/normalize_arg.json b/tests/procedural_division/normalize_arg.json index fd8e60e..fa68ef3 100644 --- a/tests/procedural_division/normalize_arg.json +++ b/tests/procedural_division/normalize_arg.json @@ -6,19 +6,19 @@ "is_method": false, "source_file": null, "lines": [ + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, 1774, 1775, 1776, - 1777, - 1778, - 1779, - 1781, - 1782, - 1783, - 1784 + 1777 ], "non_code_lines": [ - 1780 + 1773 ], "coverage_io": { "0": { @@ -33,12 +33,12 @@ "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "str", "coverage": [ + 1767, + 1768, + 1769, + 1771, 1774, - 1775, - 1776, - 1778, - 1781, - 1784 + 1777 ], "exception_type": "", "exception_message": "", @@ -52,12 +52,12 @@ "global_vars_read_from": [], "global_vars_written_to": [], "unified_test_coverage": [ + 1767, + 1768, + 1769, + 1771, 1774, - 1775, - 1776, - 1778, - 1781, - 1784 + 1777 ], "needs_pytest": false, "exceptions_raised": [], diff --git a/tests/procedural_division/test_coverage_str_helper_procedural_division.py b/tests/procedural_division/test_coverage_str_helper_procedural_division.py index 1aac2df..8606f4c 100644 --- a/tests/procedural_division/test_coverage_str_helper_procedural_division.py +++ b/tests/procedural_division/test_coverage_str_helper_procedural_division.py @@ -10,7 +10,7 @@ # In sum, these tests covered 71.88% of coverage_str_helper's lines # Line(s) not covered by ANY of the tests below: -# ['1806', '1817', '1822-1823', '1831-1832', '1835-1836'] +# ['1799', '1810', '1815-1816', '1824-1825', '1828-1829'] def counter(start=0) -> str: while True: yield f"test#-{start}" @@ -21,12 +21,12 @@ def counter(start=0) -> str: "this_list, non_code_lines, expected_result, args_after", [ ( - [1764, 1765, 1747, 1748, 1750, 1751, 1752], - {1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}, - "['1764-1765', '1747-1748', '1750-1752']", + [1740, 1741, 1743, 1744, 1745, 1757, 1758], + {1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}, + "['1740-1741', '1743-1745', '1757-1758']", { - "this_list": "[1764, 1765, 1747, 1748, 1750, 1751, 1752]", - "non_code_lines": "{1760, 1761, 1753, 1755, 1756, 1757, 1758, 1759}", + "this_list": "[1740, 1741, 1743, 1744, 1745, 1757, 1758]", + "non_code_lines": "{1746, 1748, 1749, 1750, 1751, 1752, 1753, 1754}", }, ), ], diff --git a/tests/procedural_division/test_normalize_arg_procedural_division.py b/tests/procedural_division/test_normalize_arg_procedural_division.py index f2e826e..cf0afee 100644 --- a/tests/procedural_division/test_normalize_arg_procedural_division.py +++ b/tests/procedural_division/test_normalize_arg_procedural_division.py @@ -8,7 +8,7 @@ # In sum, these tests covered 60.0% of normalize_arg's lines # Line(s) not covered by ANY of the tests below: -# ['1777', '1779', '1782-1783'] +# ['1770', '1772', '1775-1776'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/procedural_division/test_update_global_procedural_division.py b/tests/procedural_division/test_update_global_procedural_division.py index 252017b..01f5baa 100644 --- a/tests/procedural_division/test_update_global_procedural_division.py +++ b/tests/procedural_division/test_update_global_procedural_division.py @@ -11,7 +11,7 @@ # In sum, these tests covered 46.15% of update_global's lines # Line(s) not covered by ANY of the tests below: -# ['1764-1765', '1747-1748', '1750-1752'] +# ['1740-1741', '1743-1745', '1757-1758'] def counter(start=0) -> str: while True: yield f"test#-{start}" diff --git a/tests/procedural_division/update_global.json b/tests/procedural_division/update_global.json index 72d0b11..8bf2e87 100644 --- a/tests/procedural_division/update_global.json +++ b/tests/procedural_division/update_global.json @@ -9,29 +9,29 @@ "is_method": false, "source_file": null, "lines": [ - 1746, + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, 1747, + 1755, + 1756, + 1757, + 1758, + 1759 + ], + "non_code_lines": [ + 1746, 1748, 1749, 1750, 1751, 1752, - 1754, - 1762, - 1763, - 1764, - 1765, - 1766 - ], - "non_code_lines": [ 1753, - 1755, - 1756, - 1757, - 1758, - 1759, - 1760, - 1761 + 1754 ], "coverage_io": { "0": { @@ -51,12 +51,12 @@ "expected_result": "CoverageInfo(args_before=['6','2'], args_after={}, kwargs={}, kwargs_after={}, globals_before={'error_code': 0}, globals_after={}, expected_result='', expected_type='', coverage=[], exception_type='', exception_message='', constructor='', cost=0.0, testable=True)", "expected_type": "src.unit_test_generator.CoverageInfo", "coverage": [ - 1746, - 1749, - 1754, - 1762, - 1763, - 1766 + 1739, + 1742, + 1747, + 1755, + 1756, + 1759 ], "exception_type": "", "exception_message": "", @@ -79,12 +79,12 @@ ], "global_vars_written_to": [], "unified_test_coverage": [ - 1746, - 1749, - 1754, - 1762, - 1763, - 1766 + 1739, + 1742, + 1747, + 1755, + 1756, + 1759 ], "needs_pytest": false, "exceptions_raised": [], From 3bb7e71e5167c57ecd6cb6f86d092d2fe3d5a246 Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 10:52:04 -0500 Subject: [PATCH 164/165] src tets no longer work, so removed it --- .github/workflows/python-app-ubuntu.yml | 2 +- .github/workflows/python-app-windows.yml | 10 +++++----- tests/all_types/test_get_item_at_index.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index bdc1ba1..ac404e9 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -199,7 +199,7 @@ jobs: poetry run pip install genbadge[all] 2>&1 1>/dev/null poetry run coverage combine tests/fizzbuzz/.coverage tests/oo_car/.coverage tests/all_types/.coverage tests/pass_by_assignment/.coverage tests/procedural_division/.coverage src/.coverage ls -lah - #poetry run coverage run -m pytest . + #poetry run coverage run -m pytest . --omit="*/src" poetry run coverage report -m --omit="*/test_*" poetry run coverage xml --omit="*/test_*" poetry run coverage html diff --git a/.github/workflows/python-app-windows.yml b/.github/workflows/python-app-windows.yml index de52c31..871ec39 100644 --- a/.github/workflows/python-app-windows.yml +++ b/.github/workflows/python-app-windows.yml @@ -98,10 +98,10 @@ jobs: poetry run python pass_by_assignment.py poetry run pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - - name: pytest helper functions - # continue-on-error: true - run: | - cd src - poetry run pytest --log-level=DEBUG -s -v . + #- name: pytest helper functions + # # continue-on-error: true + # run: | + # cd src + # poetry run pytest --log-level=DEBUG -s -v . # TODO Get full coverage \ No newline at end of file diff --git a/tests/all_types/test_get_item_at_index.py b/tests/all_types/test_get_item_at_index.py index c421d66..2456493 100644 --- a/tests/all_types/test_get_item_at_index.py +++ b/tests/all_types/test_get_item_at_index.py @@ -4,7 +4,7 @@ import re import pytest -from tests.all_types import all_types +import all_types # In sum, these tests covered 85.71% of get_item_at_index's lines From fc0c93db0456a3a561a29f10c79fc6b6b67a4fbd Mon Sep 17 00:00:00 2001 From: James Hatfield Date: Fri, 14 Nov 2025 14:19:28 -0500 Subject: [PATCH 165/165] added time and removed sleep --- .github/workflows/python-app-ubuntu.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app-ubuntu.yml b/.github/workflows/python-app-ubuntu.yml index ac404e9..25eb0ed 100644 --- a/.github/workflows/python-app-ubuntu.yml +++ b/.github/workflows/python-app-ubuntu.yml @@ -157,11 +157,11 @@ jobs: # continue-on-error: true run: | cd tests/oo_car - # echo "example_car.py -d runtime:" - poetry run python example_car.py -d - #echo "example_car.py runtime:" - poetry run python example_car.py - sleep 1 + echo "example_car.py -d runtime:" + time poetry run python example_car.py -d + echo "example_car.py runtime:" + time poetry run python example_car.py + #sleep 1 poetry run coverage run -m pytest -s -v . #--doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - name: pytest pass_by_assignment