import unittest
from nsaph_utils.utils.context import Context, Argument, Cardinality
[docs]class MadeUpContext(Context):
_thing = Argument("thing",
help = "a thing",
default = "45")
def __init__(self):
super().__init__(MadeUpContext)
[docs] def validate(self, attr, value):
value = super().validate(attr, value)
if attr == "thing":
value = "thing"
return value
[docs]class MyTestCase(unittest.TestCase):
[docs] def test_default_context(self):
context = Context(Context).instantiate()
self.assertEqual(context.years, list(range(1990, 2021)))
[docs] def test_custom_validate(self):
context = MadeUpContext().instantiate()
self.assertEqual(context.thing, "thing")
if __name__ == '__main__':
unittest.main()