Nuked a todo and corrected a bunch of tests

This commit is contained in:
Maximilien Rigaut 2022-06-07 02:07:12 +02:00
parent 2eea57e9fa
commit 62f3adb289
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
13 changed files with 86 additions and 67 deletions

View File

@ -1,19 +1,25 @@
#!/usr/bin/python3
# Main program, use this to start parsing
import rich
from bootstraparse.modules import sitecreator
import argparse
import sys
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="bootstraparse", description='Parses a folder for all .bpr files and '
'magically recreates the same architecture '
'with html translated files.')
def parse(_args):
parser = argparse.ArgumentParser(
prog="bootstraparse",
description='Parses a folder for all .bpr files and magically recreates the same architecture '
'with html translated files.'
)
parser.add_argument('origin', help='the root folder of all files to parse.')
parser.add_argument('destination', help="path of the folder where to output all the magic.")
# parser.add_argument("-v", "verbosity")
args = parser.parse_args()
if sitecreator.create_website(args.origin, args.destination) == 0:
rich.print("Bootstraparse run successful!")
return parser.parse_args(_args)
if __name__ == "__main__": # pragma: no cover
args = parse(sys.argv[1:])
if sitecreator.create_website(args.origin, args.destination) == 0:
print("Bootstraparse run successful!")

View File

@ -132,7 +132,7 @@ class ConfigLoader:
# def __init__(self, config_folder):
# super().__init__(config_folder)
if __name__ == '__main__':
if __name__ == '__main__': # pragma: no cover
conf = ConfigLoader("../configs/")
conf.add_folder("../../../example_userfiles/config/")
rich.inspect(conf)

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
@ -200,8 +199,10 @@ class EtCustomSpanContainer(BaseContainer):
class ReContextContainer(BaseContainer):
children = ""
def get_content(self, exm, arbitrary_list=None):
child_start, child_end = exm(export.ExportRequest(self.type, self.children))
child_start, child_end = exm(export.ExportRequest(self.type, self.children)) # noqa: F841
output = "\n"
for element in self.content:
if isinstance(element, syntax.Linebreak):
@ -357,6 +358,7 @@ class ContextManager:
"table:row": ["table:separator", "table:row"], # TODO: Implement tables
"blockquotes": [] # TODO: Implement blockquotes
}
self.contextualised = False
def encapsulate(self, start, end):
"""
@ -433,6 +435,8 @@ class ContextManager:
Returns the pile entirely processed as a list of containers.
"""
# self.pile = self.parsed_list.copy()
if self.contextualised:
return self.pile
index = 0
line_number = 1
while index < len(self.parsed_list):
@ -477,6 +481,7 @@ class ContextManager:
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
index += 1
self.contextualised = True
return self.finalize_pile()
def __iter__(self):

View File

@ -48,10 +48,8 @@ class ExportManager:
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
"""
def __init__(self, cnoifg, templates): # noqa
# self.config = cnoifg TODO: actually import config
# self.templates = templates # noqa TODO: actually import templates
self.config = config.ConfigLoader(pathresolver.b_path("configs/"))
self.templates = config.ConfigLoader(pathresolver.b_path("templates/"))
self.config = cnoifg
self.templates = templates
self.advanced_export = {
"header": self.header_transform,
"display": self.display_transform,
@ -247,7 +245,9 @@ if __name__ == '__main__': # pragma: no cover
"""[this is a link]('http://te.st')"""
)
test = parser.parse_line(io_string)
exm = ExportManager(None, None)
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
exm = ExportManager(None, None, __config, __templates)
cxm = context_mngr.ContextManager(test)
cxc = ContextConverter(cxm(), exm)
rich.inspect(cxc)

View File

@ -366,11 +366,13 @@ class PreParser:
if __name__ == "__main__": # pragma: no cover
from bootstraparse.modules import config
from bootstraparse.modules import pathresolver
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
site_path = pathresolver.b_path("../../example_userfiles/test.bpr")
config_path = pathresolver.b_path("../../example_userfiles/config/")
_env = environment.Environment()
_env.config = config.ConfigLoader(config_path)
_env.export_mngr = export.ExportManager('', '')
_env.export_mngr = export.ExportManager(__config, __templates)
t_pp = PreParser(site_path, _env)
out = t_pp.do_replacements()
rich.print(t_pp.get_all_lines())

View File

@ -1,6 +1,5 @@
# Module for file and directories repartition
import os
import rich
from bootstraparse.modules import pathresolver, preparser, error_mngr, environment, export
@ -79,12 +78,13 @@ class SiteCrawler:
if __name__ == "__main__":
from bootstraparse.modules import config
from bootstraparse.modules import pathresolver
site_path = pathresolver.b_path("../../example_userfiles/test.bpr")
config_path = pathresolver.b_path("../../example_userfiles/configs/")
_env = environment.Environment()
_env.config = config.ConfigLoader(config_path)
_env.export_mngr = export.ExportManager('', '')
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
_env.export_mngr = export.ExportManager('', '', __config, __templates)
xpath = pathresolver.b_path("../../example_userfiles")
dpath = pathresolver.b_path("../../example_output")
sc = SiteCrawler(xpath, dpath, _env)

View File

@ -1,6 +1,5 @@
# 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
@ -62,4 +61,3 @@ if __name__ == "__main__":
xpath = pathresolver.b_path("../../example_userfiles")
dpath = pathresolver.b_path("../../example_output")
create_website(xpath, dpath)

View File

@ -160,19 +160,19 @@ _token_list_with_expected_result = [
],
[
context_mngr.EtUlistContainer([
sy.EtUlistToken([sy.TextToken(["a"])]),
sy.EtUlistToken([context_mngr.TextContainer([sy.TextToken(["a"])])]),
sy.Linebreak([]),
sy.EtUlistToken([sy.TextToken(["b"])]),
sy.EtUlistToken([context_mngr.TextContainer([sy.TextToken(["b"])])]),
sy.Linebreak([]),
sy.EtUlistToken([sy.TextToken(["c"])]),
sy.EtUlistToken([sy.TextToken(["d"])]),
sy.EtUlistToken([context_mngr.TextContainer([sy.TextToken(["c"])])]),
sy.EtUlistToken([context_mngr.TextContainer([sy.TextToken(["d"])])]),
]),
context_mngr.EtUlistContainer([
sy.EtOlistToken([sy.TextToken(["aa"])]),
sy.EtOlistToken([sy.TextToken(["bb"])]),
sy.EtOlistToken([sy.TextToken(["cc"])]),
context_mngr.EtOlistContainer([
sy.EtOlistToken([context_mngr.TextContainer([sy.TextToken(["aa"])])]),
sy.EtOlistToken([context_mngr.TextContainer([sy.TextToken(["bb"])])]),
sy.EtOlistToken([context_mngr.TextContainer([sy.TextToken(["cc"])])]),
sy.Linebreak([]),
sy.EtOlistToken([sy.TextToken(["dd"])]),
sy.EtOlistToken([context_mngr.TextContainer([sy.TextToken(["dd"])])]),
sy.Linebreak([]),
]),
context_mngr.LinebreakContainer([sy.Linebreak([])]),
@ -416,10 +416,10 @@ _token_list_with_expected_result = [
],
[
context_mngr.EtOlistContainer([
sy.EtOlistToken([sy.TextToken(["a"])]),
sy.EtOlistToken([context_mngr.TextContainer([sy.TextToken(["a"])])]),
], _opts),
context_mngr.EtOlistContainer([
sy.EtUlistToken([sy.TextToken(["b"])]),
context_mngr.EtUlistContainer([
sy.EtUlistToken([context_mngr.TextContainer([sy.TextToken(["b"])])]),
], _opts),
],
__GLk(1),
@ -631,7 +631,10 @@ def test_context_call(init_list, expected, file_line):
print(f"Executing tests @{file_line}")
ctx = context_mngr.ContextManager(init_list) # noqa : F841
if isinstance(expected[0], context_mngr.BaseContainer) or isinstance(expected[0], sy.SemanticType):
assert ctx() == expected
for i, e in zip(ctx(), expected):
rich.inspect(i)
rich.inspect(e)
assert i == e
else:
with pytest.raises(expected[0]):
ctx()
@ -644,7 +647,10 @@ def test_content_call_raises():
def test_export_error():
em = export.ExportManager(None, None)
from bootstraparse.modules import config, pathresolver
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
em = export.ExportManager(__config, __templates)
with pytest.raises(TypeError):
context_mngr.TextContainer([sy.TextToken(['e']), None]).export(em)

View File

@ -3,6 +3,8 @@ import pytest
from bootstraparse.modules import context_mngr, export
from bootstraparse.modules import syntax as sy #sy.SemanticType, sy.TextToken, sy.Linebreak, sy.StructuralElementStartToken, sy.StructuralElementEndToken, sy.EtUlistToken, sy.EtOlistToken # noqa
from bootstraparse.modules.tools import __GLk
from bootstraparse.modules import config, pathresolver
__XF = pytest.mark.xfail
_opts = sy.OptionalToken([
sy.OptionalVarToken([
@ -15,7 +17,8 @@ _opts = sy.OptionalToken([
class FalseHyperlink(list):
url = "http://test.com"
content = ["test"]
content = ["test9"]
text = "test9"
_list_classes_expected_value = [
@ -81,9 +84,8 @@ _list_classes_expected_value = [
]),
]),
]),
"<ul><li>test7</li></ul>",
"<ul>\n<li>test7</li></ul>",
__GLk(1),
__XF,
],
[
context_mngr.EtOlistContainer([
@ -93,16 +95,12 @@ _list_classes_expected_value = [
]),
]),
]),
"<ol><li>test8</li></ol>",
"<ol>\n<li>test8</li></ol>",
__GLk(1),
__XF,
],
[
context_mngr.HyperLinkContainer([
sy.HyperlinkToken(FalseHyperlink(['test9'])),
context_mngr.TextContainer([
sy.TextToken(['test9']),
]),
]),
"<a href=\"http://test.com\">test9</a>",
__GLk(1),
@ -130,20 +128,14 @@ _list_classes_expected_value = [
],
[
context_mngr.DisplayContainer([
sy.DisplayToken(["!"]),
context_mngr.TextContainer([
sy.TextToken(['test12']),
]),
sy.DisplayToken(["!", "test12"]),
]),
"<p class=\"display-1\">test12</p>",
__GLk(1),
],
[
context_mngr.DisplayContainer([
sy.DisplayToken(["!!"]),
context_mngr.TextContainer([
sy.TextToken(['test13']),
]),
sy.DisplayToken(["!!", "test13"]),
]),
"<p class=\"display-2\">test13</p>",
__GLk(1),
@ -197,15 +189,14 @@ _list_classes_expected_value = [
_opts,
]),
]),
"<ol><li>test13</li></ol>",
"<ol>\n<li>test13</li></ol>",
__GLk(1),
__XF,
],
[
context_mngr.LinebreakContainer([
sy.Linebreak([""]),
]),
"<br/>\n",
"\n",
__GLk(1),
],
@ -219,6 +210,8 @@ _zipped_list_classes_expected_value = [
@pytest.mark.parametrize("container, export_v, line", _zipped_list_classes_expected_value)
def test_container_export_value(container, export_v, line):
print(line)
em = export.ExportManager(None, None)
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
em = export.ExportManager(__config, __templates)
assert isinstance(container, context_mngr.BaseContainer)
assert container.export(em) == export_v

View File

@ -3,9 +3,11 @@ from itertools import zip_longest
import bootstraparse.modules.export as export
import pytest
from bootstraparse.modules import context_mngr, syntax
from bootstraparse.modules import context_mngr, syntax, config, pathresolver
from bootstraparse.modules.tools import __GLk
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
__XF = pytest.mark.xfail
_all_templates = {
@ -53,7 +55,7 @@ def test_export():
"""
Test the export module
"""
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
assert type(em) is export.ExportManager
@ -90,7 +92,7 @@ def test_transform(export_type, export_subtype):
"""
Test the transform method
"""
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
re = em.transform(export.ExportRequest(export_type, export_subtype, "", { # noqa E741
"header_level": "1",
"display_level": "1",
@ -110,12 +112,12 @@ def test_transform(export_type, export_subtype):
def test_get_template_error():
with pytest.raises(KeyError):
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
em(export.ExportRequest("nope", "header", "", {}))
def test_with_optionnals():
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
em(export.ExportRequest("structural_elements", "div", _opts)) # noqa E741
@ -138,14 +140,14 @@ def test_return_values():
def test_bad_header():
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
with pytest.raises(KeyError):
em(export.ExportRequest("structural_elements", "header", "", {}))
@pytest.mark.parametrize("export_type, export_subtype, line", zipped_templates)
def test_get_templates(export_type, export_subtype, line):
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
# assert type(em.get_templates()) is dict
print(export_type, export_subtype)
r = em(export.ExportRequest(export_type, export_subtype, "", {
@ -167,7 +169,7 @@ def test_get_templates(export_type, export_subtype, line):
def test_context_cov():
em = export.ExportManager("test", "test")
em = export.ExportManager(__config, __templates)
lst = [context_mngr.TextContainer([syntax.TextToken("test")])]
# base = context_mngr.ContextManager(lst)

View File

@ -16,9 +16,11 @@ from bootstraparse.modules import export
# Environment variables
env = environment.Environment()
env.export_mngr = export.ExportManager('', '')
# env.export_mngr = export.ExportManager('', '')
env.config = config.ConfigLoader(pathresolver.b_path("../../example_userfiles/configs/"))
env.export_mngr = export.ExportManager('', '')
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
env.export_mngr = export.ExportManager(__config, __templates)
_BASE_PATH_PREPARSER = "../../"
_TEMP_DIRECTORY = tempfile.TemporaryDirectory()

View File

@ -1,6 +1,8 @@
import bootstraparse.modules.sitecreator as sitecreator
import pytest
@pytest.mark.xfail(reason="TODO")
def test_create_site():
sitecreator.create_website()
sitecreator.create_environment()

View File

@ -1,6 +1,9 @@
# Test the base parser
from bootstraparse import __main__
def test_to_test():
assert bparse.to_test() is None
args = __main__.parse(["path1", "path2"])
assert args.origin == "path1"
assert args.destination == "path2"