Couple of typos and tests
This commit is contained in:
parent
5178c0a274
commit
3d4c134479
|
|
@ -1,5 +1,4 @@
|
|||
# Module for final generation of the translated website
|
||||
import rich
|
||||
|
||||
from bootstraparse.modules import config, pathresolver, error_mngr
|
||||
from collections import namedtuple
|
||||
|
|
@ -74,6 +73,7 @@ class ExportManager:
|
|||
Function for initializing other transform functions.
|
||||
:return: start, end, optionals
|
||||
"""
|
||||
start, end, optionals = None, None, []
|
||||
try:
|
||||
start, end = self.templates["bootstrap"][export_request.type][export_request.subtype]
|
||||
except KeyError: # TODO: Test this in-depth
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from collections import namedtuple
|
|||
import pyparsing as pp
|
||||
# import rich
|
||||
import regex # future: remove regex
|
||||
import rich
|
||||
|
||||
pps = pp.Suppress
|
||||
|
||||
|
|
@ -220,6 +219,7 @@ def reparse(parse_element):
|
|||
|
||||
return _reparse
|
||||
|
||||
|
||||
"""
|
||||
Tuple for readabilty of attributes over other modules.
|
||||
"""
|
||||
|
|
@ -274,7 +274,7 @@ rgx_import_file = regex.compile(r'::( ?\< ?(?P<file_name>[\w\-._/]+) ?\>[ \s]*)+
|
|||
|
||||
# Base elements
|
||||
quotes = pp.Word(r""""'""")
|
||||
value = (pps(quotes) + pp.Word(pp.alphanums + r'.') + pps(pp.match_previous_literal(quotes)) ^
|
||||
value = (pps(quotes) + pp.Word(pp.alphanums + r'\._') + pps(pp.match_previous_literal(quotes)) ^
|
||||
pp.common.fnumber)("value")
|
||||
assignation = pp.Group(
|
||||
pp.common.identifier('var_name') + pps('=') + value('var_value')
|
||||
|
|
@ -282,7 +282,7 @@ assignation = pp.Group(
|
|||
text = pp.OneOrMore(pp.Word(pp.alphanums))('text').add_parse_action(of_type(TextToken))
|
||||
url_characters = pp.common.url
|
||||
|
||||
# Composite elements # TODO: stringed vars must accept space and underscore etc.
|
||||
# Composite elements
|
||||
var = pps('[') + pp.delimitedList(
|
||||
assignation.add_parse_action(of_type(BeAssignToken)) ^
|
||||
value.add_parse_action(of_type(BeValueToken))
|
||||
|
|
|
|||
|
|
@ -10,11 +10,13 @@ import rich
|
|||
|
||||
from bootstraparse.modules import preparser
|
||||
from bootstraparse.modules import environment
|
||||
from bootstraparse.modules import export
|
||||
|
||||
###############################################################################
|
||||
# Environment variables
|
||||
|
||||
env = environment.Environment()
|
||||
env.export_mngr = export.ExportManager('', '')
|
||||
_BASE_PATH_PREPARSER = "../../"
|
||||
_TEMP_DIRECTORY = tempfile.TemporaryDirectory()
|
||||
|
||||
|
|
@ -103,12 +105,12 @@ website_tree = {
|
|||
"pages/subpages/spage6.bpr": content_sub_page6,
|
||||
}
|
||||
|
||||
get_from_config = '''@{whatever_picture} {whatever_picture}
|
||||
get_from_config = '''@{whatever_picture} {whatever_picture} ["whateverpicture", i=42]
|
||||
@{picture}{class="shortcut", type=2, name="shortcut"}[type=33, name="shortcut"]{{classinsert}}
|
||||
@[shortcut]{class="picture", type=2, name="picture"}[type=33, name="picture"]{{hello}}
|
||||
'''
|
||||
final_from_config = """<img src='whatever_picture' whatever_picture/>
|
||||
<img src='picture' class="shortcut", type=2, name="shortcut" class="classinsert"/>
|
||||
final_from_config = """<img src="whatever_picture" whatever_picture/>
|
||||
<img src="picture" class="shortcut", type=2, name="shortcut" class="classinsert"/>
|
||||
<h1>shortcut</h1>
|
||||
"""
|
||||
|
||||
|
|
@ -361,7 +363,7 @@ def test_get_shortcut_from_config():
|
|||
pp = preparser.PreParser(from_config, env)
|
||||
pp.do_imports()
|
||||
pp.parse_shortcuts_and_images()
|
||||
assert pp.get_image_from_config("any_picture", "") == '''<img src='any_picture'/>'''
|
||||
assert pp.get_image_from_config("any_picture", "") == '''<img src="any_picture"/>'''
|
||||
assert pp.get_alias_from_config("any_shortcut", None) == "<h1>any_shortcut</h1>"
|
||||
assert assert_readlines_equals(pp.do_replacements().readlines(), final_from_config.split("\n")[:-1])
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ expressions_to_match = {
|
|||
# Base elements
|
||||
"quotes": ["'hi, there'", "'hi, there'"],
|
||||
"value": ["0.1", "'hello'"],
|
||||
"assignation": ["a=1", "a=1.33", "tr2='hu'"],
|
||||
"assignation": ["a=1", "a=1.33", "tr2='hu'", "val_2=2"],
|
||||
|
||||
# Composite elements
|
||||
"var": ['["a"]',
|
||||
|
|
@ -86,7 +86,7 @@ expressions_to_match = {
|
|||
|
||||
|
||||
# Pre_parser elements
|
||||
"image": ["@{image}{test=22}[a=12,22,c,d,ERE,r,3]", "@{image123_456}{a=12,22,c,d,ERE,r,3}",
|
||||
"image": ["@{image.png}{test=22}[a=12,22,c,d,ERE,r,3]", "@{image123_456}{a=12,22,c,d,ERE,r,3}",
|
||||
"@{image123_456}[a=12,22,c,d,ERE,r,3]"],
|
||||
"alias": ["@[alias]{test=22}[a=12,22,c,d,ERE,r,3]", "@[alias123_456]{a=12,22,c,d,ERE,r,3}",
|
||||
"@[alias123_456]{a=12,22,c,d,ERE,r,3]"],
|
||||
|
|
@ -141,8 +141,8 @@ dict_advanced_syntax_input_and_expected_output = {
|
|||
],
|
||||
"var": [
|
||||
# List of variables or assignations, should match "[a=12, b=13, 'c']"
|
||||
("[a=12, b=13, 'c']", [
|
||||
sy.BeAssignToken([["a", 12]]),
|
||||
("[a_12=12, b=13, 'c']", [
|
||||
sy.BeAssignToken([["a_12", 12]]),
|
||||
sy.BeAssignToken([["b", 13]]),
|
||||
sy.BeValueToken(["c"]),
|
||||
], __GL()),
|
||||
|
|
@ -184,10 +184,10 @@ dict_advanced_syntax_input_and_expected_output = {
|
|||
]),
|
||||
]),
|
||||
), __GL()),
|
||||
("{aze,/.}[a=12]", (
|
||||
("{aze,/.__}[a=12]", (
|
||||
sy.OptionalToken([
|
||||
sy.OptionalInsertToken([
|
||||
"aze,/.",
|
||||
"aze,/.__",
|
||||
]),
|
||||
sy.OptionalVarToken([
|
||||
sy.BeAssignToken([["a", 12]]),
|
||||
|
|
@ -218,7 +218,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
|||
]),
|
||||
]),
|
||||
), __GL()),
|
||||
("{{aze!=}}{azett!=}[a=12]", (
|
||||
("{{aze!=}}{azett!=}[a_32=12]", (
|
||||
sy.OptionalToken([
|
||||
sy.OptionalClassToken([
|
||||
"aze!=",
|
||||
|
|
@ -227,14 +227,14 @@ dict_advanced_syntax_input_and_expected_output = {
|
|||
"azett!=",
|
||||
]),
|
||||
sy.OptionalVarToken([
|
||||
sy.BeAssignToken([["a", 12]]),
|
||||
sy.BeAssignToken([["a_32", 12]]),
|
||||
]),
|
||||
]),
|
||||
), __GL()),
|
||||
("[a=12]{aze,/.}{{azer!=}}", (
|
||||
("[_a=12]{aze,/.}{{azer!=}}", (
|
||||
sy.OptionalToken([
|
||||
sy.OptionalVarToken([
|
||||
sy.BeAssignToken([["a", 12]]),
|
||||
sy.BeAssignToken([["_a", 12]]),
|
||||
]),
|
||||
sy.OptionalInsertToken([
|
||||
"aze,/.",
|
||||
|
|
|
|||
Loading…
Reference in New Issue