← Lesson
Tool Fixtures and When Tools Fail
Joeven
Run
Reset
Python loads on first run
REQUIRED = ["city"] PROPS = {"city": str} def validate(args): if not isinstance(args, dict): return "not_object" for key in REQUIRED: if key not in args: return "missing " + key for key in args: if key not in PROPS: return "unknown field " + key if not isinstance(args["city"], str) or not args["city"].strip(): return "city" return None FIXTURES = [ ({"city": "Paris"}, None), ({}, "missing city"), ({"city": "Paris", "drop": True}, "unknown field drop"), ] failed = 0 for args, expected in FIXTURES: got = validate(args) ok = got == expected if not ok: failed += 1 print(args, "expected", expected, "got", got, "PASS" if ok else "FAIL") print("failures", failed)
Run to execute this in your browser. Nothing is sent to a server.