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:
I don't care about types, which is the main thing that most schema do care about. Some limited type-casting can be nice, but I've found more and more that it's better to do those kinds of things in the test function itself.
The very-useful Namespace.error_or() is completely tied to voluptuous. It also doesn't actually validate the schema correctly, due to the need to keep the schema definition succinct.
With voluptuous especially, specifying default values is verbose.
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:
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:
Namespace.error_or()
is completely tied to voluptuous. It also doesn't actually validate the schema correctly, due to the need to keep the schema definition succinct.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:Not bad, but feels like there should be an
error_or
class. Maybe each of the arguments above can be its own schema function, andTestCase
is basically just a container:That seems pretty good...