def build_and_run_file(filename): ''' Builds and runs the filename specified according to the extension PARAM filename: name of file to build and run ''' (directory, name, extension) = get_file_tuple(filename) if extension == 'c': print(" = = = = = = ", YELLOW, "GCC: Compiling " + filename + " file", \ RESET, " = = = = = =\n") compiler = Compiler(filename) out = compiler.compile() if out != 0: print('Error while compiling. Code:', out, 'Please retry.') return out print("") out = compiler.run() return out elif extension == 'cpp': print(" = = = = = = ", YELLOW, "GPP: Compiling " + filename + " file", \ RESET, " = = = = = =\n") compiler = Compiler(filename) out = compiler.compile() if out != 0: print('Error while compiling. Code:', out, 'Please retry.') return out print("") out = compiler.run() return out elif extension == 'py': print(" = = = = = = ", YELLOW, "PYTHON: Executing " + filename + " file", \ RESET, " = = = = = =\n") command_run = EXECUTABLE_PYTHON + " " + filename test_file = directory + "/" + name + ".input" if os.path.exists(test_file): command_run += " < " + test_file return perform_system_command(command_run) elif extension == 'java': command = EXECUTABLE_JAVAC + ' ' + filename perform_system_command(command) command_run = EXECUTABLE_JAVA + ' ' + name test_file = directory + "/" + name + ".input" if os.path.exists(test_file): command_run += " < " + test_file return perform_system_command(command_run) else: print("Language yet not supported") return -1
def run(self): command_run = get_command_to_run(self.filename) return perform_system_command(command_run)
def compile(self): """ :return: 0 if compilation successful """ command = get_command_for_compilation(self.filename) return perform_system_command(command)
def test_perform_system_call(self, mock): cmd = 'universal' perform_system_command(cmd) mock.assert_called_once_with(cmd)