diff --git a/src/bootstraparse/modules/preparser.py b/src/bootstraparse/modules/preparser.py index 7f6a1ab..3a59a67 100644 --- a/src/bootstraparse/modules/preparser.py +++ b/src/bootstraparse/modules/preparser.py @@ -6,6 +6,7 @@ from io import StringIO from bootstraparse.modules import pathresolver as pr from bootstraparse.modules import environment + import rich from rich.tree import Tree @@ -150,9 +151,8 @@ class PreParser: :return: the html to insert as a string :param shortcut: the id of the shortcut to fetch """ - if shortcut: - return '

hello world

' - return 'error' + # return self.__env.config[""(shortcut) + return f'

{shortcut}

' def get_picture_from_config(self, shortcut): """ @@ -160,9 +160,7 @@ class PreParser: :return: the html to insert as a string :param shortcut: the id of the picture to fetch """ - if shortcut: - return '' - return 'error' + return f'' # todo: test import in sub-folders # todo: test same imports on multiple lines @@ -189,8 +187,8 @@ class PreParser: def __eq__(self, other): """ Checks if the PreParser object is equal to another PreParser object. - :param other: the other PreParser object :return: True if the PreParser objects are equal, False otherwise + :param other: the other PreParser object """ if self.path == other.path: if self.name == other.name: @@ -204,8 +202,8 @@ class PreParser: def __ne__(self, other): """ Checks if the PreParser object is not equal to another PreParser object. - :param other: the other PreParser object :return: True if the PreParser objects are not equal, False otherwise + :param other: the other PreParser object """ return not self.__eq__(other) @@ -238,5 +236,5 @@ if __name__ == "__main__": # pragma: no cover # rich.print(michel.rich_tree()) string_to_match = r'@[bite]{id=2}[saucisse=13] @[chaussette] @[bermuda]{tomate=tomate}[12] @[pasteque]' # rich.inspect(_rgx_alias.match(string_to_match).captures('alias_name', 'class', 'variables')) - for e in _rgx_alias.match(string_to_match).captures(1): - rich.inspect(e.captures('alias_name', 'class', 'variables')) + for ex in _rgx_alias.match(string_to_match).captures(1): + rich.inspect(ex.captures('alias_name', 'class', 'variables')) diff --git a/tests/modules/test_config.py b/tests/modules/test_config.py index f27fe2b..ffade17 100644 --- a/tests/modules/test_config.py +++ b/tests/modules/test_config.py @@ -38,6 +38,7 @@ def test_config_load(): assert usr_c["aliases2"] is not None assert usr_c.__repr__() + def test_add_to_config(): usr_c = config.ConfigLoader(user_conf) usr_c.add_folder(app_conf) @@ -54,4 +55,4 @@ def test_add_to_config(): from_empty.load_from_file(os.path.join(app_conf, "aliases.yaml")) assert from_empty["aliases"] == {"aliases": {"test_alias": "test_parser"}, - "parser": {"name": "test_parser", "type": "test_parser"}} + "parser": {"name": "test_parser", "type": "test_parser"}} diff --git a/tests/modules/test_preparser.py b/tests/modules/test_preparser.py index 32e9b9e..d64cc43 100644 --- a/tests/modules/test_preparser.py +++ b/tests/modules/test_preparser.py @@ -10,7 +10,7 @@ from bootstraparse.modules import preparser from bootstraparse.modules import environment ############################################################################### -# Environement variables +# Environment variables env = environment.Environment() _BASE_PATH_PREPARSER = "../../" @@ -68,6 +68,11 @@ website_tree = { "pages/page2.bpr": content_page2 } +get_from_config = ''' +@{shortcut}{class="shortcut", type=2, name="shortcut"}[type=33, name="shortcut"] +@[picture]{class="picture", type=2, name="picture"}[type=33, name="picture"] +''' + @pytest.fixture(autouse=True) def base_architecture(): @@ -198,7 +203,7 @@ def test_preparser_content(filename, content): pp = preparser.PreParser(testfile, env) pp.make_import_list() - assert pp.export_with_imports().read() == content # nothing is implementes yet + assert pp.export_with_imports().read() == content # nothing is implemented yet # todo: test import in sub-folders @@ -233,3 +238,24 @@ def test_rich_tree(): pp.make_import_list() pp.rich_tree() pp.rich_tree(force=False) + + +def test_get_shortcut_from_config(): + from_config = temp_name("test_get_shortcut_from_config.bpr") + make_new_file(from_config, get_from_config) + + pp = preparser.PreParser(from_config, env) + pp.make_import_list() + assert pp.get_shortcut_from_config("any_shortcut") == "

any_shortcut

" + assert pp.get_picture_from_config("any_picture") == '' + + +@pytest.mark.xfail(reason="Not implemented") +def test_replace(): + replace_file = temp_name("test_preparse.bpr") + make_new_file(replace_file, get_from_config) + pp = preparser.PreParser(replace_file, env) + + pp.make_import_list() + image_f = pp.parse_shortcuts_and_images() + assert image_f.read() == """\n

test_preparse

\n\n"""