Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: add validation of generically generated invalid files #420

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mzuenni
Copy link
Collaborator

@mzuenni mzuenni commented Feb 7, 2025

Dynamically generates (likely) invalid testcases to challenge validators
related: #352

@mpsijm mpsijm marked this pull request as draft February 8, 2025 11:13
@mzuenni
Copy link
Collaborator Author

mzuenni commented Feb 12, 2025

@mpsijm @RagnarGrootKoerkamp more input here is welcome :)

Copy link
Collaborator

@mpsijm mpsijm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good at first glance! 😄 Tried it on some problems but didn't try to break it yet. Here are some first comments based on the code 🙂

Comment on lines +921 to +927
action = (
"Invalidation"
if mode == validate.Mode.INVALID
else (
f"Collecting {mode} constraints" if constraints else f"{mode} validation"
).capitalize()
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .capitalize() the action when both branches return something that already starts with a capital? 🤔

Oh wait, the mode is not capitalized. Maybe this can be simplified to only mode.capitalize() then 🙂

skel/problem/generators/generators.yaml Show resolved Hide resolved
if test_path:
test_case = test_path.relative_to(p.path / "data").with_suffix("")
log(f"Generating invalid testcases based on: {test_case}")
debug(f"writing generated invalid testcases to: {base_path}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug log is visible, even without -v, I guess that's intended ('cause the log is "debug" and not "verbose")?

from typing import Optional, TypeVar

_GENERATOR_NAMES: set[str] = set()
GENERATORS: list[tuple[str, str | Callable[[str], Optional[str]], bool]] = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add documentation comments about what going on here? From what I'm gathering, these generators are created once validator_tests is imported, and these generators are then used to generate invalid test cases in problem.py.

One note about creating these generators in top-level code: this does mean that this is always executed, also in the many instances where a command different than bt validate is called, and also when performing tab-completion in your shell. Since these generators are only used inside Problem.validate_invalid_extra_data, perhaps we should wrap this in a function anyway 😛 I think Python will still us nest the decorator magic inside that function 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a global var with all the generators, i.e. the same as GENERATORS = [(), (), ()...] i.e. trivial to construct. I think its just clearer this way and easier to extend.


testcases.append(testcase.Testcase(p, full_path, short_path=short_path))

return p._validate_data(validate.Mode.INVALID, None, "Generic Invalidation", testcases)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, doc/validation.md only talks about Input/Answer/Output (in)validation, I think it would be good to add a section about this new "Generic Invalidation" as well 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants