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

Manually add checklist targets #4

Open
salotz opened this issue Jul 15, 2024 · 0 comments
Open

Manually add checklist targets #4

salotz opened this issue Jul 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@salotz
Copy link
Contributor

salotz commented Jul 15, 2024

In normal operations we use the parser to collect the checklist. However, in some cases you want to write tests for things that are not functions. For instance if you have some configuration over a set of literal values or constants that should have a desired behavior you want to make sure this is tested, even if it technically isn't a unit test of some code.

For a global value you want to test:

GLOBAL_MAGIC_NUM = 113  # checklist:
from ... import GLOBAL_MAGIC_NUM
@pointer(target=GLOBAL_MAGIC_NUM)
def test_GLOBAL_MAGIC_NUM():
    assert GLOBAL_MAGIC_NUM < 137
    assert GLOBAL_MAGIC_NUM > 93

Further consider a table of regexes:

REGEXES= [ # checklist:
    ("slug", r"^[a-z0-9]+(?:-[a-z0-9]+)*$"), 
    ("email: r"(^[\u0100-\u017F\u0180-\u024F]"
                  # dot-atom
                  + r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
                  # quoted-string
                  + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*"$)',
]

You want to expect tests for each entry in that list so you would annotate as shown in the snippet and then write tests like:

from ... import REGEXES

@pointer(target=REGEXES, element=0)
def test_REGEXES_slug():
    ...
@salotz salotz added the enhancement New feature or request label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant