summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2023-04-25 04:03:48 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2023-04-25 04:03:48 -0600
commit1b2d6aff6ccf72fdb292a1f05bb41bf9633a8f55 (patch)
tree435d5752fc5c50a3453e550c7f95f85b70d8ad2a /tests
parent42a135329e69360745294e7bcdd4261318aeafc0 (diff)
refactor tests and add more typing
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py31
-rw-r--r--tests/sample_files/__init__.py (renamed from tests/io_files/__init__.py)0
-rw-r--r--tests/sample_files/checksum.txt1
-rw-r--r--tests/sample_files/config/__init__.py (renamed from tests/io_files/md/__init__.py)0
-rw-r--r--tests/sample_files/config/default.yaml (renamed from tests/io_files/simple.yaml)5
-rw-r--r--tests/sample_files/config/default_missing_dirs.yaml (renamed from tests/io_files/simple_missing_dirs.yaml)6
-rw-r--r--tests/sample_files/config/default_missing_mandatory_key.yaml (renamed from tests/io_files/simple_missing_key.yaml)5
-rw-r--r--tests/sample_files/config/default_missing_root_dir.yaml (renamed from tests/io_files/simple_missing_root_dir.yaml)6
-rw-r--r--tests/sample_files/config/multiple_default.yaml (renamed from tests/io_files/multiple.yaml)10
-rw-r--r--tests/sample_files/config/multiple_default_one_doc_error.yaml (renamed from tests/io_files/multiple_one_doc_error.yaml)9
-rw-r--r--tests/sample_files/md/__init__.py (renamed from tests/io_files/md/a/__init__.py)0
-rw-r--r--tests/sample_files/md/a/__init__.py0
-rw-r--r--tests/sample_files/md/a/second.md (renamed from tests/io_files/md/a/second.md)0
-rw-r--r--tests/sample_files/md/first.md (renamed from tests/io_files/md/first.md)0
-rw-r--r--tests/sample_files/md/new.md (renamed from tests/io_files/md/new.md)0
-rw-r--r--tests/test_configuration.py54
-rw-r--r--tests/test_database.py9
-rw-r--r--tests/test_utils.py23
-rw-r--r--tests/test_yaml_parser.py12
19 files changed, 69 insertions, 102 deletions
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/sample_files/__init__.py
index e69de29..e69de29 100644
--- a/tests/io_files/__init__.py
+++ b/tests/sample_files/__init__.py
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/io_files/md/__init__.py b/tests/sample_files/config/__init__.py
index e69de29..e69de29 100644
--- a/tests/io_files/md/__init__.py
+++ b/tests/sample_files/config/__init__.py
diff --git a/tests/io_files/simple.yaml b/tests/sample_files/config/default.yaml
index df3888b..08121a6 100644
--- a/tests/io_files/simple.yaml
+++ b/tests/sample_files/config/default.yaml
@@ -10,12 +10,8 @@ path:
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:
@@ -24,5 +20,4 @@ dirs:
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/sample_files/config/default_missing_dirs.yaml
index aa15fb5..03ee35a 100644
--- a/tests/io_files/simple_missing_dirs.yaml
+++ b/tests/sample_files/config/default_missing_dirs.yaml
@@ -10,12 +10,8 @@ path:
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
+# test missing dirs (doesn't have any)
... \ No newline at end of file
diff --git a/tests/io_files/simple_missing_key.yaml b/tests/sample_files/config/default_missing_mandatory_key.yaml
index ac81563..b5554f7 100644
--- a/tests/io_files/simple_missing_key.yaml
+++ b/tests/sample_files/config/default_missing_mandatory_key.yaml
@@ -11,12 +11,8 @@ path:
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:
@@ -25,5 +21,4 @@ dirs:
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/sample_files/config/default_missing_root_dir.yaml
index 07fa824..896e141 100644
--- a/tests/io_files/simple_missing_root_dir.yaml
+++ b/tests/sample_files/config/default_missing_root_dir.yaml
@@ -10,13 +10,9 @@ path:
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 /:
+# test missing "/" dir in specific
something:
... \ No newline at end of file
diff --git a/tests/io_files/multiple.yaml b/tests/sample_files/config/multiple_default.yaml
index 8d99c40..54954b1 100644
--- a/tests/io_files/multiple.yaml
+++ b/tests/sample_files/config/multiple_default.yaml
@@ -10,12 +10,8 @@ path:
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:
@@ -24,7 +20,6 @@ dirs:
index: False
rss: False
sitemap: False
- exclude_dirs: []
...
---
define: &root "$PYSSG_HOME/pyssg/site_example/"
@@ -37,12 +32,8 @@ path:
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:
@@ -51,5 +42,4 @@ dirs:
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/sample_files/config/multiple_default_one_doc_error.yaml
index 86f6546..44d9beb 100644
--- a/tests/io_files/multiple_one_doc_error.yaml
+++ b/tests/sample_files/config/multiple_default_one_doc_error.yaml
@@ -10,12 +10,8 @@ path:
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:
@@ -24,7 +20,6 @@ dirs:
index: False
rss: False
sitemap: False
- exclude_dirs: []
...
---
define: &root "$PYSSG_HOME/pyssg/site_example/"
@@ -37,12 +32,8 @@ path:
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/md/a/__init__.py b/tests/sample_files/md/__init__.py
index e69de29..e69de29 100644
--- a/tests/io_files/md/a/__init__.py
+++ b/tests/sample_files/md/__init__.py
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
--- /dev/null
+++ b/tests/sample_files/md/a/__init__.py
diff --git a/tests/io_files/md/a/second.md b/tests/sample_files/md/a/second.md
index cb4e333..cb4e333 100644
--- a/tests/io_files/md/a/second.md
+++ b/tests/sample_files/md/a/second.md
diff --git a/tests/io_files/md/first.md b/tests/sample_files/md/first.md
index 567ea3e..567ea3e 100644
--- a/tests/io_files/md/first.md
+++ b/tests/sample_files/md/first.md
diff --git a/tests/io_files/md/new.md b/tests/sample_files/md/new.md
index ce684a7..ce684a7 100644
--- a/tests/io_files/md/new.md
+++ b/tests/sample_files/md/new.md
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'