import unittest import parchments import datetime import decimal import json TEST_INDEX = ( ('goats', 'int', 0), ('price', 'dollar', 2), ('value', 'percentage', 4), ('names', 'string', 0), ('animal', 'bool', 0), ) test_grid = parchments.Grid(TEST_INDEX) class TestGrid(unittest.TestCase): def test_grid_add_period(self, period=datetime.datetime.now(), index=[1, 22.2, 0.70, 'bob', True]): try: test_grid.add_period(datetime.datetime.now(), [1, 22.2, 0.70, 'bob', True]) self.assertTrue(True) except: self.assertTrue(False) def test_add_period_with_datetime_input(self): self.test_grid_add_period(period=datetime.datetime.now()) def test_add_period_with_date_input(self): self.test_grid_add_period(period=datetime.date.today())
def test_next_period_year_roll_over_day_iteration(self): period_test_grid = parchments.Grid(TEST_INDEX, period_iteration='day') period_test_grid.add_period(datetime.datetime(2020, 12, 31), PERIOD_DATA) self.assertTrue(period_test_grid.period_index[0].next_period.key == '20210101')
def test_next_period_day_iteration(self): period_test_grid = parchments.Grid(TEST_INDEX, period_iteration='day') period_test_grid.add_period(datetime.datetime(2020, 4, 10), PERIOD_DATA) self.assertTrue(period_test_grid.period_index[0].next_period.key == '20200411')
def test_previous_period_month_roll_over_day_iteration(self): period_test_grid = parchments.Grid(TEST_INDEX, period_iteration='day') period_test_grid.add_period(datetime.datetime(2020, 4, 1), PERIOD_DATA) self.assertTrue(period_test_grid.period_index[0].previous_period.key == '20200331')
def test_previous_period_year_iteration(self): period_test_grid = parchments.Grid(TEST_INDEX, period_iteration='year') period_test_grid.add_period(datetime.datetime(2020, 4, 1), PERIOD_DATA) self.assertTrue(period_test_grid.period_index[0].previous_period.key == '20190101')
def speed_test(): my_grid = parchments.Grid(row_index, period_iteration='month') my_grid.add_period(datetime(2021, 4, 1), other_period_data) my_grid.add_period(datetime(2021, 5, 1), period_data) my_grid.project_future(datetime(2021, 7, 1), 'median')