owenrusk.dev

errands

small jobs the runtime does for the studio.

git clone https://owenrusk.dev/errands.git

errands / tests/test_tools.py -rw-r--r-- · 799 bytes

 1 import json
 2 import unittest
 3 
 4 from errands import tools
 5 
 6 
 7 class CallTest(unittest.TestCase):
 8     def test_calls_a_registered_tool(self):
 9         tools.TOOLS["echo"] = lambda text: text
10         try:
11             out = json.loads(tools.call(json.dumps({"tool": "echo", "args": {"text": "hi"}})))
12         finally:
13             del tools.TOOLS["echo"]
14         self.assertEqual(out, {"ok": True, "result": "hi"})
15 
16     def test_errors_are_json(self):
17         out = json.loads(tools.call(json.dumps({"tool": "no_such_tool"})))
18         self.assertEqual(out, {"ok": False, "error": "KeyError: 'no_such_tool'"})
19         self.assertFalse(json.loads(tools.call("not json"))["ok"])
20 
21     def test_mail_tools_are_there(self):
22         self.assertLessEqual({"mail_unread", "mail_reply", "mail_send"}, set(tools.TOOLS))