SonOfLilit / kleenexp

modern regular expression syntax everywhere with a painless upgrade path
MIT License
73 stars 16 forks source link

pytest tests could be refactored to use fixtures and parameterization #10

Closed InbarRose closed 2 years ago

InbarRose commented 2 years ago

i have noticed a few improvements that can be made to testing.

many of the tests are easily convertible to parameterized. this improvement will mean that instead of the test failing on the first failed assertion, it will test all possible options and all failures will be reported. it will increase the overall count of tests, but essentially you would be getting enhanced visibility per test if you have some failures you would not need to run multiple times, you would see all failures at once.

example:

(in PR form https://github.com/SonOfLilit/kleenexp/pull/11 )

# previous
def test_short_names():
    macro_names = [
        ("linefeed", "lf"),
        ("not_linefeed", "nlf"),
       # ... snipped ...
        ("hex_digit", "hexd"),
        ("hex_number", "hexn"),
    ]
    for long, short in macro_names:
        assert compile(Macro("#" + long)) == compile(Macro("#" + short))

#proposed 
@pytest.mark.parametrize(
    argnames=["long", "short"],
    argvalues=[
        ("linefeed", "lf"),
        ("not_linefeed", "nlf"),
       # ... snipped ...
        ("hex_digit", "hexd"),
        ("hex_number", "hexn"),
    ])
def test_short_names(long, short):
    assert compile(Macro("#" + long)) == compile(Macro("#" + short))

additionally some of the tests can be refactored to use fixtures. instead of using globally accessible objects defined at the module level, this improvement would align better with pytest best practices, but it does not seem to provide that much additional value at the moment.

I am happy to refactor the tests. please let me know.

InbarRose commented 2 years ago

@SonOfLilit for your consideration.

SonOfLilit commented 2 years ago

I don't feel like it would be a great use of your time, these tests don't tend to fail in mysterious ways much. If you want, there are some actually interesting tasks that can be taken, like adding cool functionality to the compiler(s)