Repository navigation
Conversation
Cover legalize_vector_name, append_random, append_uuid, append_node_pid, basename, try_remove, try_rmdir, diff_files, split, naturally_sorted, get_num_suffix, parse_key_val, get_lib_path and set_path. Gaps were found by running Pynguin on grass.script.utils. The tests are written by hand, with AI assistance, and the expected values were checked against the behavior of the functions. Several mutations of utils.py were used to confirm that the tests fail when the code changes.
Test the extraction of standard options from lib/gis/parser_standard_options.c (dynamic answers, multiline strings, multiline function calls, escaped quotes), the heading lookup, the Markdown generation for a single option and the CSV, HTML and Markdown output of the option table. The whole real C source file is parsed to check that every standard option is found. Pynguin was run on the module to see what a generator can do. It only produced empty inputs for the nested list and dict parameters, so the tests are written by hand, with AI assistance, with expected values checked against the C source. Mutations of the module were used to confirm that the tests fail when the code changes.
A multiline G_ call in a case of lib/gis/parser_standard_options.c, such as G_asprintf(, set the open parenthesis count and the following lines subtracted their net count, so the closing line increased the count instead of bringing it to zero. All lines after the call were then skipped until the end of the case. The standard options currently in the C source have such calls only as the last statement of a case, so the generated documentation is unchanged. Add the continuation lines' net count instead, and add a test with an assignment after a multiline call. The problem was found by checking whether the new tests detect changes of this line, with AI assistance.
| def test_naturally_sorted_key(): | ||
| """Check that the key function selects the text used for sorting""" | ||
| items = [("b", "file10"), ("a", "file9")] | ||
| assert gutils.naturally_sorted(items, key=lambda item: item[1]) == [ |
There was a problem hiding this comment.
[ruff] reported by reviewdog 🐶
Suggested change
| assert gutils.naturally_sorted(items, key=lambda item: item[1]) == [ | |
| assert gutils.naturally_sorted(items, key=operator.itemgetter(1)) == [ |
There was a problem hiding this comment.
[ruff] reported by reviewdog 🐶
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add pytest tests for
grass.script.utilshelpers (legalize_vector_name,append_*,basename,try_remove/try_rmdir,parse_key_val,get_lib_path,set_path, and others) and forman/parser_standard_options.py, which had no tests. Fix a parenthesis counting bug inparse_optionsfound while writing them (separate commit).Motivation and context
Pynguin was run on
grass.script.utilsandman/parser_standard_options.pyto find untested code. Its generated tests were not usable as-is, so the tests are written by hand, with AI assistance, with expected values checked against the code. Pynguin only indicated the gaps.parse_optionsdiddiff -= count_par_diff(line), so a multilineG_call made it skip every line untilbreak;. The generated documentation is unchanged, because the C source only has such calls as the last statement of a case.How has this been tested?
pytest python/grass/script/tests/utils_test.py man/tests: all pass. Coverage ofgrass.script.utilsunder pytest goes from 32% to 88%.utils.pyandparser_standard_options.pywere applied to check that the tests fail when the code changes.parse_optionsonlib/gis/parser_standard_options.cis identical before and after the fix (89 options).Types of changes
Checklist
pre-defined prefixes
of this project.
Generated by Claude Code