mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
python: Reformat with Black, except quotes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
5028c081cb
commit
11741543da
@@ -26,8 +26,9 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
|
||||
authentication_line = f"{client.email}:{client.api_key}"
|
||||
# A limited Markdown engine that just processes the code example syntax.
|
||||
realm = get_realm("zulip")
|
||||
md_engine = markdown.Markdown(extensions=[markdown_extension.makeExtension(
|
||||
api_url=realm.uri + "/api")])
|
||||
md_engine = markdown.Markdown(
|
||||
extensions=[markdown_extension.makeExtension(api_url=realm.uri + "/api")]
|
||||
)
|
||||
|
||||
# We run our curl tests in alphabetical order (except that we
|
||||
# delay the deactivate-user test to the very end), since we depend
|
||||
@@ -47,25 +48,27 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
|
||||
# example, and then run that to test it.
|
||||
curl_command_html = md_engine.convert(line.strip())
|
||||
unescaped_html = html.unescape(curl_command_html)
|
||||
curl_command_text = unescaped_html[len("<p><code>curl\n"):-len("</code></p>")]
|
||||
curl_command_text = unescaped_html[len("<p><code>curl\n") : -len("</code></p>")]
|
||||
|
||||
curl_command_text = curl_command_text.replace(
|
||||
"BOT_EMAIL_ADDRESS:BOT_API_KEY", authentication_line)
|
||||
"BOT_EMAIL_ADDRESS:BOT_API_KEY", authentication_line
|
||||
)
|
||||
|
||||
print("Testing {} ...".format(curl_command_text.split("\n")[0]))
|
||||
|
||||
# Turn the text into an arguments list.
|
||||
generated_curl_command = [
|
||||
x for x in shlex.split(curl_command_text) if x != "\n"]
|
||||
generated_curl_command = [x for x in shlex.split(curl_command_text) if x != "\n"]
|
||||
|
||||
response_json = None
|
||||
response = None
|
||||
try:
|
||||
# We split this across two lines so if curl fails and
|
||||
# returns non-JSON output, we'll still print it.
|
||||
response_json = subprocess.check_output(generated_curl_command, universal_newlines=True)
|
||||
response_json = subprocess.check_output(
|
||||
generated_curl_command, universal_newlines=True
|
||||
)
|
||||
response = json.loads(response_json)
|
||||
assert(response["result"] == "success")
|
||||
assert response["result"] == "success"
|
||||
except (AssertionError, Exception):
|
||||
error_template = """
|
||||
Error verifying the success of the API documentation curl example.
|
||||
@@ -89,13 +92,20 @@ Common reasons for why this could occur:
|
||||
|
||||
To learn more about the test itself, see zerver/openapi/test_curl_examples.py.
|
||||
"""
|
||||
print(error_template.format(
|
||||
file_name=file_name,
|
||||
line=line,
|
||||
curl_command=generated_curl_command,
|
||||
response=response_json if response is None else json.dumps(response, indent=4)))
|
||||
print(
|
||||
error_template.format(
|
||||
file_name=file_name,
|
||||
line=line,
|
||||
curl_command=generated_curl_command,
|
||||
response=response_json
|
||||
if response is None
|
||||
else json.dumps(response, indent=4),
|
||||
)
|
||||
)
|
||||
raise
|
||||
|
||||
if REGISTERED_GENERATOR_FUNCTIONS != CALLED_GENERATOR_FUNCTIONS:
|
||||
raise Exception("Some registered generator functions were not called:\n"
|
||||
" " + str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS))
|
||||
raise Exception(
|
||||
"Some registered generator functions were not called:\n"
|
||||
" " + str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user