Skip to content

Commit

Permalink
Upgrade the version of timew-report
Browse files Browse the repository at this point in the history
The version of `timew-report` was restricted in #10 to deal with failing
tests. This change updates the version required by the `Pipfile` and
makes the following code changes:

1. Update a test helper to pass in a value for the new required argument
   `annotation`. This is not used by the test suite, so the helper uses
   `None` for now.

2. Addresses some breaking changes and deprecation warnings in
   `get_date` released in [1.4]. `get_date` now returns a `date` instead
   of a `datetime`. `get_start_date` offers the same implementation that
   `get_date` used to, so no logic has changed here, and this avoids
   deprecation warnings.

[1.4]: lauft/timew-report@a964eb3
  • Loading branch information
jonafato committed Sep 17, 2021
1 parent fb9dd5f commit 239afee
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
timew-report = "<1.3"
timew-report = ">=1.4"

[dev-packages]
pytest = "*"
Expand Down
30 changes: 27 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions billwarrior/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def __init__(self, intervals, config):

for category in sorted(sorted_intervals.keys(), key=config.text_for):
intervals = sorted_intervals[category]
days = set([interval.get_date().date() for interval in intervals])
days = set([interval.get_start_date() for interval in intervals])
intervals_by_day = {
day: [i for i in intervals if i.get_date().date() == day]
day: [i for i in intervals if i.get_start_date() == day]
for day in days
}

Expand Down
30 changes: 15 additions & 15 deletions tests/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_creates_different_categories_from_interval_tags_and_mapping(self):
items = invoice.items()

expected_a, expected_b = (
ItemCategory("Consulting & Research", {a.get_date().date(): [a]}, 0.0),
ItemCategory("Travel", {b.get_date().date(): [b]}, 0.0),
ItemCategory("Consulting & Research", {a.get_start_date(): [a]}, 0.0),
ItemCategory("Travel", {b.get_start_date(): [b]}, 0.0),
)

self.assertEqual(len(items), 2)
Expand All @@ -91,7 +91,7 @@ def test_groups_intervals_of_same_category(self):

expected = ItemCategory(
"Consulting & Research",
{same_day.date(): [a, b], c.get_date().date(): [c]},
{same_day.date(): [a, b], c.get_start_date(): [c]},
0.0,
)

Expand Down Expand Up @@ -155,12 +155,12 @@ def test_sets_unit_price_for_item_category(self):
expected_a, expected_b = (
ItemCategory(
"Consulting & Research",
{a.get_date().date(): [a]},
{a.get_start_date(): [a]},
billw_config.rate_for(category_a),
),
ItemCategory(
"Software Development",
{b.get_date().date(): [b]},
{b.get_start_date(): [b]},
billw_config.rate_for(category_b),
),
)
Expand Down Expand Up @@ -189,12 +189,12 @@ def test_alpha_orders_categories(self):
expected_a, expected_b = (
ItemCategory(
"Consulting & Research",
{a.get_date().date(): [a]},
{a.get_start_date(): [a]},
billw_config.rate_for(category_a),
),
ItemCategory(
"Software Development",
{b.get_date().date(): [b]},
{b.get_start_date(): [b]},
billw_config.rate_for(category_b),
),
)
Expand All @@ -219,12 +219,12 @@ def test_prints_invoice_categories_and_items(self):
expected_a, expected_b = (
ItemCategory(
"Consulting & Research",
{a.get_date().date(): [a]},
{a.get_start_date(): [a]},
billw_config.rate_for(category_a),
),
ItemCategory(
"Software Development",
{b.get_date().date(): [b]},
{b.get_start_date(): [b]},
billw_config.rate_for(category_b),
),
)
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_line_items_should_be_populated_with_entries_per_day(self):
[tests.give_interval(a_day + timedelta(days=2))],
[tests.give_interval(a_day + timedelta(days=3))],
]
intervals_by_day = {entry[0].get_date().date(): entry for entry in entries}
intervals_by_day = {entry[0].get_start_date(): entry for entry in entries}

category = ItemCategory("arbitray category", intervals_by_day, 0.0)

Expand All @@ -265,11 +265,11 @@ def test_line_items_should_be_sorted_by_date(self):
[tests.give_interval()],
[tests.give_interval()],
]
dates = [entry[0].get_date().date() for entry in entries]
dates = [entry[0].get_start_date() for entry in entries]

category = ItemCategory("arbitray category", dict(zip(dates, entries)), 0.0)

sorted_date_list = sorted([entry[0].get_date().date() for entry in entries])
sorted_date_list = sorted([entry[0].get_start_date() for entry in entries])
self.assertListEqual(
[
datetime.strptime(line_item.date, "%B %d, %Y").date()
Expand All @@ -280,7 +280,7 @@ def test_line_items_should_be_sorted_by_date(self):

def test_str_should_display_header_line_items_and_subtotal_as_latex_output(self):
a, b = tests.give_interval(), tests.give_interval()
entries = {a.get_date().date(): [a], b.get_date().date(): [b]}
entries = {a.get_start_date(): [a], b.get_start_date(): [b]}

category = ItemCategory("arbitrary category", entries, 0.0)

Expand All @@ -289,8 +289,8 @@ def test_str_should_display_header_line_items_and_subtotal_as_latex_output(self)
"\\feetype{%s}\n" % category.header,
"".join(
[
"%s\n" % LineItem(i.get_date(), i.get_duration(), 0.0)
for i in sorted([a, b], key=lambda x: x.get_date())
"%s\n" % LineItem(i.get_start_date(), i.get_duration(), 0.0)
for i in sorted([a, b], key=lambda x: x.get_start_date())
]
),
"\\subtotal\n",
Expand Down
2 changes: 1 addition & 1 deletion tests/testsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def give_interval(day=None, tags=[]):

end = start + timedelta(0, randint(60 * 5, 60 * 60 * 2)) # up to 2h

return TimeWarriorInterval(start.strftime(DT_FORMAT), end.strftime(DT_FORMAT), tags)
return TimeWarriorInterval(start.strftime(DT_FORMAT), end.strftime(DT_FORMAT), tags, None)

0 comments on commit 239afee

Please sign in to comment.