Test sitecrawler

This commit is contained in:
Maximilien Rigaut 2022-06-07 05:21:19 +02:00
parent bfec09034e
commit ae6fa81bfd
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
1 changed files with 18 additions and 19 deletions

View File

@ -5,21 +5,21 @@ import pytest
import rich
import bootstraparse.modules.sitecrawler as sitecrawler
from bootstraparse.modules import environment, config, pathresolver, export
from bootstraparse.modules import environment, config, pathresolver, export, preparser
_TEMP_DIRECTORY = tempfile.TemporaryDirectory()
_BASE = os.path.join(_TEMP_DIRECTORY.name, "base")
_DEST = os.path.join(_TEMP_DIRECTORY.name, "dest")
files = [
("base/test1.bpr", ""),
("base/test2.bpr", ""),
("base/test3.bpr", ""),
("base/_noimport.bpr", ""),
("base/subtests/test4.bpr", ""),
("base/subtests/test5.bpr", ""),
("base/config/test6.yml", ""),
("base/config/test7.yml", ""),
("base/templates/test8.yml", ""),
("base/test1.bpr", "*Test*", ""),
("base/test2.bpr", "", ""),
("base/test3.bpr", "", ""),
("base/_noimport.bpr", "", ""),
("base/subtests/test4.bpr", "", ""),
("base/subtests/test5.bpr", "", ""),
("base/config/test6.yml", "", None),
("base/config/test7.yml", "", None),
("base/templates/test8.yml", "", None),
]
@ -29,13 +29,9 @@ def make_new_file(path, content="", mode="w+"):
"""
name = os.path.join(_TEMP_DIRECTORY.name, path)
os.makedirs(os.path.dirname(name), exist_ok=True)
# print(f"Creating : {name}")
# print(f"Content : {content}")
# print(f"Location : {os.path.dirname(name)}")
# print()
with open(name, mode=mode) as f:
f.write(content)
return name
return path
@pytest.fixture(scope="module")
@ -43,7 +39,7 @@ def list_files():
"""
List all files in the test directory
"""
return [make_new_file(file, content) for file, content in files]
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")
@ -74,7 +70,6 @@ def test_sitecrawler(list_files, env):
"""
crw = sitecrawler.SiteCrawler(_BASE, _DEST, env)
rich.inspect(crw)
crw.set_all_preparsers()
for pre, dest in crw:
assert os.path.exists(dest)
@ -87,9 +82,13 @@ def test_sitecrawler(list_files, env):
crw.set_all_preparsers()
@pytest.mark.skip(reason="Not implemented")
def test_result_crawler(list_files, env):
"""
Test the sitecrawler.ResultCrawler class
"""
pass
crw = sitecrawler.SiteCrawler(_BASE, _DEST, env)
crw.set_all_preparsers()
for pp, dest in crw:
assert os.path.exists(dest)
assert os.path.isfile(dest)
assert isinstance(pp, preparser.PreParser)