Files
auto-archiver/tests/test_implementation.py
Patrick Robertson 3c543a3a6a Various fixes for issues with new architecture (#208)
* Add formatters to the TOC - fixes #204

* Add 'steps' settings to the example YAML in the docs. Fixes #206

* Improved docs on authentication architecture

* Fix setting modules on the command line - they now override any module settings in the orchestration as opposed to appending

* Fix tests for gsheet-feeder: add a test service_account.json (note: not real keys in there)

* Rename the command line entrypoint to _command_line_run

Also: make it clear that code implementation should not call this
Make sure the command line entry returns (we don't want a generator)

* Fix unit tests to use now code-entry points

* Version bump

* Move iterating of generator up to __main__

* Breakpoint

* two minor fixes

* Fix unit tests + add new '__main__' entry point implementation test

* Skip youtube tests if running on CI. Should still run them locally

* Fix full implementation run on GH actions

* Fix skipif test for GH Actions CI

* Add skipifs for truth - it blocks GH:

---------

Co-authored-by: msramalho <19508417+msramalho@users.noreply.github.com>
2025-02-18 19:10:09 +00:00

74 lines
2.4 KiB
Python

import sys
import pytest
from auto_archiver.__main__ import main
@pytest.fixture
def orchestration_file_path(tmp_path):
return (tmp_path / "example_orch.yaml").as_posix()
@pytest.fixture
def orchestration_file(orchestration_file_path):
def _orchestration_file(content=''):
with open(orchestration_file_path, "w") as f:
f.write(content)
return orchestration_file_path
return _orchestration_file
@pytest.fixture
def autoarchiver(tmp_path, monkeypatch, request):
def _autoarchiver(args=[]):
def cleanup():
from loguru import logger
if not logger._core.handlers.get(0):
logger._core.handlers_count = 0
logger.add(sys.stderr)
request.addfinalizer(cleanup)
# change dir to tmp_path
monkeypatch.chdir(tmp_path)
with monkeypatch.context() as m:
m.setattr(sys, "argv", ["auto-archiver"] + args)
return main()
return _autoarchiver
def test_run_auto_archiver_no_args(caplog, autoarchiver):
with pytest.raises(SystemExit):
autoarchiver()
assert "provide at least one URL via the command line, or set up an alternative feeder" in caplog.text
def test_run_auto_archiver_invalid_file(caplog, autoarchiver):
# exec 'auto-archiver' on the command lin
with pytest.raises(SystemExit):
autoarchiver(["--config", "nonexistent_file.yaml"])
assert "Make sure the file exists and try again, or run without th" in caplog.text
def test_run_auto_archiver_empty_file(caplog, autoarchiver, orchestration_file):
# create a valid (empty) orchestration file
path = orchestration_file(content="")
# exec 'auto-archiver' on the command lin
with pytest.raises(SystemExit):
autoarchiver(["--config", path])
# should treat an empty file as if there is no file at all
assert " No URLs provided. Please provide at least one URL via the com" in caplog.text
def test_call_autoarchiver_main(caplog, monkeypatch, tmp_path):
from auto_archiver.__main__ import main
# monkey patch to change the current working directory, so that we don't use the user's real config file
monkeypatch.chdir(tmp_path)
with monkeypatch.context() as m:
m.setattr(sys, "argv", ["auto-archiver"])
with pytest.raises(SystemExit):
main()
assert "No URLs provided. Please provide at least one" in caplog.text