-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractiveTester.py
More file actions
36 lines (30 loc) · 1.07 KB
/
interactiveTester.py
File metadata and controls
36 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import readline
class interactiveTester:
def __init__(self):
self.command_func_print = []
self.prompt = '>>> '
self.resultPrompt = '>>>>>> '
self.exitCommand = 'exit'
def boundCommand(self, commandPrefix, func, printResult = False):
self.command_func_print.append((commandPrefix, func, printResult))
def setPrompt(self, prompt):
self.prompt = prompt
def setResultPrompt(self, prompt):
self.resultPrompt = prompt
def setExitCommand(self, command):
self.exitCommand = command
def start(self):
while True:
x = input(self.prompt)
if x == self.exitCommand:
break
hit = False
for command, func, p in self.command_func_print:
args = x[len(command):].split()
if x.startswith(command):
hit = True
r = func(*args)
if p:
print(self.resultPrompt + str(r))
if hit == False:
print('what ?')