Custom types used throughout the library
from fastcore.test import ExceptionExpected
with ExceptionExpected(TypeError, "Member is a documentation type, cannot be instantiated"):
t = Member()
with ExceptionExpected(TypeError, "Member is a documentation type, cannot be instantiated"):
t = Mem()
from fastcore.test import ExceptionExpected
with ExceptionExpected(TypeError, "Documented is a documentation type, cannot be instantiated"):
t = Documented()
with ExceptionExpected(TypeError, "Documented is a documentation type, cannot be instantiated"):
t = Doc()
_da = [["zero", 0], ["one", 1]]
_d = FunctionalEnum("test_enum", _da)
test_eq(hasattr(_d, "zero"), True)
test_eq(str(_d.zero), "0")
test_eq(_d.zero == 0, True)
test_eq(hasattr(_d, "one"), True)
test_eq(str(_d.one), "1")
test_eq(_d.one == 1, True)
_da = [["addition", ("Sum of two numbers", "addition")], ["subtraction", ("Some documentation")], ["multiplication", (None, "multiplication")]]
_d = DocumentedEnum("test_enum", _da)
test_eq(hasattr(_d, "addition"), True)
test_eq(str(_d.addition), "addition")
test_eq(_d.addition.__doc__, "Sum of two numbers")
test_eq(_d.addition == "addition", True)
test_eq(str(_d.subtraction), str(None))
test_eq(_d.subtraction.__doc__, "Some documentation")
test_eq(_d.subtraction != "addition", True)
test_eq(str(_d.multiplication), "multiplication")
test_eq(_d.multiplication.__doc__, "An enumeration.")
test_eq(_d.multiplication != "addition", True)
@enumify
class DaysOfWeek:
MONDAY:tuple[Member,Documented] = "First day of the week"
TUESDAY:Member
WEDNESDAY:Documented = "Wed", "Third day of the week"
THURSDAY:Documented = 0, "Fourth day of the week"
test_eq(DaysOfWeek.MONDAY, "monday")
test_eq(DaysOfWeek.MONDAY.__doc__, "First day of the week")
test_eq(DaysOfWeek.TUESDAY, "tuesday")
test_eq(DaysOfWeek.TUESDAY.__doc__, "An enumeration.")
test_eq(DaysOfWeek.WEDNESDAY, "Wed")
test_eq(DaysOfWeek.WEDNESDAY.__doc__, "Third day of the week")
test_eq(DaysOfWeek.THURSDAY, 0)
test_eq(DaysOfWeek.THURSDAY.__doc__, "Fourth day of the week")
@enumify
class DaysOfWeek:
MONDAY:tuple[Mem,Doc] = "First day of the week"
TUESDAY:Mem
WEDNESDAY:Doc = "Wed", "Third day of the week"
THURSDAY:Doc = 0, "Fourth day of the week"
test_eq(DaysOfWeek.MONDAY, "monday")
test_eq(DaysOfWeek.MONDAY.__doc__, "First day of the week")
test_eq(DaysOfWeek.TUESDAY, "tuesday")
test_eq(DaysOfWeek.TUESDAY.__doc__, "An enumeration.")
test_eq(DaysOfWeek.WEDNESDAY, "Wed")
test_eq(DaysOfWeek.WEDNESDAY.__doc__, "Third day of the week")
test_eq(DaysOfWeek.THURSDAY, 0)
test_eq(DaysOfWeek.THURSDAY.__doc__, "Fourth day of the week")