diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2023-02-19 23:36:04 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2023-02-19 23:36:04 -0600 |
commit | f2ab2bac6b26f82730d5f5d7ab1e6d5f2f1060e3 (patch) | |
tree | 88a1ce15061cd7a9cee00941bc9ff3c39e09ab5e /tests | |
parent | e28fbb181851ca16bc0ade9c371628f86c25adbc (diff) |
add yaml_parser tests, small refactor
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 6 | ||||
-rw-r--r-- | tests/io_files/simple.yaml | 28 | ||||
-rw-r--r-- | tests/test_yaml_parser.py | 19 |
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 58416ea..1beffc6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import os import sys from typing import Callable import pytest @@ -7,6 +8,11 @@ from pyssg.arg_parser import get_parser from pyssg.custom_logger import setup_logger +@pytest.fixture +def test_dir(): + return os.path.dirname(os.path.abspath(__file__)) + + @pytest.fixture(scope='session') def arg_parser(): return get_parser() diff --git a/tests/io_files/simple.yaml b/tests/io_files/simple.yaml new file mode 100644 index 0000000..0b722a6 --- /dev/null +++ b/tests/io_files/simple.yaml @@ -0,0 +1,28 @@ +%YAML 1.2 +--- +define: &root "$HOME/pyssg/site_example/" + +title: "Example site" +path: + src: !join [*root, "src"] + dst: !join [*root, "dst"] + plt: !join [*root, "plt"] + db: !join [*root, ".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: [] +...
\ No newline at end of file diff --git a/tests/test_yaml_parser.py b/tests/test_yaml_parser.py new file mode 100644 index 0000000..9a1b3c3 --- /dev/null +++ b/tests/test_yaml_parser.py @@ -0,0 +1,19 @@ +from importlib.resources import path as rpath +from pyssg.yaml_parser import get_parsed_yaml + + +def test_yaml_resource_read() -> None: + yaml: list[dict] = get_parsed_yaml('simple.yaml', 'tests.io_files') + assert len(yaml) == 1 + + +def test_yaml_path_read(test_dir: str) -> None: + yaml: list[dict] = get_parsed_yaml(f'{test_dir}/io_files/simple.yaml') + assert len(yaml) == 1 + + +def test_yaml_join() -> None: + yaml: dict = get_parsed_yaml('simple.yaml', 'tests.io_files')[0] + define_str: str = '$HOME/pyssg/site_example/' + assert yaml['define'] == define_str + assert yaml['path']['src'] == f'{define_str}src' |