import os import re import shutil def checkOutput(output): """ Ensure hello world is in string. return: whether hello world is present """ return output == 'Hello world!\n' def runCommand(command): """ Define a function to run a shell commmand and return the output param command: command to run return: Whether retcode is 0 """ fh = os.popen(command, mode='r', buffering=-1) output = fh.read() retcode = fh.close() assert retcode == None def runCommandAndOutputCheck(command): """ Define a function to run a shell command and ensure output is correct param command: command return: Whether retcode is 0 && output matches test. """ fh = os.popen(command, mode='r', buffering=-1) output = fh.read() retcode = fh.close() assert retcode == None and CheckOutput(output)