From a609b1cb2b43fd17e03efa62314f679b47ae6cb5 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Fri, 24 Feb 2023 03:53:13 -0600 Subject: add utils tests, small refactor --- tests/conftest.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'tests/conftest.py') diff --git a/tests/conftest.py b/tests/conftest.py index b44fbf6..e2d6946 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,8 @@ import os import sys import pytest -from typing import Callable +from pathlib import Path +from typing import Any, Callable from pytest import MonkeyPatch from argparse import ArgumentParser from datetime import datetime, timezone @@ -70,3 +71,48 @@ def get_fmt_time() -> Callable[..., str]: def fmt_time(fmt: str) -> str: return datetime.now(tz=timezone.utc).strftime(fmt) return fmt_time + + +@pytest.fixture +def simple_dict() -> dict[str, Any]: + return {'define': '$PYSSG_HOME/pyssg/site_example/', + 'title': 'Example site', + 'path': { + 'src': '/tmp/pyssg/pyssg/site_example/src', + 'dst': '/tmp/pyssg/pyssg/site_example/dst', + 'plt': '/tmp/pyssg/pyssg/site_example/plt', + 'db': '/tmp/pyssg/pyssg/site_example/.files'}, + 'url': { + 'main': 'https://example.com', + 'static': 'https://static.example.com', + 'default_image': 'images/default.png'}, + 'fmt': { + 'date': '%a, %b %d, %Y @ %H:%M %Z', + 'list_date': '%b %d', + 'list_sep_date': '%B %Y'}, + 'dirs': { + '/': { + 'cfg': { + 'plt': 'page.html', + 'tags': False, + 'index': False, + 'rss': False, + 'sitemap': False, + 'exclude_dirs': []}}}} + + +@pytest.fixture(scope='function') +def tmp_dir_structure(tmp_path: Path) -> Path: + root: Path = tmp_path/'dir_str' + # order matters + dirs: list[Path] = [root, + root/'first', + root/'first/f1', + root/'first/f1/f2', + root/'second', + root/'second/s1'] + for i, d in enumerate(dirs): + d.mkdir() + for ext in ['txt', 'md', 'html']: + (d/f'f{i}.{ext}').write_text('sample') + return root -- cgit v1.2.3-54-g00ecf