tests: Reorganize extract_odf_links tests for new feature.

This commit is contained in:
Brett Smith 2020-08-30 09:18:41 -04:00
parent 977b16e365
commit cf2d825a08

View file

@ -18,18 +18,26 @@ import io
import pytest
from pathlib import Path
from . import testutil
from conservancy_beancount.tools import extract_odf_links
SRC_PATH = testutil.test_path('repository/LinksReport.ods')
EXPECTED_FILE_LINKS = {
'/repository/Projects/project-data.yml',
str(testutil.test_path('repository/Projects/project-data.yml')),
str(testutil.test_path('repository/Projects/Bad Link.txt')),
INCLUDED_FILE_LINKS = {
Path('/repository/Projects/project-data.yml'),
Path('Projects/project-data.yml'),
Path('Projects/Bad Link.txt'),
}
def expected_links(rel_path):
return frozenset(
str(path if path.is_absolute() else rel_path / path)
for path in INCLUDED_FILE_LINKS
)
@pytest.mark.parametrize('arglist,sep', [
(['-0'], '\0'),
(['-d', '\\v'], '\v'),
@ -45,8 +53,9 @@ def test_extract_file_links(arglist, sep, caplog):
actual = stdout.getvalue().split(sep)
if actual and not actual[-1]:
actual.pop()
assert len(actual) == len(EXPECTED_FILE_LINKS)
assert set(actual) == EXPECTED_FILE_LINKS
expected = expected_links(SRC_PATH.parent)
assert len(actual) == len(expected)
assert set(actual) == expected
assert caplog.records
assert any(
log.levelname == 'WARNING'