55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""test_extract_odf_links.py - Unit tests for ODF link extraction"""
|
|
# Copyright © 2020 Brett Smith
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import io
|
|
|
|
import pytest
|
|
|
|
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')),
|
|
}
|
|
|
|
@pytest.mark.parametrize('arglist,sep', [
|
|
(['-0'], '\0'),
|
|
(['-d', '\\v'], '\v'),
|
|
([str(SRC_PATH)], '\n'), # Test that links aren't duplicated
|
|
])
|
|
def test_extract_file_links(arglist, sep, caplog):
|
|
arglist.append(str(SRC_PATH))
|
|
stdout = io.StringIO()
|
|
stderr = io.StringIO()
|
|
exitcode = extract_odf_links.main(arglist, stdout, stderr)
|
|
assert exitcode == 0
|
|
assert not stderr.getvalue()
|
|
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
|
|
assert caplog.records
|
|
assert any(
|
|
log.levelname == 'WARNING'
|
|
and log.message.endswith('/Bad Link.txt not found')
|
|
for log in caplog.records
|
|
)
|