Skip to content

Commit

Permalink
deprecate COUNTER 3 support
Browse files Browse the repository at this point in the history
(also ran black on some unaffected files; should have been caught
earlier?)
  • Loading branch information
Wooble committed Sep 13, 2019
1 parent 2c90648 commit 75b6b11
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
7 changes: 1 addition & 6 deletions pycounter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@
u"Access denied category",
u"Reporting Period Total",
),
"PR1": (
u"Platform",
u"Publisher",
u"User Activity",
u"Reporting Period Total",
),
"PR1": (u"Platform", u"Publisher", u"User Activity", u"Reporting Period Total"),
# FIXME: this is outputting counter 5 reports in 4 format for... reasons.
"TR_J1": (
u"Journal",
Expand Down
31 changes: 20 additions & 11 deletions pycounter/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,20 +550,15 @@ class CounterPlatform(CounterEresource):
"""a COUNTER platform report line."""

def __init__(
self,
period=None,
metric=None,
month_data=None,
platform="",
publisher="",
self, period=None, metric=None, month_data=None, platform="", publisher=""
):
super(CounterPlatform, self).__init__(
period=period,
metric=metric,
month_data=month_data,
title='', # no title for platform report
title="", # no title for platform report
platform=platform,
publisher=publisher
publisher=publisher,
)
self.isbn = None

Expand Down Expand Up @@ -823,7 +818,7 @@ def _parse_line(line, report, last_col):
}
month_data = []
curr_month = report.period[0]
months_start_idx = 5 if report.report_type != 'PR1' else 4
months_start_idx = 5 if report.report_type != "PR1" else 4
for data in line[months_start_idx:]:
month_data.append((curr_month, format_stat(data)))
curr_month = next_month(curr_month)
Expand Down Expand Up @@ -853,8 +848,13 @@ def _parse_line(line, report, last_col):
return CounterDatabase(metric=line[3], month_data=month_data, **common_args)
elif report.report_type == "PR1":
# there is no title in the PR1 report
return CounterPlatform(metric=line[2], month_data=month_data, platform=line[0],
publisher=line[1], period=report.period)
return CounterPlatform(
metric=line[2],
month_data=month_data,
platform=line[0],
publisher=line[1],
period=report.period,
)
raise PycounterException("Should be unreachable") # pragma: no cover


Expand All @@ -876,6 +876,15 @@ def _get_type_and_version(specifier):
if not any(report_type.startswith(x) for x in ("JR", "BR", "DB", "PR1")):
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)
)
)

return report_type, report_version


Expand Down
6 changes: 4 additions & 2 deletions pycounter/sushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ def raw_to_full(raw_report):
pdf_usage += int(inst.Count)
elif inst.MetricType == "ft_html":
html_usage += int(inst.Count)
elif report.report_type.startswith("DB") or \
report.report_type == "PR1":
elif (
report.report_type.startswith("DB")
or report.report_type == "PR1"
):
metrics_for_db[inst.MetricType].append(
(item_date, int(inst.Count))
)
Expand Down
5 changes: 1 addition & 4 deletions pycounter/test/test_bad_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import pycounter.exceptions


@pytest.mark.parametrize(
"report_type",
[u"Bogus Report 7 (R4)"],
)
@pytest.mark.parametrize("report_type", [u"Bogus Report 7 (R4)"])
def test_report_type(report_type):
"""Report type doesn't exist."""
data = [[report_type]]
Expand Down
5 changes: 5 additions & 0 deletions pycounter/test/test_jr1_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def test_pdf(self):
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
16 changes: 11 additions & 5 deletions pycounter/test/test_output_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ def test_totals_sparse_data(tmp_path):

start = date(2019, 1, 1)
end = date(2019, 3, 31)
cb1 = CounterBook(period=(start, end), title="Book 1",
month_data=[(date(2019, 2, 1), 3), (date(2019, 3, 1), 5)])
cb2 = CounterBook(period=(start, end), title="Book 2",
month_data=[(date(2019, 1, 1), 1), (date(2019, 3, 1), 7)])
cb1 = CounterBook(
period=(start, end),
title="Book 1",
month_data=[(date(2019, 2, 1), 3), (date(2019, 3, 1), 5)],
)
cb2 = CounterBook(
period=(start, end),
title="Book 2",
month_data=[(date(2019, 1, 1), 1), (date(2019, 3, 1), 7)],
)
report = CounterReport(report_type="BR2", period=(start, end))
report.pubs = [cb1, cb2]
report.write_tsv(str(tmp_path / "outputfile.tsv"))
Expand All @@ -53,7 +59,7 @@ def test_totals_sparse_data(tmp_path):
totals_line = output_lines[8]
assert totals_line.startswith("Total for all titles")
totals = totals_line.split("\t")
assert [int(t) for t in totals[-3:]] == [0+1, 3+0, 5+7], "check totals match"
assert [int(t) for t in totals[-3:]] == [0 + 1, 3 + 0, 5 + 7], "check totals match"
# book 1 line
book_line = output_lines[9]
assert book_line.startswith("Book 1")
Expand Down
5 changes: 3 additions & 2 deletions pycounter/test/test_pr1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def test_reportname(self):

def test_stats(self):
publication = self.report.pubs[0]
self.assertEqual([x[2] for x in publication],
[91, 41, 13, 21, 44, 8, 0, 0, 36, 36, 7, 2])
self.assertEqual(
[x[2] for x in publication], [91, 41, 13, 21, 44, 8, 0, 0, 36, 36, 7, 2]
)

def test_row_metric(self):
# test metric of the first row
Expand Down

0 comments on commit 75b6b11

Please sign in to comment.