def test_iob_update(self): """ Test updating an existing dictionary with a new bolus entry""" curr_dict = {1425340800: 10.0, 1425341100: 15, 1425341400: 5} #IOB values 5 minutes apart for 10 minutes associated_bolus = [{"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:10:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:10:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}] res_dict = insulin_on_board.update_iob_dict(curr_dict, associated_bolus, action_time=10/60) initial_iob = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] fifteen_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:15:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10, (same as original dict) self.assertEqual(initial_iob, 10.0) #At time = 5 min, IOB should be 15, (same as original dict) self.assertEqual(five_min, 15.0) #At time = 10 min, the original dict value of 5 should add to the new bolus of 10 --> 15 total self.assertEqual(ten_min, 15.0) #At time = 15 min, the original dict should update to account for the 5 remaining units of the new entry self.assertEqual(ten_min, 15.0)
def test_simple_iob_dict_creation(self): """ Check a single insulin dose distribution over action_time = one hour""" expected_input = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 6, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=1) half_way = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:30:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #30 mins later three_fourth = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:45:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #45 mins later #test that halfway through the action time, IOB is half the original bolus self.assertEqual(tools.round_to(half_way), float(expected_input[0]['normal'] / 2)) #test that 75% through the action time, IOB is one fourth the original bolus self.assertEqual(tools.round_to(three_fourth), float(expected_input[0]['normal'] / 4))
def test_complex_iob_dict_creation(self): """ Check two insulin doses five minutes apart, action_time = 10 minutes""" expected_input = [{"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}, {"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:05:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:05:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=10/60) initial_iob = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10 self.assertEqual(initial_iob, 10.0) #At time = 5 min, initial IOB = 5 + second IOB = 10 --> 15 total self.assertEqual(five_min, 15.0) #At time = 10 min, initial IOB = 0, and second IOB should have 5 units left self.assertEqual(ten_min, 5.0)
def test_wizard_format_no_iob(self): """ Test that wizard events meet format requirements""" start_time = datetime(2015, 1, 1, 0, 0, 0) # populate gluc list with some fake glucose values gluc = [100, 217, 49] # populate carb list with some fake carb values (corresponding to a # meal) carbs = [90, 31, 61] # populate timesteps with some fake time values later than start_time timesteps = [ tools.convert_ISO_to_epoch('2015-01-01 15:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-02 19:30:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-03 09:12:00', '%Y-%m-%d %H:%M:%S') ] # test that wizard events formats correctly even when no bolus and # no_wizard data is given bolus_data = [] no_wizard = [] zonename = 'US/Pacific' pump_name = 'Medtronic' res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps, bolus_data, no_wizard, zonename, pump_name) # make sure that for every wizrd event, a bolus event is also created # (ie there shold be 6 total events) self.assertEqual(len(res_dict), 6) # check that the reccomendation of the wizard calculates correctly carb_ratio1 = res_dict[1]["insulinCarbRatio"] carb_input1 = res_dict[1]["carbInput"] # should match carbs[0] = 90 units1 = res_dict[1]["units"] net_reccomendation1 = res_dict[1]["recommended"]["net"] expected_reccomendation1 = tools.round_to(carb_input1 / carb_ratio1) self.assertEqual(net_reccomendation1, expected_reccomendation1) self.assertEqual(units1, "mmol/L") carb_ratio2 = res_dict[3]["insulinCarbRatio"] carb_input2 = res_dict[3]["carbInput"] # should match carbs[0] = 90 units2 = res_dict[3]["units"] net_reccomendation2 = res_dict[3]["recommended"]["net"] expected_reccomendation2 = tools.round_to(carb_input2 / carb_ratio2) self.assertEqual(net_reccomendation2, expected_reccomendation2) self.assertEqual(units2, "mmol/L") carb_ratio3 = res_dict[5]["insulinCarbRatio"] carb_input3 = res_dict[5]["carbInput"] # should match carbs[0] = 90 units3 = res_dict[5]["units"] net_reccomendation3 = res_dict[5]["recommended"]["net"] expected_reccomendation3 = tools.round_to(carb_input3 / carb_ratio3) self.assertEqual(net_reccomendation3, expected_reccomendation3) self.assertEqual(units3, "mmol/L")
def test_insulin_on_board(self): """ Check that assigning iob values to specific times works as intended """ start_time = tools.convert_ISO_to_epoch('2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') five_min = tools.convert_ISO_to_epoch('2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') ten_min = tools.convert_ISO_to_epoch('2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') fifteen_min = tools.convert_ISO_to_epoch('2015-03-03T00:15:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') curr_dict = {start_time: 10.0, five_min: 15.0, ten_min: 15.0, fifteen_min: 5.0} #test an iob value for a time that exists in the dict exact_time = start_time expected_exact_output = 10.0 self.assertEqual(expected_exact_output, insulin_on_board.insulin_on_board(curr_dict, exact_time)) #test iob values within 5 minutes of a time value that exists in the dict approx_time_round_down = tools.convert_ISO_to_epoch('2015-03-03T00:19:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #4 mins away from fifteen_min approx_time_round_up = tools.convert_ISO_to_epoch('2015-03-03T00:14:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #1 min away from fifteen_min expected_approx_output = 5.0 self.assertEqual(expected_approx_output, insulin_on_board.insulin_on_board(curr_dict, approx_time_round_down)) self.assertEqual(expected_approx_output, insulin_on_board.insulin_on_board(curr_dict, approx_time_round_up)) #test an iob value that is out of the 5 minute approximation range far_time = tools.convert_ISO_to_epoch('2015-03-03T00:22:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') expected_far_output = 0 self.assertEqual(expected_far_output, insulin_on_board.insulin_on_board(curr_dict, far_time)) #test the boundy case of exactly 5 minutes away boundry_time = tools.convert_ISO_to_epoch('2015-03-03T00:20:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #exactly 5 minutes away from fifteen_min expected_boundry_output = 5.0 self.assertEqual(expected_boundry_output, insulin_on_board.insulin_on_board(curr_dict, boundry_time))
def test_night_bolus_removal(self): """ Test that night boluses are removed properly""" #bolus removal depandent on time of day and glucose level #the function takes a list of carb-time-glucose lists and a timezone name night_time = tools.convert_ISO_to_epoch('2015-01-01 00:30:00', '%Y-%m-%d %H:%M:%S') zonemane = "US/Pacific" offset = -480 local_epoch_night_time = night_time - offset * 60 #removing night events must happen in the user's local time test_in_range_night_event = [[90, local_epoch_night_time, 249]] #remove test_high_night_event = [[90, local_epoch_night_time, 250]] #keep expected_removed_event = [] expected_kept_event = [[90, local_epoch_night_time, 250]] #call to function returns a numpy list which is converted to a regular list for these tests result_removed = bolus.remove_night_boluses(test_in_range_night_event, zonemane) self.assertEqual(expected_removed_event, np.ndarray.tolist(result_removed)) result_kept = bolus.remove_night_boluses(test_high_night_event, zonemane) self.assertEqual(expected_kept_event, np.ndarray.tolist(result_kept))
def test_insulin_on_board(self): """ Check that assigning iob values to specific times works as intended """ start_time = tools.convert_ISO_to_epoch('2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') five_min = tools.convert_ISO_to_epoch('2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') ten_min = tools.convert_ISO_to_epoch('2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') fifteen_min = tools.convert_ISO_to_epoch('2015-03-03T00:15:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') curr_dict = { start_time: 10.0, five_min: 15.0, ten_min: 15.0, fifteen_min: 5.0 } #test an iob value for a time that exists in the dict exact_time = start_time expected_exact_output = 10.0 self.assertEqual( expected_exact_output, insulin_on_board.insulin_on_board(curr_dict, exact_time)) #test iob values within 5 minutes of a time value that exists in the dict approx_time_round_down = tools.convert_ISO_to_epoch( '2015-03-03T00:19:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #4 mins away from fifteen_min approx_time_round_up = tools.convert_ISO_to_epoch( '2015-03-03T00:14:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #1 min away from fifteen_min expected_approx_output = 5.0 self.assertEqual( expected_approx_output, insulin_on_board.insulin_on_board(curr_dict, approx_time_round_down)) self.assertEqual( expected_approx_output, insulin_on_board.insulin_on_board(curr_dict, approx_time_round_up)) #test an iob value that is out of the 5 minute approximation range far_time = tools.convert_ISO_to_epoch('2015-03-03T00:22:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') expected_far_output = 0 self.assertEqual( expected_far_output, insulin_on_board.insulin_on_board(curr_dict, far_time)) #test the boundy case of exactly 5 minutes away boundry_time = tools.convert_ISO_to_epoch( '2015-03-03T00:20:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z') #exactly 5 minutes away from fifteen_min expected_boundry_output = 5.0 self.assertEqual( expected_boundry_output, insulin_on_board.insulin_on_board(curr_dict, boundry_time))
def test_simple_iob_dict_creation(self): """ Check a single insulin dose distribution over action_time = one hour""" expected_input = [{"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 6, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=1) half_way = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:30:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #30 mins later three_fourth = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:45:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #45 mins later #test that halfway through the action time, IOB is half the original bolus self.assertEqual(tools.round_to(half_way), float(expected_input[0]['normal'] / 2)) #test that 75% through the action time, IOB is one fourth the original bolus self.assertEqual(tools.round_to(three_fourth), float(expected_input[0]['normal'] / 4))
def test_insulin_sensitivity(self): """ Test that insulin sensitivity is assigned correctly according to time of day""" start_time = datetime(2015, 1, 1, 0, 0, 0) # gluc and carb values do not affect sensistivity gluc = [100, 100, 100, 100] carbs = [100, 100, 100, 100] timesteps = [ tools.convert_ISO_to_epoch('2015-01-01 04:30:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 10:45:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 13:12:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 23:56:00', '%Y-%m-%d %H:%M:%S') ] bolus_data = [] no_wizard = [] # zonemae here is in UTC so that timestems reflect time and deviceTime # to make time checking easier zonename = 'UTC' pump_name = 'Medtronic' res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps, bolus_data, no_wizard, zonename, pump_name) # expected sensitivity: expected_early_morning = tools.convert_to_mmol(30) expected_morning = tools.convert_to_mmol(40) expected_afternoon = tools.convert_to_mmol(50) expected_night = tools.convert_to_mmol(35) # resulting sensitivity: early_morning = res_dict[1]["insulinSensitivity"] morning = res_dict[3]["insulinSensitivity"] afternoon = res_dict[5]["insulinSensitivity"] night = res_dict[7]["insulinSensitivity"] self.assertEqual(expected_early_morning, early_morning) self.assertEqual(expected_morning, morning) self.assertEqual(expected_afternoon, afternoon) self.assertEqual(expected_night, night)
def test_iob_update(self): """ Test updating an existing dictionary with a new bolus entry""" curr_dict = { 1425340800: 10.0, 1425341100: 15, 1425341400: 5 } #IOB values 5 minutes apart for 10 minutes associated_bolus = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:10:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:10:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] res_dict = insulin_on_board.update_iob_dict(curr_dict, associated_bolus, action_time=10 / 60) initial_iob = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] fifteen_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:15:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10, (same as original dict) self.assertEqual(initial_iob, 10.0) #At time = 5 min, IOB should be 15, (same as original dict) self.assertEqual(five_min, 15.0) #At time = 10 min, the original dict value of 5 should add to the new bolus of 10 --> 15 total self.assertEqual(ten_min, 15.0) #At time = 15 min, the original dict should update to account for the 5 remaining units of the new entry self.assertEqual(ten_min, 15.0)
def test_complex_iob_dict_creation(self): """ Check two insulin doses five minutes apart, action_time = 10 minutes""" expected_input = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }, { "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:05:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:05:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=10 / 60) initial_iob = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10 self.assertEqual(initial_iob, 10.0) #At time = 5 min, initial IOB = 5 + second IOB = 10 --> 15 total self.assertEqual(five_min, 15.0) #At time = 10 min, initial IOB = 0, and second IOB should have 5 units left self.assertEqual(ten_min, 5.0)
def test_night_bolus_removal(self): """ Test that night boluses are removed properly""" #bolus removal depandent on time of day and glucose level #the function takes a list of carb-time-glucose lists and a timezone name night_time = tools.convert_ISO_to_epoch('2015-01-01 00:30:00', '%Y-%m-%d %H:%M:%S') zonemane = "US/Pacific" offset = -480 local_epoch_night_time = night_time - offset*60 #removing night events must happen in the user's local time test_in_range_night_event = [[90, local_epoch_night_time, 249]] #remove test_high_night_event = [[90, local_epoch_night_time, 250]] #keep expected_removed_event = [] expected_kept_event = [[90, local_epoch_night_time, 250]] #call to function returns a numpy list which is converted to a regular list for these tests result_removed = bolus.remove_night_boluses(test_in_range_night_event, zonemane) self.assertEqual(expected_removed_event, np.ndarray.tolist(result_removed)) result_kept = bolus.remove_night_boluses(test_high_night_event, zonemane) self.assertEqual(expected_kept_event, np.ndarray.tolist(result_kept))
def test_wizard_format_with_iob(self): """ Test insulin on board calculations are taken into account when giving a wizard reccomendation""" start_time = datetime(2015, 1, 1, 0, 0, 0) gluc = [100] carbs = [90] timesteps = [ tools.convert_ISO_to_epoch('2015-01-01 00:00:00', '%Y-%m-%d %H:%M:%S') ] bolus_data = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-01-01T07:59:29", "id": "3db26422-e731-429e-ab14-7dfc78a399f3", "normal": 10, # should correspond to iob value! "subType": "normal", "time": "2015-01-01T00:00:00.000Z", # same as wizard "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] no_wizard = [] zonename = 'US/Pacific' pump_name = 'Medtronic' res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps, bolus_data, no_wizard, zonename, pump_name) # check that insulin on board value is correct expected_iob = tools.convert_to_mmol(10) iob = res_dict[1]["insulinOnBoard"] self.assertEqual(expected_iob, iob) # check that net reccomendationt takes into account insulin on board carb_ratio = res_dict[1]["insulinCarbRatio"] carb_input = res_dict[1]["carbInput"] # should match carbs[0] = 90 net_reccomendation = res_dict[1]["recommended"]["net"] expected_reccomendation = (tools.round_to(carb_input / carb_ratio) - tools.round_to(iob)) self.assertEqual(net_reccomendation, expected_reccomendation)
def test_no_wizard(self): """ Test that wizard and associated bolus events are removed during no_wizard periods""" start_time = datetime(2015, 1, 1, 0, 0, 0) gluc = [87, 201, 164, 180] carbs = [96, 82, 17, 53] timesteps = [ tools.convert_ISO_to_epoch('2015-01-01 04:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 05:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 06:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 07:00:00', '%Y-%m-%d %H:%M:%S') ] bolus_data = [] # create two time ranges during which there should not be bolus events no_wizard_start1 = tools.convert_ISO_to_epoch('2015-01-01 04:55:00', '%Y-%m-%d %H:%M:%S') no_wizard1_end1 = tools.convert_ISO_to_epoch('2015-01-01 05:05:00', '%Y-%m-%d %H:%M:%S') no_wizard_start2 = tools.convert_ISO_to_epoch('2015-01-01 06:55:00', '%Y-%m-%d %H:%M:%S') no_wizard1_end2 = tools.convert_ISO_to_epoch('2015-01-01 07:05:00', '%Y-%m-%d %H:%M:%S') no_wizard = [[no_wizard_start1, no_wizard1_end1], [no_wizard_start2, no_wizard1_end2]] zonename = 'US/Pacific' pump_name = 'Medtronic' res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps, bolus_data, no_wizard, zonename, pump_name) # after no_wizard events are removed, 2 wizard events + 2 bolus events # should remain self.assertEqual(len(res_dict), 4)
def test_common_fields(self): """ Test that common fields populate properly""" name = "bolus" datatype = {} timestamp = tools.convert_ISO_to_epoch('2015-03-03 00:00:00', '%Y-%m-%d %H:%M:%S') zonename = "US/Pacific" expected = { 'time': '2015-03-03T00:00:00.000Z', # UTC time 'deviceTime': '2015-03-02T16:00:00', # local time 'timezoneOffset': -480, 'deviceId': 'DemoData-123456789', 'uploadId': 'upid_abcdefghijklmnop', 'conversionOffset': 0, } result_dict = common_fields.add_common_fields(name, datatype, timestamp, zonename) for key in expected.keys(): self.assertEqual(result_dict[key], expected[key])
def test_basal_schedule(self): """ Test that basal rates are assinged according to the basal schedule from settings""" start_time = datetime(2015, 1, 1, 0, 0, 0) num_days = 1 zonename = 'US/Pacific' pump_name = 'Medtronic' res_dict, suspend_pump = basal.scheduled_basal(start_time, num_days, zonename, pump_name) #expected segments and rate (from settings) segment_one = range(tools.convert_ISO_to_epoch('2015-01-01 00:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 01:00:00', '%Y-%m-%d %H:%M:%S')) rate_one = 0.9 segment_two = range(tools.convert_ISO_to_epoch('2015-01-01 01:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 03:00:00', '%Y-%m-%d %H:%M:%S')) rate_two = 0.6 segment_three = range(tools.convert_ISO_to_epoch('2015-01-01 03:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 04:00:00', '%Y-%m-%d %H:%M:%S')) rate_three = 0.65 segment_four = range(tools.convert_ISO_to_epoch('2015-01-01 04:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 05:00:00', '%Y-%m-%d %H:%M:%S')) rate_four = 0.8 segment_five = range(tools.convert_ISO_to_epoch('2015-01-01 05:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 08:00:00', '%Y-%m-%d %H:%M:%S')) rate_five = 0.85 segment_six = range(tools.convert_ISO_to_epoch('2015-01-01 08:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 09:00:00', '%Y-%m-%d %H:%M:%S')) rate_six = 0.8 segment_seven = range(tools.convert_ISO_to_epoch('2015-01-01 09:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 15:00:00', '%Y-%m-%d %H:%M:%S')) rate_seven = 0.75 segment_eight = range(tools.convert_ISO_to_epoch('2015-01-01 15:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-01 17:00:00', '%Y-%m-%d %H:%M:%S')) rate_eight = 0.8 segment_nine = range(tools.convert_ISO_to_epoch('2015-01-01 17:00:00', '%Y-%m-%d %H:%M:%S'), tools.convert_ISO_to_epoch('2015-01-02 00:00:00', '%Y-%m-%d %H:%M:%S')) rate_nine = 0.85 #check that expected rates match results for entry in res_dict: if entry["type"] == "basal": if entry['deliveryType'] == 'scheduled': entry_time = tools.convert_ISO_to_epoch(entry["deviceTime"], '%Y-%m-%dT%H:%M:%S') if entry_time in segment_one: self.assertEqual(entry['rate'], rate_one) elif entry_time in segment_two: self.assertEqual(entry['rate'], rate_two) elif entry_time in segment_three: self.assertEqual(entry['rate'], rate_three) elif entry_time in segment_four: self.assertEqual(entry['rate'], rate_four) elif entry_time in segment_five: self.assertEqual(entry['rate'], rate_five) elif entry_time in segment_six: self.assertEqual(entry['rate'], rate_six) elif entry_time in segment_seven: self.assertEqual(entry['rate'], rate_seven) elif entry_time in segment_eight: self.assertEqual(entry['rate'], rate_eight) else: self.assertEqual(entry['rate'], rate_nine)