diff --git a/tests/modules/test_context_mngr.py b/tests/modules/test_context_mngr.py index 87bd094..c61ab1c 100644 --- a/tests/modules/test_context_mngr.py +++ b/tests/modules/test_context_mngr.py @@ -465,7 +465,7 @@ _zipped_token_list_with_expected_result = [ @pytest.fixture def base_cm(): lst = _base_list[:] - base = context_mngr.ContextManager(_base_list) + base = context_mngr.ContextManager(lst) base() return base diff --git a/tests/modules/test_sitecrawler.py b/tests/modules/test_sitecrawler.py index b562acb..1e6263b 100644 --- a/tests/modules/test_sitecrawler.py +++ b/tests/modules/test_sitecrawler.py @@ -2,7 +2,6 @@ import os import tempfile import pytest -import rich import bootstraparse.modules.sitecrawler as sitecrawler from bootstraparse.modules import environment, config, pathresolver, export, preparser diff --git a/tests/modules/test_sitecreator.py b/tests/modules/test_sitecreator.py index cb00c80..51667fe 100644 --- a/tests/modules/test_sitecreator.py +++ b/tests/modules/test_sitecreator.py @@ -1,17 +1,65 @@ -import bootstraparse.modules.sitecreator as sitecreator +import os +import tempfile + import pytest +from bootstraparse.modules import sitecreator, syntax, context_mngr -@pytest.mark.xfail(reason="TODO") -def test_create_site(): - sitecreator.create_website() - sitecreator.create_environment() - sitecreator.create_config() - sitecreator.create_crawler() - sitecreator.create_user_config() - sitecreator.create_template() - sitecreator.env_checker() - sitecreator.begin_crawling(None) - sitecreator.begin_pre_parsing(None) - sitecreator.begin_parsing(None) - sitecreator.begin_export(None) +_TEMP_DIRECTORY = tempfile.TemporaryDirectory() +_BASE = os.path.join(_TEMP_DIRECTORY.name, "base") +_DEST = os.path.join(_TEMP_DIRECTORY.name, "dest") +files = [ + ("base/test1.bpr", "*Test*", "Test\n"), + ("base/test2.bpr", ":: <_noimport.bpr>", 'linktext\n'), + ("base/test3.bpr", "#. List", "
    \n
  1. List
  2. \n
"), + ("base/_noimport.bpr", "[linktext]('link://dest')", None), + ("base/subtests/test4.bpr", "# Header #", "

Header

\n"), + ("base/subtests/test5.bpr", "<>", "
\n test \n
\n"), + ("base/configs/test6.yml", "test: test", None), + ("base/configs/test7.yml", "test: test", None), + ("base/templates/test8.yml", "test: test", None), +] + + +def make_new_file(path, content="", mode="w+"): + """ + Make a new file + """ + name = os.path.join(_TEMP_DIRECTORY.name, path) + os.makedirs(os.path.dirname(name), exist_ok=True) + with open(name, mode=mode) as f: + f.write(content) + return path + + +@pytest.fixture(scope="module") +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] + + +@pytest.fixture(scope="module") +def env(): + return sitecreator.create_environment(_BASE, _DEST) + + +def test_create_site(env, list_files): + sitecreator.create_website(_BASE, _DEST) + for file, exp in list_files: + if exp is not None: + assert os.path.exists(file) + with open(file, "r") as f: + assert f.read() == exp + + +def test_save(list_files, env): + containers = [ + context_mngr.TextContainer([syntax.TextToken(["Test"])]), + context_mngr.TextContainer([syntax.TextToken(["Test2"])]), + ] + fd = make_new_file(os.path.join(_DEST, "filetest.html")) + sitecreator.save(containers, os.path.join(_DEST, "filetest.html"), env) + with open(fd, "r") as f: + assert f.read() == "TestTest2"