def __call__(self, status: str, headers: Iterable[Header], exc_info: Any = None) -> StartResponseReturnType: assert_false(self.was_called, "start_response() called twice") assert_regex(status, _status_re) self.was_called = True self.status = status self.headers = list(headers) return lambda s: None
def arguments_error(self) -> None: def handle(_: WSGIEnvironment, __: StartResponse) -> Iterable[bytes]: raise ArgumentsError({"foo": "bar"}) self.router.add_routes([("foo", "GET", handle)]) response = self.handle_wsgi("GET", "/foo") self.start_response.assert_status(HTTPStatus.BAD_REQUEST) html = b"".join(response).decode("utf-8") assert html.startswith("<!DOCTYPE html>") assert_regex( html, r'<li class="argument">\s*' r'<span class="argument-name">foo</span>:\s*' r'<span class="error-message">bar</span>\s*' r"</li>", )
def in_console(self, line): """In a console section: execute commands. Skip old output.""" if line.startswith("$ "): self.expected_output = "" # Reset the expected output self.write_lines(line) self.output = do_command(line) if self.output: self.write_lines(self.output) return self.in_console if line == "```": if self.expected_output.strip().startswith("re: "): regex = re.compile(self.expected_output[len("re: "):].strip(), re.MULTILINE) assert_regex(self.output.strip(), regex) else: assert_equal(self.expected_output.strip(), self.output.strip(), "Expected: {first}, got: {second}") self.write_lines(line) return self.default self.expected_output += "\n" + line return self.in_console
def unrecognized_arg_error_message(context, argument): """Check the error message.""" assert_regex(context.next_action(), f".*unrecognized arguments?: {argument}.*")
def show_next_action_with_a_prio(context): """Check that the next actions have a priority.""" for line in context.next_action().strip().split("\n"): assert_regex(line, "([A-Z])")