Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Add test for empty data in PeriodGroupedData
Browse files Browse the repository at this point in the history
If an empty data array is passed to a query with a duration parameter,
currently we get a Python exception. This fixes that error.
  • Loading branch information
annapowellsmith committed Jul 15, 2014
1 parent 68ee108 commit c0dedcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backdrop/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def fill_missing_periods(self, start_date, end_date, collect=None):
def amount_to_shift(self, delta):
is_reversed = delta < 0

if len(self._data) == 0:
return 0

return min([
first_nonempty(i['values'], is_reversed) for i in self._data],
key=abs)
4 changes: 4 additions & 0 deletions tests/read/test_weekly_grouped_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ def test_filling_data_for_missing_weeks(self):
has_entry("_start_at", d_tz(2013, 4, 8)),
has_entry("_start_at", d_tz(2013, 4, 15))
))

def test_with_empty_data(self):
data = PeriodGroupedData([], WEEK)
assert_that(data.amount_to_shift(7), equal_to(0))

0 comments on commit c0dedcc

Please sign in to comment.