Skip to content

Executors

Executor (ABC)

file_extension() staticmethod

Source code in testcase_maker/executor.py
@staticmethod
def file_extension() -> str:
    raise NotImplementedError

compile(self)

Source code in testcase_maker/executor.py
def compile(self) -> Path:
    raise NotImplementedError

execute(self, stdin)

Source code in testcase_maker/executor.py
def execute(self, stdin: str) -> str:
    raise NotImplementedError

log

CPPExecutor (Executor)

Run your answer script in C++!

file_extension() staticmethod

Source code in testcase_maker/executors/cpp.py
@staticmethod
def file_extension() -> str:
    return ".cpp"

compile(self)

Source code in testcase_maker/executors/cpp.py
def compile(self) -> "Path":
    args = ["g++", "-o", str(self.source_file.stem), str(self.source_file.absolute())]
    run_command(args, cwd=self.tempdir)
    return self.tempdir.joinpath(f"{self.source_file.stem}.exe")

execute(self, stdin)

Source code in testcase_maker/executors/cpp.py
def execute(self, stdin: str) -> str:
    args = [str(self.compiled_file)]
    return run_command(args, stdin, self.compiled_file.parent)

JavaExecutor (Executor)

Run your answer script in java!

file_extension() staticmethod

Source code in testcase_maker/executors/java.py
@staticmethod
def file_extension() -> str:
    return ".java"

compile(self)

Source code in testcase_maker/executors/java.py
def compile(self) -> "Path":
    args = ["javac", str(self.source_file.absolute()), "-d", str(self.tempdir)]
    run_command(args, cwd=self.tempdir)
    return self.tempdir.joinpath(f"{self.source_file.stem}.class")

execute(self, stdin)

Source code in testcase_maker/executors/java.py
def execute(self, stdin: str) -> str:
    args = ["java", str(self.compiled_file.stem)]
    return run_command(args, stdin, self.compiled_file.parent)

PythonExecutor (Executor)

Run your answer script in python!

file_extension() staticmethod

Source code in testcase_maker/executors/python.py
@staticmethod
def file_extension() -> str:
    return ".py"

compile(self)

Source code in testcase_maker/executors/python.py
def compile(self) -> "Path":
    copy_source = self.tempdir.joinpath(self.source_file.name)
    shutil.copy(self.source_file, copy_source)
    args = [sys.executable, "-m", "compileall", str(copy_source)]
    run_command(args, cwd=self.tempdir)
    return next(self.tempdir.joinpath("__pycache__").glob('*.pyc'))

execute(self, stdin)

Source code in testcase_maker/executors/python.py
def execute(self, stdin: str) -> str:
    args = [sys.executable, str(self.compiled_file)]
    return run_command(args, stdin)