This is a convienence method for running a programming and capturing the in and output.
def runWithInput(self, testInput=[]):
studentSubmission = 'main'
## Stores output from print() in capturedOutput
with patch('sys.stdout', new=StringIO()) as self.capturedOutput:
#["4", "5", "1.2e-2", "2.5e2"]
with patch('builtins.input', side_effect=testInput):
# alternative kann mit side_effect=['Bart', 'Lisa'] mehr als ein Wert zurückgegeben werden
if studentSubmission in sys.modules:
importlib.reload(sys.modules[ studentSubmission ] )
else:
importlib.import_module( studentSubmission )
# Now split the output into lines
self.captured_stdout = self.capturedOutput.getvalue()
self.lines = self.captured_stdout.split('\n')
if len(self.lines) == 0:
self.fail('Es wurde nichts ausgegeben.')
# Remove the last emtpy line
if len(self.lines) > 0 and self.lines[-1] == '':
self.lines.pop()
return self.lines
This is a convienence method for running a programming and capturing the in and output.