Fix up unit tests for new structure

This commit is contained in:
Patrick Robertson
2025-01-28 14:40:12 +01:00
parent 9635449ac0
commit 7a4871db6b
12 changed files with 150 additions and 88 deletions

View File

@@ -3,9 +3,10 @@ pytest conftest file, for shared fixtures and configuration
"""
from typing import Dict, Tuple
import hashlib
import pytest
from auto_archiver.core.metadata import Metadata
from auto_archiver.core.module import get_module, _LAZY_LOADED_MODULES
# Test names inserted into this list will be run last. This is useful for expensive/costly tests
# that you only want to run if everything else succeeds (e.g. API calls). The order here is important
@@ -13,6 +14,36 @@ from auto_archiver.core.metadata import Metadata
# format is the name of the module (python file) without the .py extension
TESTS_TO_RUN_LAST = ['test_twitter_api_archiver']
@pytest.fixture
def setup_module(request):
def _setup_module(module_name, config={}):
if isinstance(module_name, type):
# get the module name:
# if the class does not have a .name, use the name of the parent folder
module_name = module_name.__module__.rsplit(".",2)[-2]
m = get_module(module_name).load()
m.name = module_name
m.setup({module_name : config})
def cleanup():
_LAZY_LOADED_MODULES.pop(module_name)
request.addfinalizer(cleanup)
return m
return _setup_module
@pytest.fixture
def check_hash():
def _check_hash(filename: str, hash: str):
with open(filename, "rb") as f:
buf = f.read()
assert hash == hashlib.sha256(buf).hexdigest()
return _check_hash
@pytest.fixture
def make_item():