style: reformat files with ruff
This commit is contained in:
+5
-10
@@ -8,7 +8,7 @@ class DirectusAPI:
|
|||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
self.access_token = access_token
|
self.access_token = access_token
|
||||||
|
|
||||||
def __get_raw(self, endpoint, params = None):
|
def __get_raw(self, endpoint, params=None):
|
||||||
if params is None:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
for k in params.keys():
|
for k in params.keys():
|
||||||
@@ -16,16 +16,11 @@ class DirectusAPI:
|
|||||||
params[k] = json.dumps(params[k])
|
params[k] = json.dumps(params[k])
|
||||||
url = self.base_url + endpoint
|
url = self.base_url + endpoint
|
||||||
result = requests.get(
|
result = requests.get(
|
||||||
url,
|
url, params=params, headers={"Authorization": f"Bearer {self.access_token}", "Cache-Control": "no-store"}
|
||||||
params = params,
|
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer {self.access_token}",
|
|
||||||
"Cache-Control": "no-store"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get(self, endpoint, params = None):
|
def get(self, endpoint, params=None):
|
||||||
if params is None:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
result = self.__get_raw(endpoint, params)
|
result = self.__get_raw(endpoint, params)
|
||||||
@@ -40,7 +35,7 @@ class DirectusAPI:
|
|||||||
return None
|
return None
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_one(self, endpoint, params = None):
|
def get_one(self, endpoint, params=None):
|
||||||
if params is None:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
results = self.get(endpoint, params)
|
results = self.get(endpoint, params)
|
||||||
@@ -51,7 +46,7 @@ class DirectusAPI:
|
|||||||
else:
|
else:
|
||||||
raise Exception("One result expected, but got more than one result")
|
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:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
result = self.__get_raw(endpoint, params)
|
result = self.__get_raw(endpoint, params)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
Question,
|
Question,
|
||||||
Picture,
|
Picture,
|
||||||
Photo,
|
Photo,
|
||||||
Table
|
Table,
|
||||||
)
|
)
|
||||||
self.question_renderer = question_renderer
|
self.question_renderer = question_renderer
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
\captionof{{figure}}{{{text}}}
|
\captionof{{figure}}{{{text}}}
|
||||||
\label{{{ref}}}"""
|
\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)
|
return self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -114,13 +114,13 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
\captionof{{figure}}{{{text}}}
|
\captionof{{figure}}{{{text}}}
|
||||||
\label{{{ref}}}"""
|
\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)
|
return self.render_photo_helper(token.id, token.ref, token.text, token.number)
|
||||||
|
|
||||||
def render_table(self, token):
|
def render_table(self, token):
|
||||||
alignments = token.alignment
|
alignments = token.alignment
|
||||||
align = ""
|
align = ""
|
||||||
for alignment in alignments :
|
for alignment in alignments:
|
||||||
align += alignment
|
align += alignment
|
||||||
|
|
||||||
table = f"\\begin{{DARCtabular}}{{{align}}}\n"
|
table = f"\\begin{{DARCtabular}}{{{align}}}\n"
|
||||||
@@ -130,10 +130,10 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
table += self.render_inner(cell)
|
table += self.render_inner(cell)
|
||||||
if j < len(row.children) - 1:
|
if j < len(row.children) - 1:
|
||||||
table += " & "
|
table += " & "
|
||||||
table += r"\\"+ "\n"
|
table += r"\\" + "\n"
|
||||||
|
|
||||||
table += "\\end{DARCtabular}"
|
table += "\\end{DARCtabular}"
|
||||||
if token.caption != "" :
|
if token.caption != "":
|
||||||
table += f"\\captionof{{figure}}{{{token.caption}}}\n"
|
table += f"\\captionof{{figure}}{{{token.caption}}}\n"
|
||||||
table += f"\\label{{{token.name}}}\n"
|
table += f"\\label{{{token.name}}}\n"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ class Include(BlockToken):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read(cls, lines):
|
def read(cls, lines):
|
||||||
re.compile(r'')
|
re.compile(r"")
|
||||||
line = next(lines) # Consume the line with the include directive
|
line = next(lines) # Consume the line with the include directive
|
||||||
ident = re.match(r"^\s*\[include:\s*([^\]]+)\]", line).group(1)
|
ident = re.match(r"^\s*\[include:\s*([^\]]+)\]", line).group(1)
|
||||||
return ident
|
return ident
|
||||||
|
|||||||
+1
-1
@@ -87,4 +87,4 @@ class Morse(SpanToken):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
parse_inner = False
|
parse_inner = False
|
||||||
pattern = re.compile(r'\[morse:\s*([^\]]+)\]')
|
pattern = re.compile(r"\[morse:\s*([^\]]+)\]")
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class Qso(BlockToken):
|
|||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
self.children = match
|
self.children = match
|
||||||
|
|
||||||
|
|
||||||
class QsoLine(BlockToken):
|
class QsoLine(BlockToken):
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_line(cls, line):
|
def parse_line(cls, line):
|
||||||
|
|||||||
@@ -69,11 +69,13 @@ def question_stub(input):
|
|||||||
answer_pictures=answer_pictures,
|
answer_pictures=answer_pictures,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def include_stub(include):
|
def include_stub(include):
|
||||||
with open("data/includes.json") as file:
|
with open("data/includes.json") as file:
|
||||||
includes = json.load(file)
|
includes = json.load(file)
|
||||||
return includes.get(include)
|
return includes.get(include)
|
||||||
|
|
||||||
|
|
||||||
def test_html(capsys):
|
def test_html(capsys):
|
||||||
with capsys.disabled():
|
with capsys.disabled():
|
||||||
with open("test/acceptanceTest.md") as file:
|
with open("test/acceptanceTest.md") as file:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
|
|||||||
@pytest.mark.html
|
@pytest.mark.html
|
||||||
def test_include_html():
|
def test_include_html():
|
||||||
assertions = {
|
assertions = {
|
||||||
'[include:ident]': "ident\n",
|
"[include:ident]": "ident\n",
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_function(input):
|
def test_function(input):
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ def test_question_html():
|
|||||||
for assertion in assertions:
|
for assertion in assertions:
|
||||||
assert renderer.render(Document(assertion)) == assertions[assertion]
|
assert renderer.render(Document(assertion)) == assertions[assertion]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.html
|
@pytest.mark.html
|
||||||
def test_question_translation_html():
|
def test_question_translation_html():
|
||||||
assertions = {
|
assertions = {
|
||||||
@@ -34,7 +35,7 @@ def test_question_translation_html():
|
|||||||
}
|
}
|
||||||
|
|
||||||
def test_function(input):
|
def test_function(input):
|
||||||
with open('data/metadata.json') as file:
|
with open("data/metadata.json") as file:
|
||||||
metadata = json.load(file)
|
metadata = json.load(file)
|
||||||
return metadata[f"{input}"].get("number")
|
return metadata[f"{input}"].get("number")
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ def test_question_latex():
|
|||||||
}
|
}
|
||||||
|
|
||||||
def test_function(input):
|
def test_function(input):
|
||||||
return "\\question{"+input+"}"
|
return "\\question{" + input + "}"
|
||||||
|
|
||||||
with FiftyOhmLaTeXRenderer(test_function) as renderer:
|
with FiftyOhmLaTeXRenderer(test_function) as renderer:
|
||||||
for assertion in assertions:
|
for assertion in assertions:
|
||||||
|
|||||||
Reference in New Issue
Block a user