kalekundert / parametrize_from_file

Read unit test parameters from config files
MIT License
15 stars 3 forks source link

Provide a tailored schema implementation #16

Closed kalekundert closed 2 years ago

kalekundert commented 2 years ago

I currently recommend using third-party schema libraries, but I'm starting to think that it might be better to provide my own schema implementation that's better tailored to this application. Third-party schema have the following drawbacks:

For this application, all I need is (i) default values, (ii) error_or, and (iii) maybe some ability to cast things. Focusing on just these things, I think I can probably make a more succinct API than any third-party library can offer. Some ideas:

schema=TestCase(
    defaults={
        'a': 0,
    },
    cast={
        'b': int,
    },
    error_or=[
        'b',
    ],
    error='error',  # to rename the error arg, if desired.
    error_ns=with_py,
)

Not bad, but feels like there should be an error_or class. Maybe each of the arguments above can be its own schema function, and TestCase is basically just a container:

schema=TestCase(
    defaults(a=0),
    cast(b=int),
    error_or(with_sw, 'a', 'b', param='error'),
)

That seems pretty good...