diff --git a/tests/test_read.py b/tests/test_read.py index b2c4a1f..b5d4f69 100644 --- a/tests/test_read.py +++ b/tests/test_read.py @@ -1,6 +1,4 @@ -import os import pytest -import sys from io import StringIO from wosfile.read import ( @@ -97,6 +95,12 @@ def test_forgotten_EF(self): with pytest.raises(ReadError): list(r) + def test_unknown_tag(self): + f = StringIO(preamble_s + "PT abc\n\nQQ x\nER\nEF") + r = PlainTextReader(f) + with pytest.raises(NotImplementedError): + list(r) + def test_ignore_empty_lines(self): f = StringIO(preamble_s + "PT abc\n\nAU xyz\nER\nEF") r = PlainTextReader(f) diff --git a/tests/test_record.py b/tests/test_record.py index 9ad4bf5..0204f59 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -66,6 +66,11 @@ def test_record_author_address(data, record_id, author_address): assert rec.author_address == author_address +def test_record_author_address_missing(): + rec = Record({}) + assert rec.author_address is None + + addresses = [ # (input, expected, exception) ( diff --git a/wosfile/read.py b/wosfile/read.py index cf1add4..2d75704 100644 --- a/wosfile/read.py +++ b/wosfile/read.py @@ -1,7 +1,6 @@ import codecs import logging import pathlib -import sys from csv import DictReader from typing import ( AnyStr, @@ -217,11 +216,13 @@ def _format_values(self, heading: str, values: List[str]) -> str: else: return " ".join(values) except KeyError: - msg = "\n------------ ERROR ------------\n" \ - "Seems that the tag \"{}\" is new and not yet handled by the wosfile library.\n" \ - "Please report this error:\n" \ - " https://github.com/rafguns/wosfile/issues\n" \ + msg = ( + "\n------------ ERROR ------------\n" + 'Seems that the tag "{}" is new and not yet handled by the wosfile library.\n' + "Please report this error:\n" + " https://github.com/rafguns/wosfile/issues\n" "We are sorry for the inconvenience.\n" + ) raise NotImplementedError(msg.format(heading)) def __next__(self) -> Dict[str, str]: diff --git a/wosfile/record.py b/wosfile/record.py index 51b265e..d180f8e 100644 --- a/wosfile/record.py +++ b/wosfile/record.py @@ -22,6 +22,7 @@ def __init__( :param bool skip_empty: whether or not to skip empty fields """ + super().__init__(self) self.skip_empty = skip_empty if wos_data: self.parse(wos_data)