Updated a couple tests
This commit is contained in:
parent
edaf2c1036
commit
dc88df4f17
|
|
@ -242,9 +242,9 @@ class DisplayContainer(BaseContainer):
|
|||
subtype = "display"
|
||||
|
||||
def export(self, exm):
|
||||
self.others = {}
|
||||
# self.others = {}
|
||||
self.others["display_level"] = len(self.content[0].content[0])
|
||||
super().export(exm)
|
||||
return super().export(exm)
|
||||
|
||||
|
||||
class TableSeparatorContainer(BaseContainer):
|
||||
|
|
@ -415,31 +415,38 @@ class ContextManager:
|
|||
token.line_number = line_number
|
||||
self.pile.append(token)
|
||||
try:
|
||||
if isinstance(token, syntax.Linebreak): # linebreaks
|
||||
# Linebreaks
|
||||
if isinstance(token, syntax.Linebreak):
|
||||
self.encapsulate(index, index)
|
||||
line_number += 1
|
||||
|
||||
# Pack the optionnal with the previous container if it exists (else raise error)
|
||||
elif isinstance(token, syntax.OptionalToken):
|
||||
self.get_last_container_in_pile(index).optionals = token
|
||||
self.pile[index] = None
|
||||
|
||||
elif token.label in self.dict_lookahead: # group together multiple one-lines
|
||||
# Group together multiple one-lines
|
||||
elif token.label in self.dict_lookahead:
|
||||
lookahead_return = self.lookahead(token, index)
|
||||
index += lookahead_return[0]
|
||||
line_number += lookahead_return[1]
|
||||
|
||||
# elif token.label in self.dict_advanced_lookahead: # TODO: advanced lookahead for * logic
|
||||
# TODO: advanced lookahead for * logic
|
||||
# elif token.label in self.dict_advanced_lookahead:
|
||||
|
||||
elif isinstance(token, syntax.FinalSemanticType): # one-liners
|
||||
self.encapsulate(index, index)
|
||||
|
||||
elif token.counterpart() in self.matched_elements and len(self.matched_elements[token.counterpart()]) != 0: # found a matching token in encountered tokens
|
||||
# Found a matching token in encountered tokens
|
||||
elif token.counterpart() in self.matched_elements and len(self.matched_elements[token.counterpart()]) != 0:
|
||||
self.encapsulate(self._get_matched(token.counterpart()), index)
|
||||
|
||||
elif isinstance(token, syntax.ClosedSemanticType): # error if closing token does not have a start
|
||||
# Error if closing token does not have a start
|
||||
elif isinstance(token, syntax.ClosedSemanticType):
|
||||
raise MismatchedContainerError(token)
|
||||
|
||||
else: # starting token by default (can cause unintended behaviours on bad implementations) # TODO: remove this default behaviour, error instead
|
||||
# Starting token by default (can cause unintended behaviours on bad implementations)
|
||||
else: # TODO: remove this default behaviour, error instead
|
||||
self._add_matched(token.label, index)
|
||||
except MismatchedContainerError as e:
|
||||
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import os
|
|||
from itertools import zip_longest
|
||||
from collections import namedtuple
|
||||
|
||||
import rich
|
||||
|
||||
from bootstraparse.modules.error_mngr import MismatchedContainerError
|
||||
from bootstraparse.modules import context_mngr as cm
|
||||
import pyparsing as pp
|
||||
|
|
@ -365,7 +363,6 @@ def split_optionals(optionals):
|
|||
elif element.label == 'optional:insert':
|
||||
hi += " " + element.content[0]
|
||||
elif element.label == 'optional:var':
|
||||
rich.inspect(optionals)
|
||||
for e in element.content:
|
||||
if e.label == 'be:var':
|
||||
var_list.append(e.content[0])
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ _list_classes = [
|
|||
context_mngr.LinebreakContainer,
|
||||
]
|
||||
|
||||
_base_list = [sy.TextToken([1]), sy.TextToken([2]), sy.TextToken([3]), sy.TextToken([4])]
|
||||
_base_list = [sy.TextToken(["1"]), sy.TextToken(["2"]), sy.TextToken(["3"]), sy.TextToken(["4"])]
|
||||
_opts = sy.OptionalToken([
|
||||
sy.OptionalVarToken([
|
||||
sy.BeAssignToken([["class", "blue"]]),
|
||||
|
|
@ -45,20 +45,20 @@ _others = {
|
|||
|
||||
_token_list_with_expected_result = [
|
||||
[
|
||||
[sy.TextToken([1])],
|
||||
[context_mngr.TextContainer([sy.TextToken([1])])],
|
||||
[sy.TextToken(["1"])],
|
||||
[context_mngr.TextContainer([sy.TextToken(["1"])])],
|
||||
__GLk(1),
|
||||
],
|
||||
[
|
||||
[
|
||||
sy.StructuralElementStartToken(["div"]),
|
||||
sy.TextToken([1]),
|
||||
sy.TextToken(["1"]),
|
||||
sy.StructuralElementEndToken(["div"]),
|
||||
],
|
||||
[
|
||||
context_mngr.SeContainer([
|
||||
sy.StructuralElementStartToken(["div"]),
|
||||
context_mngr.TextContainer([sy.TextToken([1])]),
|
||||
context_mngr.TextContainer([sy.TextToken(["1"])]),
|
||||
sy.StructuralElementEndToken(["div"])
|
||||
]),
|
||||
],
|
||||
|
|
@ -154,7 +154,7 @@ _token_list_with_expected_result = [
|
|||
sy.EtOlistToken([sy.TextToken(["dd"])]),
|
||||
sy.Linebreak([]),
|
||||
sy.Linebreak([]),
|
||||
sy.TextToken([1]),
|
||||
sy.TextToken(["1"]),
|
||||
sy.Linebreak([]),
|
||||
sy.TextToken([2]),
|
||||
],
|
||||
|
|
@ -176,7 +176,7 @@ _token_list_with_expected_result = [
|
|||
sy.Linebreak([]),
|
||||
]),
|
||||
context_mngr.LinebreakContainer([sy.Linebreak([])]),
|
||||
context_mngr.TextContainer([sy.TextToken([1])]),
|
||||
context_mngr.TextContainer([sy.TextToken(["1"])]),
|
||||
context_mngr.LinebreakContainer([sy.Linebreak([])]),
|
||||
context_mngr.TextContainer([sy.TextToken([2])]),
|
||||
],
|
||||
|
|
@ -191,10 +191,9 @@ _token_list_with_expected_result = [
|
|||
context_mngr.HyperLinkContainer([
|
||||
sy.HyperlinkToken(["a", "href", "http://test.com"]),
|
||||
]),
|
||||
sy.TextToken(["a"]),
|
||||
context_mngr.TextContainer([sy.TextToken(["a"])]),
|
||||
],
|
||||
__GLk(1),
|
||||
__XF,
|
||||
],
|
||||
[
|
||||
[
|
||||
|
|
@ -477,7 +476,7 @@ def test_container_init(cls):
|
|||
|
||||
|
||||
def test_context_manager(base_cm):
|
||||
lst = [sy.SemanticType([1]), sy.SemanticType([2]), sy.SemanticType([3])]
|
||||
lst = [sy.SemanticType(["1"]), sy.SemanticType([2]), sy.SemanticType([3])]
|
||||
base = context_mngr.ContextManager(lst)
|
||||
base.pile = lst
|
||||
|
||||
|
|
@ -644,14 +643,6 @@ def test_content_call_raises():
|
|||
ctx()
|
||||
|
||||
|
||||
@pytest.mark.xfail(reason="Not implemented")
|
||||
@pytest.mark.parametrize("container", _list_classes)
|
||||
def test_container_export(container, base_cm):
|
||||
em = export.ExportManager(None, None)
|
||||
assert type(container().export(em)) == str
|
||||
assert container(_base_list).export(em) == str
|
||||
|
||||
|
||||
def test_export_error():
|
||||
em = export.ExportManager(None, None)
|
||||
with pytest.raises(TypeError):
|
||||
|
|
|
|||
|
|
@ -104,19 +104,19 @@ _list_classes_expected_value = [
|
|||
sy.TextToken(['test9']),
|
||||
]),
|
||||
]),
|
||||
"<a href=\"test9\">test9</a>",
|
||||
"<a href=\"http://test.com\">test9</a>",
|
||||
__GLk(1),
|
||||
__XF,
|
||||
],
|
||||
[
|
||||
context_mngr.SeContainer([
|
||||
sy.StructuralElementStartToken(["div"]),
|
||||
context_mngr.TextContainer([
|
||||
sy.TextToken(['test10']),
|
||||
]),
|
||||
sy.StructuralElementEndToken(["div"]),
|
||||
]),
|
||||
"<div>test10</div>",
|
||||
__GLk(1),
|
||||
__XF,
|
||||
],
|
||||
[
|
||||
context_mngr.HeaderContainer([
|
||||
|
|
@ -130,26 +130,34 @@ _list_classes_expected_value = [
|
|||
],
|
||||
[
|
||||
context_mngr.DisplayContainer([
|
||||
sy.DisplayToken("!"),
|
||||
sy.DisplayToken(["!"]),
|
||||
context_mngr.TextContainer([
|
||||
sy.TextToken(['test12']),
|
||||
]),
|
||||
]),
|
||||
"<display>test12</display>",
|
||||
"<p class=\"display-1\">test12</p>",
|
||||
__GLk(1),
|
||||
__XF,
|
||||
],
|
||||
[
|
||||
[
|
||||
context_mngr.TableRowContainer([
|
||||
context_mngr.TableCellContainer([
|
||||
context_mngr.TextContainer([sy.TextToken(["a"])]),
|
||||
]),
|
||||
context_mngr.TableCellContainer([
|
||||
context_mngr.TextContainer([sy.TextToken(["b"])]),
|
||||
]),
|
||||
context_mngr.DisplayContainer([
|
||||
sy.DisplayToken(["!!"]),
|
||||
context_mngr.TextContainer([
|
||||
sy.TextToken(['test13']),
|
||||
]),
|
||||
],
|
||||
]),
|
||||
"<p class=\"display-2\">test13</p>",
|
||||
__GLk(1),
|
||||
],
|
||||
[
|
||||
|
||||
context_mngr.TableRowContainer([
|
||||
context_mngr.TableCellContainer([
|
||||
context_mngr.TextContainer([sy.TextToken(["a"])]),
|
||||
]),
|
||||
context_mngr.TableCellContainer([
|
||||
context_mngr.TextContainer([sy.TextToken(["b"])]),
|
||||
]),
|
||||
]),
|
||||
"<table><tr><td>a</td><td>b</td></tr></table>",
|
||||
__GLk(1),
|
||||
__XF,
|
||||
|
|
@ -181,20 +189,25 @@ _list_classes_expected_value = [
|
|||
__XF,
|
||||
],
|
||||
[
|
||||
[
|
||||
context_mngr.EtOlistContainer([
|
||||
sy.EtOlistToken([
|
||||
context_mngr.TextContainer([
|
||||
sy.TextToken(['test13']),
|
||||
]),
|
||||
_opts,
|
||||
context_mngr.EtOlistContainer([
|
||||
sy.EtOlistToken([
|
||||
context_mngr.TextContainer([
|
||||
sy.TextToken(['test13']),
|
||||
]),
|
||||
_opts,
|
||||
]),
|
||||
],
|
||||
]),
|
||||
"<ol><li>test13</li></ol>",
|
||||
__GLk(1),
|
||||
__XF,
|
||||
],
|
||||
[
|
||||
context_mngr.LinebreakContainer([
|
||||
sy.Linebreak([""]),
|
||||
]),
|
||||
"<br/>\n",
|
||||
__GLk(1),
|
||||
],
|
||||
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -119,11 +119,18 @@ def test_with_optionnals():
|
|||
em(export.ExportRequest("structural_elements", "div", _opts)) # noqa E741
|
||||
|
||||
|
||||
@pytest.mark.xfail(reason="Not implemented")
|
||||
def test_format_optionnals():
|
||||
from bootstraparse.modules import syntax # noqa E402
|
||||
export.format_optionals(_opts)
|
||||
assert False
|
||||
op = export.format_optionals(_opts)
|
||||
expected = syntax.OptionalToken([
|
||||
syntax.OptionalVarToken([
|
||||
syntax.BeAssignToken([["class", "blue"]]),
|
||||
syntax.BeValueToken([123]),
|
||||
]),
|
||||
syntax.OptionalInsertToken(["var='test', number=11"]),
|
||||
])
|
||||
assert expected == _opts
|
||||
assert op == " var='test', number=11"
|
||||
|
||||
|
||||
def test_return_values():
|
||||
|
|
|
|||
|
|
@ -914,3 +914,27 @@ def test_empty_token():
|
|||
"""Test that empty tokens are correctly dropped."""
|
||||
|
||||
assert sy.of_type(sy.EmptySemanticType)("", [], []) is None
|
||||
|
||||
|
||||
def test_split_optionals():
|
||||
"""Test that optional tokens are correctly split."""
|
||||
opts = sy.OptionalToken([
|
||||
sy.OptionalVarToken([
|
||||
sy.BeAssignToken([["class", "blue"]]),
|
||||
sy.BeValueToken([123]),
|
||||
]),
|
||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||
sy.OptionalClassToken(["cinsertBlue"]),
|
||||
])
|
||||
spl = sy.split_optionals(opts)
|
||||
print(spl)
|
||||
assert type(spl) is sy.SplitOptionals
|
||||
assert len(spl) == 4
|
||||
assert spl[0] == "var='test', number=11"
|
||||
assert spl[1] == "cinsertBlue"
|
||||
assert spl[2] == [123]
|
||||
assert spl[3] == {'class': 'blue'}
|
||||
assert spl.html_insert == "var='test', number=11"
|
||||
assert spl.class_insert == "cinsertBlue"
|
||||
assert spl.var_list == [123]
|
||||
assert spl.var_dict == {'class': 'blue'}
|
||||
|
|
|
|||
Loading…
Reference in New Issue