From 1b2d6aff6ccf72fdb292a1f05bb41bf9633a8f55 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Tue, 25 Apr 2023 04:03:48 -0600 Subject: refactor tests and add more typing --- tests/conftest.py | 31 +++++------- tests/io_files/__init__.py | 0 tests/io_files/md/__init__.py | 0 tests/io_files/md/a/__init__.py | 0 tests/io_files/md/a/second.md | 12 ----- tests/io_files/md/first.md | 10 ---- tests/io_files/md/new.md | 10 ---- tests/io_files/multiple.yaml | 55 ---------------------- tests/io_files/multiple_one_doc_error.yaml | 48 ------------------- tests/io_files/simple.yaml | 28 ----------- tests/io_files/simple_missing_dirs.yaml | 21 --------- tests/io_files/simple_missing_key.yaml | 29 ------------ tests/io_files/simple_missing_root_dir.yaml | 22 --------- tests/sample_files/__init__.py | 0 tests/sample_files/checksum.txt | 1 + tests/sample_files/config/__init__.py | 0 tests/sample_files/config/default.yaml | 23 +++++++++ .../sample_files/config/default_missing_dirs.yaml | 17 +++++++ .../config/default_missing_mandatory_key.yaml | 24 ++++++++++ .../config/default_missing_root_dir.yaml | 18 +++++++ tests/sample_files/config/multiple_default.yaml | 45 ++++++++++++++++++ .../config/multiple_default_one_doc_error.yaml | 39 +++++++++++++++ tests/sample_files/md/__init__.py | 0 tests/sample_files/md/a/__init__.py | 0 tests/sample_files/md/a/second.md | 12 +++++ tests/sample_files/md/first.md | 10 ++++ tests/sample_files/md/new.md | 10 ++++ tests/test_configuration.py | 54 ++++++++++----------- tests/test_database.py | 9 ++-- tests/test_utils.py | 23 +++++---- tests/test_yaml_parser.py | 12 ++--- 31 files changed, 265 insertions(+), 298 deletions(-) delete mode 100644 tests/io_files/__init__.py delete mode 100644 tests/io_files/md/__init__.py delete mode 100644 tests/io_files/md/a/__init__.py delete mode 100644 tests/io_files/md/a/second.md delete mode 100644 tests/io_files/md/first.md delete mode 100644 tests/io_files/md/new.md delete mode 100644 tests/io_files/multiple.yaml delete mode 100644 tests/io_files/multiple_one_doc_error.yaml delete mode 100644 tests/io_files/simple.yaml delete mode 100644 tests/io_files/simple_missing_dirs.yaml delete mode 100644 tests/io_files/simple_missing_key.yaml delete mode 100644 tests/io_files/simple_missing_root_dir.yaml create mode 100644 tests/sample_files/__init__.py create mode 100644 tests/sample_files/checksum.txt create mode 100644 tests/sample_files/config/__init__.py create mode 100644 tests/sample_files/config/default.yaml create mode 100644 tests/sample_files/config/default_missing_dirs.yaml create mode 100644 tests/sample_files/config/default_missing_mandatory_key.yaml create mode 100644 tests/sample_files/config/default_missing_root_dir.yaml create mode 100644 tests/sample_files/config/multiple_default.yaml create mode 100644 tests/sample_files/config/multiple_default_one_doc_error.yaml create mode 100644 tests/sample_files/md/__init__.py create mode 100644 tests/sample_files/md/a/__init__.py create mode 100644 tests/sample_files/md/a/second.md create mode 100644 tests/sample_files/md/first.md create mode 100644 tests/sample_files/md/new.md (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index d3f28d7..aaf0b3a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,18 +31,18 @@ def sitemap_date_fmt(): @pytest.fixture(scope='session') -def test_dir() -> str: - return str(os.path.dirname(os.path.abspath(__file__))) +def sample_files_path() -> str: + return f'{str(os.path.dirname(os.path.abspath(__file__)))}/sample_files' @pytest.fixture(scope='session') -def test_resource() -> str: - return 'tests.io_files' +def config_resource() -> str: + return 'tests.sample_files.config' @pytest.fixture(scope='session') -def simple_yaml() -> str: - return 'simple.yaml' +def default_yaml() -> str: + return 'default.yaml' @pytest.fixture(scope='session') @@ -76,7 +76,7 @@ def get_fmt_time() -> Callable[..., str]: @pytest.fixture -def simple_dict() -> dict[str, Any]: +def default_config_dict() -> dict[str, Any]: return {'define': '$PYSSG_HOME/pyssg/site_example/', 'title': 'Example site', 'path': { @@ -85,13 +85,9 @@ def simple_dict() -> dict[str, Any]: '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'}, + 'main': 'https://example.com'}, 'fmt': { - 'date': '%a, %b %d, %Y @ %H:%M %Z', - 'list_date': '%b %d', - 'list_sep_date': '%B %Y'}, + 'date': '%a, %b %d, %Y @ %H:%M %Z'}, 'dirs': { '/': { 'cfg': { @@ -99,13 +95,12 @@ def simple_dict() -> dict[str, Any]: 'tags': False, 'index': False, 'rss': False, - 'sitemap': False, - 'exclude_dirs': []}}}} + 'sitemap': False}}}} @pytest.fixture(scope='function') def tmp_dir_structure(tmp_path: Path) -> Path: - root: Path = tmp_path/'dir_str' + root: Path = tmp_path/'dir_structure' # order matters dirs: list[Path] = [root, root/'first', @@ -165,12 +160,12 @@ def tmp_db_wrong_col_num(tmp_path: Path) -> Path: @pytest.fixture(scope='function') def tmp_src_dir(tmp_path: Path, - test_dir: str) -> Path: + sample_files_path: str) -> Path: src: Path = tmp_path/'src' src_a: Path = src/'a' src.mkdir() src_a.mkdir() - src_test: str = f'{test_dir}/io_files/md' + src_test: str = f'{sample_files_path}/md' files: list[str] = ['first.md', 'new.md', 'a/second.md'] for f in files: diff --git a/tests/io_files/__init__.py b/tests/io_files/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io_files/md/__init__.py b/tests/io_files/md/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io_files/md/a/__init__.py b/tests/io_files/md/a/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/io_files/md/a/second.md b/tests/io_files/md/a/second.md deleted file mode 100644 index cb4e333..0000000 --- a/tests/io_files/md/a/second.md +++ /dev/null @@ -1,12 +0,0 @@ -title: Second blog post for testing purposes -author: David Luévano - Someone Else -lang: en -summary: This is just a post used for testing (the second). -tags: test - english - short - update - multiple-author - -A second "blog entry" for testing purposes which uses multiple authors and is inside a subdirectory. diff --git a/tests/io_files/md/first.md b/tests/io_files/md/first.md deleted file mode 100644 index 567ea3e..0000000 --- a/tests/io_files/md/first.md +++ /dev/null @@ -1,10 +0,0 @@ -title: First blog post for testing purposes -author: David Luévano -lang: en -summary: This is just a post used for testing. -tags: test - english - short - update - -Even though I have this "blog" subdomain and page setup, doesn't mean I'll be blogging for pyssg, this is just to serve as an example for the types of sites that pyssg can be used for. \ No newline at end of file diff --git a/tests/io_files/md/new.md b/tests/io_files/md/new.md deleted file mode 100644 index ce684a7..0000000 --- a/tests/io_files/md/new.md +++ /dev/null @@ -1,10 +0,0 @@ -title: New file -author: David Luévano -lang: en -summary: New file used for testing the database. -tags: test - english - short - update - -This is a sample markdown file used for testing pyssg. \ No newline at end of file diff --git a/tests/io_files/multiple.yaml b/tests/io_files/multiple.yaml deleted file mode 100644 index 8d99c40..0000000 --- a/tests/io_files/multiple.yaml +++ /dev/null @@ -1,55 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_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: [] -... ---- -define: &root "$PYSSG_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/io_files/multiple_one_doc_error.yaml b/tests/io_files/multiple_one_doc_error.yaml deleted file mode 100644 index 86f6546..0000000 --- a/tests/io_files/multiple_one_doc_error.yaml +++ /dev/null @@ -1,48 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_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: [] -... ---- -define: &root "$PYSSG_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: - # just removing all paths as it will cause an error -... \ No newline at end of file diff --git a/tests/io_files/simple.yaml b/tests/io_files/simple.yaml deleted file mode 100644 index df3888b..0000000 --- a/tests/io_files/simple.yaml +++ /dev/null @@ -1,28 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_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/io_files/simple_missing_dirs.yaml b/tests/io_files/simple_missing_dirs.yaml deleted file mode 100644 index aa15fb5..0000000 --- a/tests/io_files/simple_missing_dirs.yaml +++ /dev/null @@ -1,21 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_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: -# test missing dirs -... \ No newline at end of file diff --git a/tests/io_files/simple_missing_key.yaml b/tests/io_files/simple_missing_key.yaml deleted file mode 100644 index ac81563..0000000 --- a/tests/io_files/simple_missing_key.yaml +++ /dev/null @@ -1,29 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_HOME/pyssg/site_example/" - -# test missing mandatory key -# 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/io_files/simple_missing_root_dir.yaml b/tests/io_files/simple_missing_root_dir.yaml deleted file mode 100644 index 07fa824..0000000 --- a/tests/io_files/simple_missing_root_dir.yaml +++ /dev/null @@ -1,22 +0,0 @@ -%YAML 1.2 ---- -define: &root "$PYSSG_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: -# test missing /: - something: -... \ No newline at end of file diff --git a/tests/sample_files/__init__.py b/tests/sample_files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_files/checksum.txt b/tests/sample_files/checksum.txt new file mode 100644 index 0000000..025b879 --- /dev/null +++ b/tests/sample_files/checksum.txt @@ -0,0 +1 @@ +The content of this file is irrelevant as it is only to test the checksum function. \ No newline at end of file diff --git a/tests/sample_files/config/__init__.py b/tests/sample_files/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_files/config/default.yaml b/tests/sample_files/config/default.yaml new file mode 100644 index 0000000..08121a6 --- /dev/null +++ b/tests/sample_files/config/default.yaml @@ -0,0 +1,23 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + /: + cfg: + plt: "page.html" + tags: False + index: False + rss: False + sitemap: False +... \ No newline at end of file diff --git a/tests/sample_files/config/default_missing_dirs.yaml b/tests/sample_files/config/default_missing_dirs.yaml new file mode 100644 index 0000000..03ee35a --- /dev/null +++ b/tests/sample_files/config/default_missing_dirs.yaml @@ -0,0 +1,17 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: +# test missing dirs (doesn't have any) +... \ No newline at end of file diff --git a/tests/sample_files/config/default_missing_mandatory_key.yaml b/tests/sample_files/config/default_missing_mandatory_key.yaml new file mode 100644 index 0000000..b5554f7 --- /dev/null +++ b/tests/sample_files/config/default_missing_mandatory_key.yaml @@ -0,0 +1,24 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_HOME/pyssg/site_example/" + +# test missing mandatory key +# 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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + /: + cfg: + plt: "page.html" + tags: False + index: False + rss: False + sitemap: False +... \ No newline at end of file diff --git a/tests/sample_files/config/default_missing_root_dir.yaml b/tests/sample_files/config/default_missing_root_dir.yaml new file mode 100644 index 0000000..896e141 --- /dev/null +++ b/tests/sample_files/config/default_missing_root_dir.yaml @@ -0,0 +1,18 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: +# test missing "/" dir in specific + something: +... \ No newline at end of file diff --git a/tests/sample_files/config/multiple_default.yaml b/tests/sample_files/config/multiple_default.yaml new file mode 100644 index 0000000..54954b1 --- /dev/null +++ b/tests/sample_files/config/multiple_default.yaml @@ -0,0 +1,45 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + /: + cfg: + plt: "page.html" + tags: False + index: False + rss: False + sitemap: False +... +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + /: + cfg: + plt: "page.html" + tags: False + index: False + rss: False + sitemap: False +... \ No newline at end of file diff --git a/tests/sample_files/config/multiple_default_one_doc_error.yaml b/tests/sample_files/config/multiple_default_one_doc_error.yaml new file mode 100644 index 0000000..44d9beb --- /dev/null +++ b/tests/sample_files/config/multiple_default_one_doc_error.yaml @@ -0,0 +1,39 @@ +%YAML 1.2 +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + /: + cfg: + plt: "page.html" + tags: False + index: False + rss: False + sitemap: False +... +--- +define: &root "$PYSSG_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" +fmt: + date: "%a, %b %d, %Y @ %H:%M %Z" +dirs: + # just removing all paths as it will cause an error +... \ No newline at end of file diff --git a/tests/sample_files/md/__init__.py b/tests/sample_files/md/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_files/md/a/__init__.py b/tests/sample_files/md/a/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_files/md/a/second.md b/tests/sample_files/md/a/second.md new file mode 100644 index 0000000..cb4e333 --- /dev/null +++ b/tests/sample_files/md/a/second.md @@ -0,0 +1,12 @@ +title: Second blog post for testing purposes +author: David Luévano + Someone Else +lang: en +summary: This is just a post used for testing (the second). +tags: test + english + short + update + multiple-author + +A second "blog entry" for testing purposes which uses multiple authors and is inside a subdirectory. diff --git a/tests/sample_files/md/first.md b/tests/sample_files/md/first.md new file mode 100644 index 0000000..567ea3e --- /dev/null +++ b/tests/sample_files/md/first.md @@ -0,0 +1,10 @@ +title: First blog post for testing purposes +author: David Luévano +lang: en +summary: This is just a post used for testing. +tags: test + english + short + update + +Even though I have this "blog" subdomain and page setup, doesn't mean I'll be blogging for pyssg, this is just to serve as an example for the types of sites that pyssg can be used for. \ No newline at end of file diff --git a/tests/sample_files/md/new.md b/tests/sample_files/md/new.md new file mode 100644 index 0000000..ce684a7 --- /dev/null +++ b/tests/sample_files/md/new.md @@ -0,0 +1,10 @@ +title: New file +author: David Luévano +lang: en +summary: New file used for testing the database. +tags: test + english + short + update + +This is a sample markdown file used for testing pyssg. \ No newline at end of file diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 68f7808..36761eb 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -7,10 +7,10 @@ from pyssg.configuration import get_static_config, get_parsed_config # this test is a bit sketchy, as the way the datetimes are calculated could vary # by milliseconds or even have a difference in seconds -def test_static_default(rss_date_fmt: str, - sitemap_date_fmt: str, - get_fmt_time: Callable[..., str], - version: str) -> None: +def test_static_config(rss_date_fmt: str, + sitemap_date_fmt: str, + get_fmt_time: Callable[..., str], + version: str) -> None: rss_run_date: str = get_fmt_time(rss_date_fmt) sitemap_run_date: str = get_fmt_time(sitemap_date_fmt) sc_dict: dict[str, Any] = {'fmt': {'rss_date': rss_date_fmt, @@ -22,21 +22,21 @@ def test_static_default(rss_date_fmt: str, assert static_config == sc_dict -def test_simple(test_dir: str, - simple_yaml: str, - simple_dict: dict[str, Any]) -> None: - yaml_path: str = f'{test_dir}/io_files/{simple_yaml}' +def test_default_config(sample_files_path: str, + default_yaml: str, + default_config_dict: dict[str, Any]) -> None: + yaml_path: str = f'{sample_files_path}/config/{default_yaml}' yaml: list[dict[str, Any]] = get_parsed_config(yaml_path) assert len(yaml) == 1 - assert yaml[0] == simple_dict + assert yaml[0] == default_config_dict -def test_simple_mising_key(test_dir: str, - caplog: LogCaptureFixture) -> None: +def test_default_config_mising_mandatory_key(sample_files_path: str, + caplog: LogCaptureFixture) -> None: err: tuple[str, int, str] = ('pyssg.configuration', ERROR, 'config doesn\'t have "title"') - yaml_path: str = f'{test_dir}/io_files/simple_missing_key.yaml' + yaml_path: str = f'{sample_files_path}/config/default_missing_mandatory_key.yaml' with pytest.raises(SystemExit) as system_exit: get_parsed_config(yaml_path) assert system_exit.type == SystemExit @@ -44,12 +44,12 @@ def test_simple_mising_key(test_dir: str, assert caplog.record_tuples[-1] == err -def test_simple_mising_dirs(test_dir: str, - caplog: LogCaptureFixture) -> None: +def test_default_config_mising_dirs(sample_files_path: str, + caplog: LogCaptureFixture) -> None: err: tuple[str, int, str] = ('pyssg.configuration', ERROR, 'config doesn\'t have any dirs (dirs.*)') - yaml_path: str = f'{test_dir}/io_files/simple_missing_dirs.yaml' + yaml_path: str = f'{sample_files_path}/config/default_missing_dirs.yaml' with pytest.raises(SystemExit) as system_exit: get_parsed_config(yaml_path) assert system_exit.type == SystemExit @@ -57,12 +57,12 @@ def test_simple_mising_dirs(test_dir: str, assert caplog.record_tuples[-1] == err -def test_simple_root_dir(test_dir: str, - caplog: LogCaptureFixture) -> None: +def test_default_config_root_dir(sample_files_path: str, + caplog: LogCaptureFixture) -> None: err: tuple[str, int, str] = ('pyssg.configuration', ERROR, 'config doesn\'t have "dirs./"') - yaml_path: str = f'{test_dir}/io_files/simple_missing_root_dir.yaml' + yaml_path: str = f'{sample_files_path}/config/default_missing_root_dir.yaml' with pytest.raises(SystemExit) as system_exit: get_parsed_config(yaml_path) assert system_exit.type == SystemExit @@ -71,24 +71,24 @@ def test_simple_root_dir(test_dir: str, # this really just tests that both documents in the yaml file are read, -# multiple.yaml is just simple.yaml with the same document twice, -# shouldn't be an issue as the yaml package handles this -def test_multiple(test_dir: str, simple_dict: dict[str, Any]) -> None: - yaml_path: str = f'{test_dir}/io_files/multiple.yaml' +# both documents are the same (the default.yaml) +def test_multiple_default_config(sample_files_path: str, + default_config_dict: dict[str, Any]) -> None: + yaml_path: str = f'{sample_files_path}/config/multiple_default.yaml' yaml: list[dict[str, Any]] = get_parsed_config(yaml_path) assert len(yaml) == 2 - assert yaml[0] == simple_dict - assert yaml[1] == simple_dict + assert yaml[0] == default_config_dict + assert yaml[1] == default_config_dict # also, this just tests that the checks for a well formed config file are # processed for all documents -def test_multiple_one_doc_error(test_dir: str, - caplog: LogCaptureFixture) -> None: +def test_multiple_default_config_one_doc_error(sample_files_path: str, + caplog: LogCaptureFixture) -> None: err: tuple[str, int, str] = ('pyssg.configuration', ERROR, 'config doesn\'t have any dirs (dirs.*)') - yaml_path: str = f'{test_dir}/io_files/multiple_one_doc_error.yaml' + yaml_path: str = f'{sample_files_path}/config/multiple_default_one_doc_error.yaml' with pytest.raises(SystemExit) as system_exit: get_parsed_config(yaml_path) assert system_exit.type == SystemExit diff --git a/tests/test_database.py b/tests/test_database.py index 7ca597f..c5957e4 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -6,8 +6,9 @@ from pyssg.database import Database from pyssg.database_entry import DatabaseEntry -def test_read_database_no_db(test_dir: str, caplog: LogCaptureFixture) -> None: - path: str = f'{test_dir}/non_existent_db.psv' +def test_read_database_no_db(sample_files_path: str, + caplog: LogCaptureFixture) -> None: + path: str = f'{sample_files_path}/non_existent_db.psv' war: tuple[str, int, str] = ('pyssg.database', WARNING, f'"{path}" doesn\'t exist, will be created ' @@ -18,9 +19,9 @@ def test_read_database_no_db(test_dir: str, caplog: LogCaptureFixture) -> None: assert caplog.record_tuples[-1] == war -def test_read_database_not_a_file(test_dir: str, +def test_read_database_not_a_file(sample_files_path: str, caplog: LogCaptureFixture) -> None: - path: str = test_dir + path: str = sample_files_path err: tuple[str, int, str] = ('pyssg.database', ERROR, f'"{path}" is not a file') diff --git a/tests/test_utils.py b/tests/test_utils.py index 86242c2..75b79c2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -33,13 +33,14 @@ def test_path_expansion_failure(path: str) -> None: assert system_exit.value.code == 1 -def test_checksum(test_dir: str, simple_yaml: str) -> None: - path: str = f'{test_dir}/io_files/{simple_yaml}' - simple_yaml_checksum: str = 'd4f0a3ed56fd530d3ea485dced25534c' +def test_checksum(sample_files_path: str) -> None: + path: str = f'{sample_files_path}/checksum.txt' + simple_yaml_checksum: str = '437b5a0e20d32fc14944c1c00d066303' checksum: str = get_checksum(path) assert checksum == simple_yaml_checksum +# TODO: actually check the existence of the files and not just the log def test_copy_file(tmp_path: Path, caplog: LogCaptureFixture) -> None: src: Path = tmp_path/'src' dst: Path = tmp_path/'dst' @@ -55,7 +56,9 @@ def test_copy_file(tmp_path: Path, caplog: LogCaptureFixture) -> None: assert caplog.record_tuples[-1] == inf -def test_copy_file_failure(tmp_path: Path, caplog: LogCaptureFixture) -> None: +# TODO: actually check the existence of the files and not just the log +def test_copy_file_already_exists(tmp_path: Path, + caplog: LogCaptureFixture) -> None: src: Path = tmp_path/'src' dst: Path = tmp_path/'dst' src.mkdir() @@ -82,7 +85,9 @@ def test_create_dir(tmp_path: Path, caplog: LogCaptureFixture) -> None: assert caplog.record_tuples[-1] == inf -def test_create_dir_failure(tmp_path: Path, caplog: LogCaptureFixture) -> None: +# TODO: actually check the existence of the files and not just the log +def test_create_dir_already_exists(tmp_path: Path, + caplog: LogCaptureFixture) -> None: path: Path = tmp_path/'new_dir' inf: tuple[str, int, str] = ('pyssg.utils', INFO, @@ -106,7 +111,9 @@ def test_create_dirs(tmp_path: Path, caplog: LogCaptureFixture) -> None: assert caplog.record_tuples[-1] == inf -def test_create_dirs_failure(tmp_path: Path, caplog: LogCaptureFixture) -> None: +# TODO: actually check the existence of the files and not just the log +def test_create_dirs_already_exists(tmp_path: Path, + caplog: LogCaptureFixture) -> None: path: Path = tmp_path/'new_dir' sub_path: Path = path/'sub_dir' inf: tuple[str, int, str] = ('pyssg.utils', @@ -131,7 +138,7 @@ def test_dir_structure(tmp_dir_structure: Path, exclude: list[str], exp_dir_str: list[str]) -> None: dir_str: list[str] = get_dir_structure(str(tmp_dir_structure), exclude) - # order doesn't matter + # order doesn't matter, only for checking that both lists contain the same assert sorted(dir_str) == sorted(exp_dir_str) @@ -158,5 +165,5 @@ def test_file_list(tmp_dir_structure: Path, exclude_dirs: list[str], exp_flist: list[str]) -> None: flist: list[str] = get_file_list(str(tmp_dir_structure), exts, exclude_dirs) - # order doesn't matter + # order doesn't matter, only for checking that both lists contain the same assert sorted(flist) == sorted(exp_flist) diff --git a/tests/test_yaml_parser.py b/tests/test_yaml_parser.py index 906c7e6..0d8df96 100644 --- a/tests/test_yaml_parser.py +++ b/tests/test_yaml_parser.py @@ -5,19 +5,19 @@ from pyssg.yaml_parser import get_parsed_yaml # and test the join functionality -def test_yaml_resource_read(simple_yaml: str, test_resource: str) -> None: - yaml: list[dict[str, Any]] = get_parsed_yaml(simple_yaml, test_resource) +def test_yaml_resource_read(default_yaml: str, config_resource: str) -> None: + yaml: list[dict[str, Any]] = get_parsed_yaml(default_yaml, config_resource) assert len(yaml) == 1 -def test_yaml_path_read(test_dir: str) -> None: - yaml_path: str = f'{test_dir}/io_files/simple.yaml' +def test_yaml_path_read(sample_files_path: str, default_yaml: str) -> None: + yaml_path: str = f'{sample_files_path}/config/{default_yaml}' yaml: list[dict[str, Any]] = get_parsed_yaml(yaml_path) assert len(yaml) == 1 -def test_yaml_join(simple_yaml: str, test_resource: str) -> None: - yaml: dict[str, Any] = get_parsed_yaml(simple_yaml, test_resource)[0] +def test_yaml_join(default_yaml: str, config_resource: str) -> None: + yaml: dict[str, Any] = get_parsed_yaml(default_yaml, config_resource)[0] define_str: str = '$PYSSG_HOME/pyssg/site_example/' assert yaml['define'] == define_str assert yaml['path']['src'] == f'{define_str}src' -- cgit v1.2.3-70-g09d2