This commit is contained in:
Maximilien Rigaut 2022-06-07 20:24:37 +02:00
parent c5b94730e0
commit 3e910f5c95
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
11 changed files with 22 additions and 17 deletions

View File

@ -36,7 +36,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest --cov-fail-under=100 -o xfail_strict=true --cov-report=term-missing .

View File

@ -11,7 +11,6 @@
# container = BaseContainer()
# container[number] -> The number element in the content
# "class_insert" >> container[number] -> Get an element from one of the mapped methods
import rich
from bootstraparse.modules import syntax, error_mngr, export
from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa
@ -316,7 +315,6 @@ class LinebreakContainer(BaseContainer):
return "<br />\n"*(len(self.content)-1)
"""
Dictionary of all correspondences between tokens and containers.
"""
@ -444,8 +442,8 @@ class ContextManager:
# self.pile = self.parsed_list.copy()
if self.contextualised:
return self.pile
index = 0
line_number = 1
index, line_number = 0, 1
while index < len(self.parsed_list):
token = self.parsed_list[index]
@ -521,7 +519,10 @@ class ContextManager:
line = "Undefined"
name = "Undefined"
log_exception(
TypeError(f"Encountered a non-container element in the pile during the final pass: {p}, at line {line} in file {name}."),
TypeError(
f"Encountered a non-container element in the pile during "
f"the final pass: {p}, at line {line} in file {name}."
),
level="CRITICAL"
)
self.pile = final_pile

View File

@ -182,7 +182,8 @@ class LonelyOptionalError(BootstraparseError):
self.name = None
if last_in_pile:
super().__init__(f"Could not match token {token} at line {self.line} with "
f"last element in pile {last_in_pile} at line {last_in_pile.line_number} in file {self.name}(not a container).")
f"last element in pile {last_in_pile} at line {last_in_pile.line_number} "
f"in file {self.name}(not a container).")
else:
super().__init__(f"Could not match token {token} at line {self.line} in file {self.name}"
f"as there was nothing in the pile.")

View File

@ -248,7 +248,8 @@ class PreParser:
validated_elements.append(f'[{key}]')
except KeyError:
error_mngr.log_exception(
KeyError(f"Could not find key {key} in dict config{''.join(validated_elements)} in configs {'; '.join(self._env.config.config_folders)}"),
KeyError(f"Could not find key {key} in dict config{''.join(validated_elements)} "
f"in configs {'; '.join(self._env.config.config_folders)}"),
level='CRITICAL'
)
return sub_dict

View File

@ -33,7 +33,6 @@ class SiteCrawler:
def get_all_paths(self):
self.files, self.directories = self.list_recursively(self.initial_path, self.initial_path)
print (self.files, self.directories)
def list_recursively(self, path, root):
files = []

View File

@ -1,8 +1,6 @@
# Module sequencing the successive actions necessary for website building
import os
import rich
from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr

View File

@ -678,3 +678,6 @@ def test_finalize_pile(base_cm):
base_cm.pile[0] = {}
with pytest.raises(TypeError):
base_cm.finalize_pile()
base_cm.pile[0] = sy.TextToken(['e'])
with pytest.raises(TypeError):
base_cm.finalize_pile()

View File

@ -44,7 +44,7 @@ Test content line 7
"""
content_page1 = """Test page1\nTest page1-2\nTest page1-3\n"""
content_page2 = """Test page2\n::< page1.bpr >"""
content_page3 = """Test page3\n::< subpages/page3.bpr > < subpages/spage4.bpr > <subpages/spage5.bpr > <subpages/spage6.bpr > < page4.bpr >"""
content_page3 = """Test page3\n::< subpages/page3.bpr > < subpages/spage4.bpr > <subpages/spage5.bpr > <subpages/spage6.bpr > < page4.bpr >""" # noqa: E501
content_page4 = """Test page4\n::< page5.bpr > < page6.bpr > < ../index.bpr >"""
content_page5 = """Test page5\n::"""
content_page6 = """Test page6\n::"""
@ -401,5 +401,5 @@ def test_make_replacement_errors():
assert pp.make_replacements("This is a test", "not_existing") == "This is a test"
assert pp.make_replacements("This is a test {}", "shortcuts") == "This is a test shortcuts"
assert pp.make_replacements("This is a test {}", "images") == "This is a test images"
assert pp.make_replacements("This is a test {} {} {image} {b}", 1, 2, image="images", b="b") == "This is a test 1 2 images b"
assert pp.make_replacements("This is a test {} {} {image} {b}", 1, 2, image="images", b="b") == "This is a test 1 2 images b" # noqa: E501
assert pp.make_replacements("This is a test {} {} {image} {b}", karm=3) == "This is a test {} {} {image} {b}"

View File

@ -16,7 +16,7 @@ files = [
("base/_noimport.bpr", "", ""),
("base/subtests/test4.bpr", "", ""),
("base/subtests/test5.bpr", "", ""),
("base/config/test6.yml", "", None),
("base/config/test6.bpr", "", None),
("base/config/test7.yml", "", None),
("base/templates/test8.yml", "", None),
]
@ -38,7 +38,8 @@ def list_files():
"""
List all files in the test directory
"""
return [(os.path.join(_DEST, make_new_file(file, content).split("/", 1)[1].replace(".bpr", ".html")), exp) for file, content, exp in files]
return [(os.path.join(_DEST, make_new_file(file, content).split("/", 1)[1].replace(".bpr", ".html")), exp)
for file, content, exp in files]
@pytest.fixture(scope="module")

View File

@ -37,7 +37,8 @@ def list_files():
"""
List all files in the test directory
"""
return [(os.path.join(_DEST, make_new_file(file, content).split("/", 1)[1].replace(".bpr", ".html")), exp) for file, content, exp in files]
return [(os.path.join(_DEST, make_new_file(file, content).split("/", 1)[1].replace(".bpr", ".html")), exp)
for file, content, exp in files]
@pytest.fixture(scope="module")

View File

@ -4,7 +4,7 @@ import pyparsing
import pytest
import bootstraparse.modules.syntax as sy
from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file # , find_functions_in_file, find_classes_in_file
from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file
ptp = pytest.param
__XF = pytest.mark.xfail