class EndToEndRunner: def __init__(self, file_system): self._file_system = file_system def test(self, test_case): self._tear_down(test_case) self._setup(test_case) self._execute(test_case) self._verify(test_case) def _tear_down(self, test_case): self._output = StringIO() self._display = Display(self._output, verbose=True) self._controller = Controller(self._file_system, self._display) self._file_system.deleteDirectory(self._path_for(test_case)) def _setup(self, test_case): test_case._project.setup(self._file_system, self._path_for(test_case) / "project") @staticmethod def _path_for(test_case): return TEMP / "flap" / "acceptance" / test_case.escaped_name def _execute(self, test_case): self._file_system.move_to_directory(self._path_for(test_case)) self._controller.run(tex_file="./project/" + test_case._invocation.tex_file, output="output") def _verify(self, test_case): self._verify_generated_files(test_case) self._verify_console_output(test_case) def _verify_generated_files(self, test_case): location = self._file_system.open(Path.fromText("output")) actual = LatexProject.extract_from_directory(location) test_case._expected.assert_is_equivalent_to(actual) def _verify_console_output(self, test_case): self._verify_shown(__version__) self._verify_shown(self._display.HEADER) self._verify_shown(self._display._horizontal_line()) entries = [each.as_dictionary for each in test_case._output] for each_entry in entries: each_entry["code"] = truncate(each_entry["code"], self._display.WIDTHS[3]) self._verify_shown(self._display.ENTRY.format(**each_entry)) self._verify_shown( self._display.SUMMARY.format(count=len(test_case._output))) def _verify_shown(self, text): message = "Could not find the following text:\n" \ " \"{pattern}\"\n" \ "\n" \ "The output was:\n" \ "{output}\n" if text not in self._output.getvalue(): raise AssertionError( message.format(pattern=text, output=self._output.getvalue()))
class EndToEndRunner: def __init__(self, file_system): self._file_system = file_system def test(self, test_case): self._tear_down(test_case) self._setup(test_case) self._execute(test_case) self._verify(test_case) def _tear_down(self, test_case): self._output = StringIO() self._display = Display(self._output) self._controller = Controller(self._file_system, self._display) self._file_system.deleteDirectory(self._path_for(test_case)) def _setup(self, test_case): test_case._project.setup(self._file_system, self._path_for(test_case) / "project") def _path_for(self, test_case): return TEMP / "flap" / "acceptance" / test_case.escaped_name def _execute(self, test_case): self._file_system.move_to_directory(self._path_for(test_case)) main_tex_file = "./project/main.tex" self._controller.run(["__main.py__", main_tex_file, "output"]) def _verify(self, test_case): self._verify_generated_files(test_case) self._verify_console_output(test_case) def _verify_generated_files(self, test_case): location = self._file_system.open(Path.fromText("output")) actual = LatexProject.extract_from_directory(location) actual.assert_is_equivalent_to(test_case._expected) def _verify_console_output(self, test_case): self._verify_shown(__version__) self._verify_shown(self._display.HEADER) self._verify_shown(self._display._horizontal_line()) entries = [each.as_dictionary for each in test_case._output] for each_entry in entries: self._verify_shown(self._display.ENTRY.format(**each_entry)) self._verify_shown(self._display.SUMMARY.format(count=len(test_case._output))) def _verify_shown(self, text): message = "Could not find the following text:\n" \ " \"{pattern}\"\n" \ "\n" \ "The output was:\n" \ "{output}\n" if text not in self._output.getvalue(): raise AssertionError(message.format(pattern=text, output=self._output.getvalue()))
def _tear_down(self, test_case): self._output = StringIO() self._display = Display(self._output, verbose=True) self._controller = Controller(self._file_system, self._display) self._file_system.deleteDirectory(self._path_for(test_case))
def _tear_down(self, test_case): self._output = StringIO() self._display = Display(self._output) self._controller = Controller(self._file_system, self._display) self._file_system.deleteDirectory(self._path_for(test_case))