mirror of https://github.com/eyhc1/rendercv.git
Ruff whitespace linting
This commit is contained in:
parent
55abcd06e8
commit
64b42a68cd
|
@ -1115,14 +1115,17 @@ class Connection(BaseModel):
|
||||||
# `[[:word:]]` in Ruby includes lots of things that could never be in a # domain name. As my intent here is to construct an HTTPS URL,
|
# `[[:word:]]` in Ruby includes lots of things that could never be in a # domain name. As my intent here is to construct an HTTPS URL,
|
||||||
# I will use a more restrictive set of characters.
|
# I will use a more restrictive set of characters.
|
||||||
|
|
||||||
pattern = re.compile(r"""
|
pattern = re.compile(
|
||||||
|
r"""
|
||||||
^\s* # ignore leading spaces
|
^\s* # ignore leading spaces
|
||||||
@? # Optional @ prefix
|
@? # Optional @ prefix
|
||||||
(?P<uname>[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part
|
(?P<uname>[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part
|
||||||
@ # separator
|
@ # separator
|
||||||
(?P<domain>[a-z0-9]+([a-z0-9.-]+)?) # domain part
|
(?P<domain>[a-z0-9]+([a-z0-9.-]+)?) # domain part
|
||||||
\s*$ # ignore trailing whitespace
|
\s*$ # ignore trailing whitespace
|
||||||
""", re.VERBOSE | re.IGNORECASE)
|
""",
|
||||||
|
re.VERBOSE | re.IGNORECASE,
|
||||||
|
)
|
||||||
|
|
||||||
m = pattern.match(address)
|
m = pattern.match(address)
|
||||||
if m is None:
|
if m is None:
|
||||||
|
@ -1135,7 +1138,7 @@ class Connection(BaseModel):
|
||||||
if not Connection.is_valid_fqdn(domain):
|
if not Connection.is_valid_fqdn(domain):
|
||||||
raise ValueError("Invalid hostname in mastodon address")
|
raise ValueError("Invalid hostname in mastodon address")
|
||||||
|
|
||||||
url = HttpUrl(f'https://{domain}/@{uname}')
|
url = HttpUrl(f"https://{domain}/@{uname}")
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
|
|
|
@ -17,7 +17,7 @@ class TestDataModel(unittest.TestCase):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
str_with_latex_characers = r"asdf#asdf$asdf%asdf& ~ fd_ \ ^aa aa{ bb}"
|
str_with_latex_characers = r"asdf#asdf$asdf%asdf& ~ fd_ \ ^aa aa{ bb}"
|
||||||
expected ='asdf\\#asdf$asdf\\%asdf\\& \\textasciitilde{} fd_ \\ ^aa aa{ bb}'
|
expected = "asdf\\#asdf$asdf\\%asdf\\& \\textasciitilde{} fd_ \\ ^aa aa{ bb}"
|
||||||
with self.subTest(msg="string with LaTeX characters"):
|
with self.subTest(msg="string with LaTeX characters"):
|
||||||
result = data_model.escape_latex_characters(str_with_latex_characers)
|
result = data_model.escape_latex_characters(str_with_latex_characers)
|
||||||
print(result)
|
print(result)
|
||||||
|
@ -862,46 +862,44 @@ class TestDataModel(unittest.TestCase):
|
||||||
data_model.read_input_file("nonexistent.json")
|
data_model.read_input_file("nonexistent.json")
|
||||||
|
|
||||||
def test_mastodon_parsing(self):
|
def test_mastodon_parsing(self):
|
||||||
mastodon_name = 'a_tooter@example.exchange'
|
mastodon_name = "a_tooter@example.exchange"
|
||||||
expected = HttpUrl("https://example.exchange/@a_tooter")
|
expected = HttpUrl("https://example.exchange/@a_tooter")
|
||||||
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
with self.subTest("Without '@' prefix"):
|
with self.subTest("Without '@' prefix"):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
mastodon_name = '@a_tooter@example.exchange'
|
mastodon_name = "@a_tooter@example.exchange"
|
||||||
expected = HttpUrl("https://example.exchange/@a_tooter")
|
expected = HttpUrl("https://example.exchange/@a_tooter")
|
||||||
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
with self.subTest("With '@' prefix"):
|
with self.subTest("With '@' prefix"):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
mastodon_name = '@too@many@symbols'
|
mastodon_name = "@too@many@symbols"
|
||||||
with self.subTest("Too many '@' symbols"):
|
with self.subTest("Too many '@' symbols"):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
data_model.Connection.MastodonUname2Url(mastodon_name)
|
data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
|
|
||||||
mastodon_name = '@not_enough_at_symbols'
|
mastodon_name = "@not_enough_at_symbols"
|
||||||
with self.subTest("Missing '@' separator"):
|
with self.subTest("Missing '@' separator"):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
data_model.Connection.MastodonUname2Url(mastodon_name)
|
data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
|
|
||||||
mastodon_name = 'user@bad_domain.example'
|
mastodon_name = "user@bad_domain.example"
|
||||||
with self.subTest("Underscore in domain portion"):
|
with self.subTest("Underscore in domain portion"):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
data_model.Connection.MastodonUname2Url(mastodon_name)
|
data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
|
|
||||||
mastodon_name = 'user@bad.numeric.tld.123'
|
mastodon_name = "user@bad.numeric.tld.123"
|
||||||
with self.subTest("All digit TLD"):
|
with self.subTest("All digit TLD"):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
data_model.Connection.MastodonUname2Url(mastodon_name)
|
data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
|
|
||||||
mastodon_name = 'a_tooter@example.exchange.'
|
mastodon_name = "a_tooter@example.exchange."
|
||||||
expected = HttpUrl("https://example.exchange./@a_tooter")
|
expected = HttpUrl("https://example.exchange./@a_tooter")
|
||||||
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
result = data_model.Connection.MastodonUname2Url(mastodon_name)
|
||||||
with self.subTest("With FQDN root '.'"):
|
with self.subTest("With FQDN root '.'"):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue