def check_monthly_period_range(start_date, end_date, frequency, expected): range = period_range(date(2013, 3, 1), date(2013, 3, 31), 'monthly') assert_that(range, only_contains( (date(2013, 3, 1), date(2013, 3, 31)) )) another_range = list( period_range( date(2012, 12, 1), date(2013, 2, 28), 'monthly') ) print another_range assert_that(another_range, only_contains( (date(2012, 12, 1), date(2012, 12, 31)), (date(2013, 1, 1), date(2013, 1, 31)), (date(2013, 2, 1), date(2013, 2, 28)), )) another_range = list( period_range( date(2012, 12, 20), date(2013, 2, 28), 'monthly') ) print another_range assert_that(another_range, only_contains( (date(2012, 12, 1), date(2012, 12, 31)), (date(2013, 1, 1), date(2013, 1, 31)), (date(2013, 2, 1), date(2013, 2, 28)), ))
def check_monthly_period_range(start_date, end_date, frequency, expected): range = period_range(date(2013, 3, 1), date(2013, 3, 31), 'monthly') assert_that(range, only_contains((date(2013, 3, 1), date(2013, 3, 31)))) another_range = list( period_range(date(2012, 12, 1), date(2013, 2, 28), 'monthly')) print another_range assert_that( another_range, only_contains( (date(2012, 12, 1), date(2012, 12, 31)), (date(2013, 1, 1), date(2013, 1, 31)), (date(2013, 2, 1), date(2013, 2, 28)), )) another_range = list( period_range(date(2012, 12, 20), date(2013, 2, 28), 'monthly')) print another_range assert_that( another_range, only_contains( (date(2012, 12, 1), date(2012, 12, 31)), (date(2013, 1, 1), date(2013, 1, 31)), (date(2013, 2, 1), date(2013, 2, 28)), ))
def test_daily_period_range(): range = period_range(date(2013, 4, 1), date(2013, 4, 1), 'daily') assert_that(range, only_contains((date(2013, 4, 1), date(2013, 4, 1)))) another_range = period_range(date(2013, 4, 1), date(2013, 4, 3), 'daily') assert_that( another_range, only_contains( (date(2013, 4, 1), date(2013, 4, 1)), (date(2013, 4, 2), date(2013, 4, 2)), (date(2013, 4, 3), date(2013, 4, 3)), ))
def test_weekly_period_range(): range = period_range(date(2013, 4, 1), date(2013, 4, 7), 'weekly') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 7)) )) another_range = period_range(date(2013, 4, 1), date(2013, 4, 21), 'weekly') assert_that(another_range, only_contains( (date(2013, 4, 1), date(2013, 4, 7)), (date(2013, 4, 8), date(2013, 4, 14)), (date(2013, 4, 15), date(2013, 4, 21)), ))
def test_daily_period_range(): range = period_range(date(2013, 4, 1), date(2013, 4, 1), 'daily') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 1)) )) another_range = period_range(date(2013, 4, 1), date(2013, 4, 3), 'daily') assert_that(another_range, only_contains( (date(2013, 4, 1), date(2013, 4, 1)), (date(2013, 4, 2), date(2013, 4, 2)), (date(2013, 4, 3), date(2013, 4, 3)), ))
def test_weekly_period_range(): range = period_range(date(2013, 4, 1), date(2013, 4, 7), 'weekly') assert_that(range, only_contains((date(2013, 4, 1), date(2013, 4, 7)))) another_range = period_range(date(2013, 4, 1), date(2013, 4, 21), 'weekly') assert_that( another_range, only_contains( (date(2013, 4, 1), date(2013, 4, 7)), (date(2013, 4, 8), date(2013, 4, 14)), (date(2013, 4, 15), date(2013, 4, 21)), ))
def test_monthly_period_range_defaults_to_a_month_ago(): range = period_range(None, None, 'monthly') # from pprint import pprint # pprint(range) assert_that(range, only_contains( (date(2013, 3, 1), date(2013, 3, 31)) ))
def test_daily_period_range_fails_when_end_is_before_start(): list(period_range(date(2013, 4, 8), date(2013, 4, 1), 'daily'))
def test_daily_period_range_defaults_to_a_day_ago(): range = period_range(None, None, 'daily') assert_that(range, only_contains((date(2013, 4, 1), date(2013, 4, 1))))
def test_weekly_period_range_defaults_to_a_week_ago(): range = period_range(None, None, 'weekly') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 7)) ))
def test_monthly_period_range_defaults_to_a_month_ago(): range = period_range(None, None, 'monthly') # from pprint import pprint # pprint(range) assert_that(range, only_contains((date(2013, 3, 1), date(2013, 3, 31))))
def test_weekly_period_range_gets_the_containing_week_when_start_equals_end(): range = period_range(date(2013, 4, 8), date(2013, 4, 8), 'weekly') assert_that(range, only_contains((date(2013, 4, 8), date(2013, 4, 14))))
def test_weekly_period_range_adjusts_dates(): range = period_range(date(2013, 4, 3), date(2013, 4, 10), 'weekly') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 7)), (date(2013, 4, 8), date(2013, 4, 14)) ))
def test_weekly_period_range_adjusts_dates(): range = period_range(date(2013, 4, 3), date(2013, 4, 10), 'weekly') assert_that( range, only_contains((date(2013, 4, 1), date(2013, 4, 7)), (date(2013, 4, 8), date(2013, 4, 14))))
def test_daily_period_range_fails_when_end_is_before_start(): list(period_range(date(2013, 4, 8), date(2013, 4, 1), 'daily'))
def test_daily_period_range_between_datetime_and_date(): range = period_range(datetime(2013, 4, 1), date(2013, 4, 2), 'daily') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 1)), (date(2013, 4, 2), date(2013, 4, 2)) ))
def test_daily_period_range_defaults_to_a_day_ago(): range = period_range(None, None, 'daily') assert_that(range, only_contains( (date(2013, 4, 1), date(2013, 4, 1)) ))
def test_weekly_period_range_gets_the_containing_week_when_start_equals_end(): range = period_range(date(2013, 4, 8), date(2013, 4, 8), 'weekly') assert_that(range, only_contains( (date(2013, 4, 8), date(2013, 4, 14)) ))
def test_daily_period_range_returns_the_containing_day_when_start_equals_end(): range = period_range(date(2013, 4, 8), date(2013, 4, 8), 'daily') assert_that(range, only_contains((date(2013, 4, 8), date(2013, 4, 8))))
def test_daily_period_range_returns_the_containing_day_when_start_equals_end(): range = period_range(date(2013, 4, 8), date(2013, 4, 8), 'daily') assert_that(range, only_contains( (date(2013, 4, 8), date(2013, 4, 8)) ))
def test_weekly_period_range_between_datetime_and_date(): range = period_range(datetime(2013, 4, 1), date(2013, 4, 7), 'weekly') assert_that(range, only_contains((date(2013, 4, 1), date(2013, 4, 7))))
def test_weekly_period_range_defaults_to_a_week_ago(): range = period_range(None, None, 'weekly') assert_that(range, only_contains((date(2013, 4, 1), date(2013, 4, 7))))
def query_for_range(client, query, range_start, range_end): frequency = query.get('frequency', 'weekly') for start, end in period_range(range_start, range_end, frequency): for record in query_ga(client, query, start, end): yield record
def query_for_range(client, query, range_start, range_end): frequency = query.get('frequency', 'weekly') for start, end in period_range(range_start, range_end, frequency): for record in query_ga(client, query, start, end): yield record