|
1 | 1 | from mamba import description, context, it
|
2 | 2 | from expects import *
|
| 3 | +from datetime import datetime |
3 | 4 |
|
4 | 5 | from ooui.graph.timerange import (
|
5 | 6 | get_unique_values_grouped_by, get_format_for_units, check_dates_consecutive,
|
6 | 7 | get_date_format, convert_date_to_time_range_adjusted,
|
7 | 8 | adjust_x_values_for_time_range, combine_values_for_timerange,
|
8 | 9 | get_missing_consecutive_dates, fill_gaps_in_timerange_data,
|
9 |
| - process_timerange_data |
| 10 | + process_timerange_data, add_time_unit |
10 | 11 | )
|
11 | 12 |
|
12 | 13 |
|
|
340 | 341 | {'stacked': None, 'operator': '+', 'x': '2024-06',
|
341 | 342 | 'type': 'Revenue', 'value': 300.0},
|
342 | 343 | ))
|
| 344 | + |
| 345 | + with description('add_time_unit function'): |
| 346 | + with context('when adding different time units'): |
| 347 | + with it('adds days correctly'): |
| 348 | + start_date = datetime(2021, 1, 1) |
| 349 | + result = add_time_unit(start_date, 10, 'days') |
| 350 | + expect(result).to(equal(datetime(2021, 1, 11))) |
| 351 | + |
| 352 | + with it('adds weeks correctly'): |
| 353 | + start_date = datetime(2021, 1, 1) |
| 354 | + result = add_time_unit(start_date, 2, 'weeks') |
| 355 | + expect(result).to(equal(datetime(2021, 1, 15))) |
| 356 | + |
| 357 | + with it('adds months correctly'): |
| 358 | + start_date = datetime(2021, 1, 1) |
| 359 | + result = add_time_unit(start_date, 1, 'months') |
| 360 | + expect(result).to(equal(datetime(2021, 2, 1))) |
| 361 | + |
| 362 | + with it('adds years correctly'): |
| 363 | + start_date = datetime(2021, 1, 1) |
| 364 | + result = add_time_unit(start_date, 1, 'years') |
| 365 | + expect(result).to(equal(datetime(2022, 1, 1))) |
| 366 | + |
| 367 | + with it('adds hours correctly'): |
| 368 | + start_date = datetime(2021, 1, 1, 12, 0) |
| 369 | + result = add_time_unit(start_date, 5, 'hours') |
| 370 | + expect(result).to(equal(datetime(2021, 1, 1, 17, 0))) |
| 371 | + |
| 372 | + with it('raises an error for unsupported units'): |
| 373 | + start_date = datetime(2021, 1, 1) |
| 374 | + expect(lambda: add_time_unit(start_date, 10, 'minutes')).to( |
| 375 | + raise_error(ValueError)) |
0 commit comments