Skip to content

Commit

Permalink
remove deprecated CounterReport.year and COUNTER 3 parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Wooble committed Sep 13, 2019
1 parent 1f88f71 commit 3754869
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 167 deletions.
33 changes: 5 additions & 28 deletions pycounter/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(
self.date_run = datetime.date.today()
else:
self.date_run = date_run
self._year = None
self.section_type = section_type

def __repr__(self):
Expand All @@ -93,21 +92,6 @@ def __repr__(self):
self.period[1],
)

@property
def year(self):
warnings.warn(
DeprecationWarning(
"CounterReport.year is deprecated."
"Reports may span multiple years. "
"COUNTER 5 reports will not have a year set."
)
)
return self._year

@year.setter
def year(self, value):
self._year = value

def __iter__(self):
return iter(self.pubs)

Expand Down Expand Up @@ -745,7 +729,7 @@ def parse_generic(report_reader):

if report.report_version < 5:
try:
report.year = _year_from_header(header, report)
year = _year_from_header(header, report)
except AttributeError:
warnings.warn("Could not determine year from malformed header")

Expand All @@ -762,7 +746,7 @@ def parse_generic(report_reader):
break
last_col += 1

start_date = datetime.date(report.year, 1, 1)
start_date = datetime.date(year, 1, 1)
end_date = last_day(convert_date_column(header[last_col - 1]))
report.period = (start_date, end_date)

Expand Down Expand Up @@ -892,13 +876,7 @@ def _get_type_and_version(specifier):
raise UnknownReportTypeError(report_type)

if report_version < 4:
warnings.warn(
DeprecationWarning(
"Parsing COUNTER versions before 4 ("
"current: {}) will not be supported in "
"the next release of pycounter.".format(report_version)
)
)
raise UnknownReportTypeError("Only COUNTER 4&5 are supported.")

return report_type, report_version

Expand All @@ -909,10 +887,9 @@ def _get_c5_type_and_version(second_line, third_line):


def _year_from_header(header, report):
"""Get the year for the report from the header.
"""Get the year of the first month in the report from the header.
NOTE: for multi-year reports, this will be the date of the first month,
and probably doesn't make sense to talk of a report having a year...
(Only used for COUNTER 4.)
"""
first_date_col = 10 if report.report_version == 4 else 5
if report.report_type in ("BR1", "BR2") and report.report_version == 4:
Expand Down
16 changes: 4 additions & 12 deletions pycounter/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def parsedata(filename):
return report.parse(os.path.join(os.path.dirname(__file__), "data", filename))


@pytest.fixture(
params=["csvC4JR1", "C4JR1.csv", "simpleJR1.csv", "C4JR1_bad.csv", "C4JR1GOA.csv"]
)
@pytest.fixture(params=["csvC4JR1", "C4JR1.csv", "C4JR1_bad.csv", "C4JR1GOA.csv"])
def csv_jr1_report(request):
"""Various CSV format JR1 reports."""
return parsedata(request.param)
Expand All @@ -27,13 +25,13 @@ def tsv_jr1(request):
return parsedata(request.param)


@pytest.fixture(params=["csvC4JR1", "C4JR1.csv", "simpleJR1.csv", "C4JR1_bad.csv"])
@pytest.fixture(params=["csvC4JR1", "C4JR1.csv", "C4JR1_bad.csv"])
def csv_jr1_report_std(request):
"""Standard (non-GOA) JR1 reports."""
return parsedata(request.param)


@pytest.fixture(params=["csvC4JR1", "C4JR1.csv", "simpleJR1.csv"])
@pytest.fixture(params=["csvC4JR1", "C4JR1.csv"])
def csv_jr1_report_common_data(request):
"""JR1 reports with shared common data we can make assertions about."""
return parsedata(request.param)
Expand Down Expand Up @@ -116,13 +114,7 @@ def common_output(request):
return parsedata(request.param).as_generic(), content


@pytest.fixture(params=["simpleBR1.csv", "simpleBR2.csv"])
def br_c1(request):
"""Version 1 (COUNTER 3) book reports."""
return parsedata(request.param)


@pytest.fixture(params=["C4BR2.tsv", "C4BR1.tsv", "simpleBR1.csv", "simpleBR2.csv"])
@pytest.fixture(params=["C4BR2.tsv", "C4BR1.tsv"])
def all_book_reports(request):
"""All book reports."""
return parsedata(request.param)
Expand Down
8 changes: 0 additions & 8 deletions pycounter/test/data/simpleBR1.csv

This file was deleted.

8 changes: 0 additions & 8 deletions pycounter/test/data/simpleBR2.csv

This file was deleted.

8 changes: 0 additions & 8 deletions pycounter/test/data/simpleBR2_latin_1.csv

This file was deleted.

8 changes: 0 additions & 8 deletions pycounter/test/data/simpleJR1.csv

This file was deleted.

12 changes: 0 additions & 12 deletions pycounter/test/test_br1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
import pycounter.report


class ParseExample(unittest.TestCase):
"""Tests for parsing C3 BR1"""

def setUp(self):
self.report = pycounter.report.parse(
os.path.join(os.path.dirname(__file__), "data/simpleBR1.csv")
)

def test_reportname(self):
self.assertEqual(self.report.report_type, u"BR1")


class ParseCounter4Example(unittest.TestCase):
"""Tests for parsing C4 BR1"""

Expand Down
27 changes: 0 additions & 27 deletions pycounter/test/test_br2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
import pycounter.report


class ParseExample(unittest.TestCase):
"""Tests for parsing C3 BR2"""

def setUp(self):
self.report = pycounter.report.parse(
os.path.join(os.path.dirname(__file__), "data/simpleBR2.csv")
)

def test_reportname(self):
self.assertEqual(self.report.report_type, u"BR2")


class ParseCounter4Example(unittest.TestCase):
"""Tests for parsing C4 BR2"""

Expand All @@ -36,18 +24,3 @@ def test_reportname(self):

def test_metric(self):
self.assertEqual(self.report.metric, u"Book Section Requests")


class ParseLatin1(unittest.TestCase):
"""Tests for parsing BR2 in latin-1 encoding"""

def setUp(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.report = pycounter.report.parse(
os.path.join(os.path.dirname(__file__), "data/simpleBR2_latin_1.csv")
)

def test_title(self):
publication = self.report.pubs[1]
self.assertEqual(publication.title, u"Öfake Book")
8 changes: 0 additions & 8 deletions pycounter/test/test_br_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
import datetime


def test_version(br_c1):
assert br_c1.report_version == 1


def test_year(all_book_reports):
assert all_book_reports.year == 2012


def test_publisher(all_book_reports):
for publication in all_book_reports:
assert publication.publisher == u"Megadodo Publications"
Expand Down
4 changes: 2 additions & 2 deletions pycounter/test/test_db1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def setUp(self):
os.path.join(os.path.dirname(__file__), "data/C4DB1_split_year.tsv")
)

def test_year(self):
self.assertEqual(self.report.year, 2012)
def test_reportname(self):
self.assertEqual(self.report.report_type, u"DB1")
4 changes: 0 additions & 4 deletions pycounter/test/test_db_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def test_version(db_report):
assert db_report.report_version == 4


def test_year(db_report):
assert db_report.year == 2012


def test_publisher(db_report):
for publication in db_report:
assert publication.publisher == u"Megadodo Publications"
Expand Down
37 changes: 0 additions & 37 deletions pycounter/test/test_jr1_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,6 @@ def test_ibsn(csv_jr1_r4_report):
assert csv_jr1_r4_report.pubs[1].isbn is None


class ParseExample(unittest.TestCase):
"""Tests for parsing C3 JR1"""

def setUp(self):
self.report = report.parse(
os.path.join(os.path.dirname(__file__), "data/simpleJR1.csv")
)

def test_reportname(self):
self.assertEqual(self.report.report_version, 3)

def test_year(self):
self.assertEqual(self.report.year, 2011)

def test_platform(self):
for publication in self.report:
self.assertEqual(publication.publisher, u"Maximegalon University Press")
self.assertEqual(publication.platform, u"MJO")

def test_html(self):
expected = [0, 0]
actual = [pub.html_total for pub in self.report.pubs]

self.assertEqual(actual, expected)

def test_pdf(self):
expected = [0, 16]
actual = [pub.pdf_total for pub in self.report.pubs]

self.assertEqual(actual, expected)


def test_counter3_deprecation():
with pytest.warns(DeprecationWarning):
report.parse(os.path.join(os.path.dirname(__file__), "data/simpleJR1.csv"))


class ParseMultiyear(unittest.TestCase):
"""Multi-year COUNTER report
"""
Expand Down
4 changes: 0 additions & 4 deletions pycounter/test/test_jr1_xslx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def test_report_version(jr1_report_xlsx):
assert jr1_report_xlsx.report_version == 4


def test_year(jr1_report_xlsx):
assert jr1_report_xlsx.year == 2013


def test_publisher(jr1_report_xlsx):
assert all( # pragma: no branch
publication.publisher == u"American Medical Association"
Expand Down
2 changes: 1 addition & 1 deletion pycounter/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.parametrize("attribute", ["title", "publisher", "platform"])
@pytest.mark.parametrize("filename", ["JR1.xlsx", "simpleJR1.tsv", "simpleJR1.csv"])
@pytest.mark.parametrize("filename", ["JR1.xlsx", "simpleJR1.tsv"])
def test_unicode_fields(filename, attribute):
"""All parsers should return text fields as unicode"""
rep = report.parse(os.path.join(os.path.dirname(__file__), "data", filename))
Expand Down

0 comments on commit 3754869

Please sign in to comment.