MCPcopy Create free account
hub / github.com/jasperproject/jasper-client / TestModules

Class TestModules

tests/test_modules.py:15–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class TestModules(unittest.TestCase):
16
17 def setUp(self):
18 self.profile = DEFAULT_PROFILE
19 self.send = False
20
21 def runConversation(self, query, inputs, module):
22 """Generic method for spoofing conversation.
23
24 Arguments:
25 query -- The initial input to the server.
26 inputs -- Additional input, if conversation is extended.
27
28 Returns:
29 The server's responses, in a list.
30 """
31 self.assertTrue(module.isValid(query))
32 mic = test_mic.Mic(inputs)
33 module.handle(query, mic, self.profile)
34 return mic.outputs
35
36 def testLife(self):
37 query = "What is the meaning of life?"
38 inputs = []
39 outputs = self.runConversation(query, inputs, Life)
40 self.assertEqual(len(outputs), 1)
41 self.assertTrue("42" in outputs[0])
42
43 def testJoke(self):
44 query = "Tell me a joke."
45 inputs = ["Who's there?", "Random response"]
46 outputs = self.runConversation(query, inputs, Joke)
47 self.assertEqual(len(outputs), 3)
48 allJokes = open(jasperpath.data('text', 'JOKES.txt'), 'r').read()
49 self.assertTrue(outputs[2] in allJokes)
50
51 def testTime(self):
52 query = "What time is it?"
53 inputs = []
54 self.runConversation(query, inputs, Time)
55
56 @unittest.skipIf(not diagnose.check_network_connection(),
57 "No internet connection")
58 def testGmail(self):
59 key = 'gmail_password'
60 if key not in self.profile or not self.profile[key]:
61 return
62
63 query = "Check my email"
64 inputs = []
65 self.runConversation(query, inputs, Gmail)
66
67 @unittest.skipIf(not diagnose.check_network_connection(),
68 "No internet connection")
69 def testHN(self):
70 query = "find me some of the top hacker news stories"
71 if self.send:
72 inputs = ["the first and third"]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected