Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
rafguns committed Apr 27, 2022
1 parent b919ec3 commit ffc24c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions tests/test_read.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import pytest
import sys
from io import StringIO

from wosfile.read import (
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
(
Expand Down
11 changes: 6 additions & 5 deletions wosfile/read.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import codecs
import logging
import pathlib
import sys
from csv import DictReader
from typing import (
AnyStr,
Expand Down Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions wosfile/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ffc24c0

Please sign in to comment.