flake8, pydocstyle, pyupgrade → ruff

This commit is contained in:
Guilhem Saurel
2023-03-09 00:07:23 +01:00
parent a3555a6ff8
commit f90a21e4e6
16 changed files with 69 additions and 59 deletions

View File

@@ -4,6 +4,7 @@
import argparse
import logging
from os import environ
from pathlib import Path
from subprocess import Popen, run
from time import time
from unittest import main
@@ -21,7 +22,11 @@ LOGGER = logging.getLogger("matrix-webhook.tests.start")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"-v", "--verbose", action="count", default=0, help="increment verbosity level"
"-v",
"--verbose",
action="count",
default=0,
help="increment verbosity level",
)
@@ -77,14 +82,14 @@ def run_and_test():
"synapse.app.homeserver",
"--config-path",
"/srv/homeserver.yaml",
]
],
)
if not wait_available(f"{MATRIX_URL}/_matrix/client/r0/login", "flows"):
return False
# Register a user for the bot.
LOGGER.info("Registering the bot")
with open("/srv/homeserver.yaml") as f:
with Path("/srv/homeserver.yaml").open() as f:
secret = yaml.safe_load(f.read()).get("registration_shared_secret", None)
request_registration(MATRIX_ID, MATRIX_PW, MATRIX_URL, secret, admin=True)

View File

@@ -1,6 +1,7 @@
"""Test module for grafana formatter."""
import unittest
from pathlib import Path
import httpx
import nio
@@ -39,7 +40,7 @@ class GithubFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_github_push.json", "rb") as f:
with Path("tests/example_github_push.json", "rb").open() as f:
example_github_push = f.read().strip()
self.assertEqual(
httpx.post(
@@ -72,7 +73,7 @@ class GithubFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_github_push.json", "rb") as f:
with Path("tests/example_github_push.json").open("rb") as f:
example_github_push = f.read().strip()
self.assertEqual(
httpx.post(
@@ -92,11 +93,11 @@ class GithubFormatterTest(unittest.IsolatedAsyncioTestCase):
before = "ac7d1d9647008145e9d0cf65d24744d0db4862b8"
after = "4bcdb25c809391baaabc264d9309059f9f48ead2"
GH = "https://github.com"
expected = f'<p><a href="{GH}/nim65s">@nim65s</a> pushed on refs/heads/devel: '
expected += f'<a href="{GH}/nim65s/matrix-webhook/compare/ac7d1d964700...'
gh = "https://github.com"
expected = f'<p><a href="{gh}/nim65s">@nim65s</a> pushed on refs/heads/devel: '
expected += f'<a href="{gh}/nim65s/matrix-webhook/compare/ac7d1d964700...'
expected += f'4bcdb25c8093">{before}{after}</a>:</p>\n<ul>\n<li>'
expected += f'<a href="{GH}/nim65s/matrix-webhook/commit/{after}">'
expected += f'<a href="{gh}/nim65s/matrix-webhook/commit/{after}">'
expected += "formatters: also get headers</a></li>\n</ul>"
message = messages.chunk[0]
@@ -113,7 +114,7 @@ class GithubFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_github_push.json", "rb") as f:
with Path("tests/example_github_push.json").open("rb") as f:
example_github_push = f.read().strip()
self.assertEqual(

View File

@@ -1,9 +1,7 @@
"""
Test module for gitlab "google chat" formatter.
"""
"""Test module for gitlab "google chat" formatter."""
import unittest
from pathlib import Path
import httpx
import nio
@@ -22,7 +20,7 @@ class GitlabGchatFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_gitlab_gchat.json") as f:
with Path("tests/example_gitlab_gchat.json").open() as f:
example_gitlab_gchat_request = f.read()
self.assertEqual(
httpx.post(

View File

@@ -1,9 +1,7 @@
"""
Test module for gitlab "teams" formatter.
"""
"""Test module for gitlab "teams" formatter."""
import unittest
from pathlib import Path
import httpx
import nio
@@ -22,7 +20,7 @@ class GitlabTeamsFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_gitlab_teams.json") as f:
with Path("tests/example_gitlab_teams.json").open() as f:
example_gitlab_teams_request = f.read()
self.assertEqual(
httpx.post(

View File

@@ -1,10 +1,10 @@
"""
Test module for grafana formatter.
"""Test module for grafana formatter.
ref https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#webhook
"""
import unittest
from pathlib import Path
import httpx
import nio
@@ -23,7 +23,7 @@ class GrafanaFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_grafana.json") as f:
with Path("tests/example_grafana.json").open() as f:
example_grafana_request = f.read()
self.assertEqual(
httpx.post(

View File

@@ -1,10 +1,10 @@
"""
Test module for grafana v9 formatter.
"""Test module for grafana v9 formatter.
ref https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#webhook
"""
import unittest
from pathlib import Path
import httpx
import nio
@@ -23,7 +23,7 @@ class Grafana9xFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_grafana_9x.json") as f:
with Path("tests/example_grafana_9x.json").open() as f:
example_grafana_request = f.read()
self.assertEqual(
httpx.post(

View File

@@ -1,10 +1,10 @@
"""
Test version 9 compatibility of grafana formatter.
"""Test version 9 compatibility of grafana formatter.
ref https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#webhook
"""
import unittest
from pathlib import Path
import httpx
import nio
@@ -23,7 +23,7 @@ class GrafanaForwardFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_grafana_9x.json") as f:
with Path("tests/example_grafana_9x.json").open() as f:
example_grafana_request = f.read()
self.assertEqual(
httpx.post(

View File

@@ -50,7 +50,8 @@ class BotTest(unittest.IsolatedAsyncioTestCase):
room = await client.room_create()
self.assertEqual(
bot_req({"text": text}, KEY, room.room_id), {"status": 200, "ret": "OK"}
bot_req({"text": text}, KEY, room.room_id),
{"status": 200, "ret": "OK"},
)
sync = await client.sync()
@@ -118,7 +119,8 @@ class BotTest(unittest.IsolatedAsyncioTestCase):
room = await client.room_create()
self.assertEqual(
bot_req({"body": body}, KEY, room.room_id), {"status": 200, "ret": "OK"}
bot_req({"body": body}, KEY, room.room_id),
{"status": 200, "ret": "OK"},
)
sync = await client.sync()
@@ -142,7 +144,9 @@ class BotTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
bot_req(
{"body": body, "formatted_body": formatted_body}, KEY, room.room_id
{"body": body, "formatted_body": formatted_body},
KEY,
room.room_id,
),
{"status": 200, "ret": "OK"},
)