mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
File fixes for ruff B007, RUF015, PLR1722
This commit is contained in:
parent
cbe6c08f44
commit
9b77a9027b
5 changed files with 48 additions and 51 deletions
|
|
@ -108,15 +108,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
self.assertTrue(self.posts)
|
||||
for (
|
||||
title,
|
||||
content,
|
||||
fname,
|
||||
date,
|
||||
author,
|
||||
categ,
|
||||
tags,
|
||||
status,
|
||||
kind,
|
||||
format,
|
||||
_content,
|
||||
_fname,
|
||||
_date,
|
||||
_author,
|
||||
_categ,
|
||||
_tags,
|
||||
_status,
|
||||
_kind,
|
||||
_format,
|
||||
) in self.posts:
|
||||
self.assertTrue(title.strip())
|
||||
|
||||
|
|
@ -127,15 +127,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
pages_data = []
|
||||
for (
|
||||
title,
|
||||
content,
|
||||
_content,
|
||||
fname,
|
||||
date,
|
||||
author,
|
||||
categ,
|
||||
tags,
|
||||
status,
|
||||
_date,
|
||||
_author,
|
||||
_categ,
|
||||
_tags,
|
||||
_status,
|
||||
kind,
|
||||
format,
|
||||
_format,
|
||||
) in self.posts:
|
||||
if kind == "page":
|
||||
pages_data.append((title, fname))
|
||||
|
|
@ -147,7 +147,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
silent_f2p = mute(True)(fields2pelican)
|
||||
test_post = filter(lambda p: p[0].startswith("Empty Page"), self.posts)
|
||||
with temporary_folder() as temp:
|
||||
fname = list(silent_f2p(test_post, "markdown", temp, dirpage=True))[0]
|
||||
fname = next(iter(silent_f2p(test_post, "markdown", temp, dirpage=True)))
|
||||
self.assertTrue(fname.endswith("pages%sempty.md" % os.path.sep))
|
||||
|
||||
def test_dircat(self):
|
||||
|
|
@ -176,15 +176,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
pages_data = []
|
||||
for (
|
||||
title,
|
||||
content,
|
||||
_content,
|
||||
fname,
|
||||
date,
|
||||
author,
|
||||
categ,
|
||||
tags,
|
||||
status,
|
||||
_date,
|
||||
_author,
|
||||
_categ,
|
||||
_tags,
|
||||
_status,
|
||||
kind,
|
||||
format,
|
||||
_format,
|
||||
) in self.posts:
|
||||
if kind in {"page", "article"}:
|
||||
pass
|
||||
|
|
@ -197,15 +197,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
cust_data = []
|
||||
for (
|
||||
title,
|
||||
content,
|
||||
fname,
|
||||
date,
|
||||
author,
|
||||
categ,
|
||||
tags,
|
||||
status,
|
||||
_content,
|
||||
_fname,
|
||||
_date,
|
||||
_author,
|
||||
_categ,
|
||||
_tags,
|
||||
_status,
|
||||
kind,
|
||||
format,
|
||||
_format,
|
||||
) in self.custposts:
|
||||
if kind in {"page", "article"}:
|
||||
pass
|
||||
|
|
@ -346,7 +346,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
silent_f2p = mute(True)(fields2pelican)
|
||||
test_post = filter(lambda p: p[0].startswith("Code in List"), self.posts)
|
||||
with temporary_folder() as temp:
|
||||
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
|
||||
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
|
||||
self.assertTrue(re.search(r"\s+a = \[1, 2, 3\]", md))
|
||||
self.assertTrue(re.search(r"\s+b = \[4, 5, 6\]", md))
|
||||
|
||||
|
|
@ -362,7 +362,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
silent_f2p = mute(True)(fields2pelican)
|
||||
test_post = filter(lambda p: p[0].startswith("Code in List"), self.posts)
|
||||
with temporary_folder() as temp:
|
||||
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
|
||||
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
|
||||
sample_line = re.search(r"- This is a code sample", md).group(0)
|
||||
code_line = re.search(r"\s+a = \[1, 2, 3\]", md).group(0)
|
||||
self.assertTrue(sample_line.rindex("This") < code_line.rindex("a"))
|
||||
|
|
@ -375,7 +375,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
silent_f2p = mute(True)(fields2pelican)
|
||||
test_post = filter(lambda p: p[0].startswith("Post with raw data"), self.posts)
|
||||
with temporary_folder() as temp:
|
||||
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
|
||||
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
|
||||
escaped_quotes = re.search(r'\\[\'"“”‘’]', md)
|
||||
self.assertFalse(escaped_quotes)
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
|
|||
silent_f2p = mute(True)(fields2pelican)
|
||||
test_post = filter(lambda p: p[0].startswith("Caption on image"), self.posts)
|
||||
with temporary_folder() as temp:
|
||||
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
|
||||
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
|
||||
|
||||
caption = re.search(r"\[caption", md)
|
||||
self.assertFalse(caption)
|
||||
|
|
|
|||
|
|
@ -210,13 +210,10 @@ class TestUtils(LoggedTestCase):
|
|||
)
|
||||
|
||||
# check with preserve case
|
||||
for value, expected in samples:
|
||||
self.assertEqual(
|
||||
utils.slugify(
|
||||
"Çığ", regex_subs=subs, preserve_case=True, use_unicode=True
|
||||
),
|
||||
"Çığ",
|
||||
)
|
||||
self.assertEqual(
|
||||
utils.slugify("Çığ", regex_subs=subs, preserve_case=True, use_unicode=True),
|
||||
"Çığ",
|
||||
)
|
||||
|
||||
# check normalization
|
||||
samples = (
|
||||
|
|
|
|||
|
|
@ -1070,14 +1070,14 @@ def fields2pelican(
|
|||
rc = subprocess.call(cmd, shell=True)
|
||||
if rc < 0:
|
||||
error = "Child was terminated by signal %d" % -rc
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
|
||||
elif rc > 0:
|
||||
error = "Please, check your Pandoc installation."
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
except OSError as e:
|
||||
error = "Pandoc execution failed: %s" % e
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
|
||||
with open(out_filename, encoding="utf-8") as fs:
|
||||
content = fs.read()
|
||||
|
|
@ -1222,18 +1222,18 @@ def main():
|
|||
"You must provide one of --blogger, --dotclear, "
|
||||
"--medium, --tumblr, --wpfile or --feed options"
|
||||
)
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
|
||||
if not os.path.exists(args.output):
|
||||
try:
|
||||
os.mkdir(args.output)
|
||||
except OSError:
|
||||
error = "Unable to create the output folder: " + args.output
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
|
||||
if args.wp_attach and input_type != "wordpress":
|
||||
error = "You must be importing a wordpress xml to use the --wp-attach option"
|
||||
exit(error)
|
||||
sys.exit(error)
|
||||
|
||||
if input_type == "blogger":
|
||||
fields = blogger2fields(args.input)
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ class _HTMLWordTruncator(HTMLParser):
|
|||
def getoffset(self) -> int:
|
||||
line_start = 0
|
||||
lineno, line_offset = self.getpos()
|
||||
for i in range(lineno - 1):
|
||||
for _ in range(lineno - 1):
|
||||
line_start = self.rawdata.index("\n", line_start) + 1
|
||||
return line_start + line_offset
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class Writer:
|
|||
}
|
||||
|
||||
# generated pages, and write
|
||||
for page_num in range(list(paginators.values())[0].num_pages):
|
||||
for page_num in range(next(iter(paginators.values())).num_pages):
|
||||
paginated_kwargs = kwargs.copy()
|
||||
for key in paginators.keys():
|
||||
paginator = paginators[key]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue