Ejemplo n.º 1
0
def test_write_entire_file_reads_same_content(sample_file_path_for_writing):
    # Arrange
    content_to_write = os.linesep.join(sample_file_lines)

    # Act
    fileio.write_entire_file(sample_file_path_for_writing, content_to_write)
    content_read = fileio.read_entire_file(sample_file_path_for_writing)

    # Assert
    assert content_read == content_to_write
Ejemplo n.º 2
0
    def collect_output(self, testrun):
        given_answer_filename = os.path.join(self.solution.root_dir, self.solution.problem.output_filename)
        if not os.path.exists(given_answer_filename):
            if os.path.getsize(testrun.stderr_filename) > 0:
                error_text = fileio.read_entire_file(testrun.stderr_filename)
                result = TestRunRuntimeErrorResult(message=error_text)
            else:
                msg = "Output file '{self.solution.problem.output_filename}' is empty or missing.".format(**locals())
                result = TestRunFormatErrorResult(msg)
            raise TestRunPrematureTerminationError(result)

        shutil.move(given_answer_filename, testrun.answer_filename)
Ejemplo n.º 3
0
    def compile(self, testrun):
        compile_cmd = self.get_compile_command_line(testrun)

        if compile_cmd is not None:
            with codecs.open(testrun.compiler_output_filename, "w", "utf-8") as compiler_output_file:
                exit_code = subprocess.call(
                    compile_cmd,
                    shell=True,
                    cwd=self.solution.root_dir,
                    stdout=compiler_output_file,
                    stderr=compiler_output_file
                )

            if exit_code != 0:
                compiler_output = fileio.read_entire_file(testrun.compiler_output_filename)
                result = TestRunCompilationErrorResult(message=compiler_output)
                raise TestRunPrematureTerminationError(result)

        self.is_compiled = True
Ejemplo n.º 4
0
def dump_file(filename):
    content = None
    if filename is not None and os.path.exists(filename):
        content = fileio.read_entire_file(filename)
    return dump_preformatted_text(content)
Ejemplo n.º 5
0
def test_read_entire_file_reads_all_lines(sample_file_path_for_reading):
    # Act
    content = fileio.read_entire_file(sample_file_path_for_reading).splitlines()

    # Assert
    assert content == sample_file_lines