From a849615b419a21954605ddbb5d34e10560c3c155 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sat, 27 Jul 2019 02:10:13 +0300 Subject: [PATCH] Add tests for check functions Relies on capturing stdout. See: https://docs.pytest.org/en/5.0.1/capture.html --- tests/test_check.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_check.py diff --git a/tests/test_check.py b/tests/test_check.py new file mode 100644 index 0000000..1f85eb9 --- /dev/null +++ b/tests/test_check.py @@ -0,0 +1,64 @@ +import csv_metadata_quality.check as check +import pytest + +def test_check_invalid_issn(capsys): + '''Test checking invalid ISSN.''' + + value = '2321-2302' + + check.issn(value) + + captured = capsys.readouterr() + assert captured.out == f'Invalid ISSN: {value}\n' + + +def test_check_valid_issn(): + '''Test checking valid ISSN.''' + + value = '0024-9319' + + result = check.issn(value) + + assert result == value + + +def test_check_invalid_isbn(capsys): + '''Test checking invalid ISBN.''' + + value = '99921-58-10-6' + + check.isbn(value) + + captured = capsys.readouterr() + assert captured.out == f'Invalid ISBN: {value}\n' + + +def test_check_valid_isbn(): + '''Test checking valid ISBN.''' + + value = '99921-58-10-7' + + result = check.isbn(value) + + assert result == value + + +def test_check_invalid_separators(capsys): + '''Test checking invalid multi-value separators.''' + + value = 'Alan|Orth' + + check.separators(value) + + captured = capsys.readouterr() + assert captured.out == f'Invalid multi-value separator: {value}\n' + + +def test_check_valid_separators(): + '''Test checking valid multi-value separators.''' + + value = 'Alan||Orth' + + result = check.separators(value) + + assert result == value