From f0299298a6541334ecb91e5d14494bddc56f3628 Mon Sep 17 00:00:00 2001 From: Tim Grelka Date: Thu, 3 Jul 2025 17:58:29 +0200 Subject: [PATCH] style: reformat files with ruff --- api/directus.py | 15 +++++---------- renderer/fifty_ohm_latex_renderer.py | 12 ++++++------ renderer/include.py | 4 ++-- renderer/morse.py | 2 +- renderer/qso.py | 1 + test/test_html.py | 2 ++ test/test_include.py | 2 +- test/test_question.py | 5 +++-- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/api/directus.py b/api/directus.py index 05896c7..0258fcf 100644 --- a/api/directus.py +++ b/api/directus.py @@ -8,7 +8,7 @@ class DirectusAPI: self.base_url = base_url self.access_token = access_token - def __get_raw(self, endpoint, params = None): + def __get_raw(self, endpoint, params=None): if params is None: params = {} for k in params.keys(): @@ -16,16 +16,11 @@ class DirectusAPI: params[k] = json.dumps(params[k]) url = self.base_url + endpoint result = requests.get( - url, - params = params, - headers = { - "Authorization": f"Bearer {self.access_token}", - "Cache-Control": "no-store" - } + url, params=params, headers={"Authorization": f"Bearer {self.access_token}", "Cache-Control": "no-store"} ) return result - def get(self, endpoint, params = None): + def get(self, endpoint, params=None): if params is None: params = {} result = self.__get_raw(endpoint, params) @@ -40,7 +35,7 @@ class DirectusAPI: return None return data - def get_one(self, endpoint, params = None): + def get_one(self, endpoint, params=None): if params is None: params = {} results = self.get(endpoint, params) @@ -51,7 +46,7 @@ class DirectusAPI: else: raise Exception("One result expected, but got more than one result") - def get_file(self, endpoint, params = None): + def get_file(self, endpoint, params=None): if params is None: params = {} result = self.__get_raw(endpoint, params) diff --git a/renderer/fifty_ohm_latex_renderer.py b/renderer/fifty_ohm_latex_renderer.py index 9a6e767..21a9883 100644 --- a/renderer/fifty_ohm_latex_renderer.py +++ b/renderer/fifty_ohm_latex_renderer.py @@ -27,7 +27,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer): Question, Picture, Photo, - Table + Table, ) self.question_renderer = question_renderer @@ -105,7 +105,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer): \captionof{{figure}}{{{text}}} \label{{{ref}}}""" - def render_picture(self, token) : + def render_picture(self, token): return self.render_picture_helper(token.id, token.ref, token.text, token.number) @staticmethod @@ -114,13 +114,13 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer): \captionof{{figure}}{{{text}}} \label{{{ref}}}""" - def render_photo(self, token) : + def render_photo(self, token): return self.render_photo_helper(token.id, token.ref, token.text, token.number) def render_table(self, token): alignments = token.alignment align = "" - for alignment in alignments : + for alignment in alignments: align += alignment table = f"\\begin{{DARCtabular}}{{{align}}}\n" @@ -130,10 +130,10 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer): table += self.render_inner(cell) if j < len(row.children) - 1: table += " & " - table += r"\\"+ "\n" + table += r"\\" + "\n" table += "\\end{DARCtabular}" - if token.caption != "" : + if token.caption != "": table += f"\\captionof{{figure}}{{{token.caption}}}\n" table += f"\\label{{{token.name}}}\n" diff --git a/renderer/include.py b/renderer/include.py index 6147059..0cf92d3 100644 --- a/renderer/include.py +++ b/renderer/include.py @@ -15,8 +15,8 @@ class Include(BlockToken): @classmethod def read(cls, lines): - re.compile(r'') - line = next(lines) # Consume the line with the include directive + re.compile(r"") + line = next(lines) # Consume the line with the include directive ident = re.match(r"^\s*\[include:\s*([^\]]+)\]", line).group(1) return ident diff --git a/renderer/morse.py b/renderer/morse.py index 72eabe6..e47ba86 100644 --- a/renderer/morse.py +++ b/renderer/morse.py @@ -87,4 +87,4 @@ class Morse(SpanToken): return result parse_inner = False - pattern = re.compile(r'\[morse:\s*([^\]]+)\]') + pattern = re.compile(r"\[morse:\s*([^\]]+)\]") diff --git a/renderer/qso.py b/renderer/qso.py index 6571696..2359ffc 100644 --- a/renderer/qso.py +++ b/renderer/qso.py @@ -25,6 +25,7 @@ class Qso(BlockToken): def __init__(self, match): self.children = match + class QsoLine(BlockToken): @classmethod def parse_line(cls, line): diff --git a/test/test_html.py b/test/test_html.py index 05b8964..714bb34 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -69,11 +69,13 @@ def question_stub(input): answer_pictures=answer_pictures, ) + def include_stub(include): with open("data/includes.json") as file: includes = json.load(file) return includes.get(include) + def test_html(capsys): with capsys.disabled(): with open("test/acceptanceTest.md") as file: diff --git a/test/test_include.py b/test/test_include.py index a08a578..4b024a4 100644 --- a/test/test_include.py +++ b/test/test_include.py @@ -7,7 +7,7 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer @pytest.mark.html def test_include_html(): assertions = { - '[include:ident]': "ident\n", + "[include:ident]": "ident\n", } def test_function(input): diff --git a/test/test_question.py b/test/test_question.py index 60c7b2d..e4e4ceb 100644 --- a/test/test_question.py +++ b/test/test_question.py @@ -24,6 +24,7 @@ def test_question_html(): for assertion in assertions: assert renderer.render(Document(assertion)) == assertions[assertion] + @pytest.mark.html def test_question_translation_html(): assertions = { @@ -34,7 +35,7 @@ def test_question_translation_html(): } def test_function(input): - with open('data/metadata.json') as file: + with open("data/metadata.json") as file: metadata = json.load(file) return metadata[f"{input}"].get("number") @@ -53,7 +54,7 @@ def test_question_latex(): } def test_function(input): - return "\\question{"+input+"}" + return "\\question{" + input + "}" with FiftyOhmLaTeXRenderer(test_function) as renderer: for assertion in assertions: