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) fh.read() retcode = fh.close() return retcode == None def runCommandAndCheckOutput(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() return retcode == None and checkOutput(output)