def test_arg_with_keys_sets_each_arg_item(self): obj1 = cv2.imread(path.join(_this_path, 'data', 'object.png')) obj2 = cv2.imread(path.join(_this_path, 'data', 'different_object.png')) value_1 = 1 value_2 = 2 d_content = ImageDict() d_content[obj1] = value_1 d_content[obj2] = value_2 #create and try to update a blank ImageDict d = ImageDict() d.update(d_content) image_mask_values = ((kp.image, kp.mask, kp.value) for kp in d._keypackages) image_mask_values_spec = ((obj1, None, value_1), (obj2, None, value_2)) self.assertItemsEqual(image_mask_values, image_mask_values_spec)
def test_arg_without_keys_sets_sequence_of_key_value_pairs(self): obj1 = cv2.imread(path.join(_this_path, 'data', 'object.png')) obj2 = cv2.imread(path.join(_this_path, 'data', 'different_object.png')) value_1 = 1 value_2 = 2 key_value_pairs = ((obj1, value_1), (obj2, value_2)) #create and try to update a blank ImageDict d = ImageDict() d.update(key_value_pairs) items = [[kp.image, kp.mask, kp.value] for kp in d._keypackages] items_spec = ((obj1, None, value_1), (obj2, None, value_2)) #below works like assertSequenceEqual but gets around numpy's demand for unambiguous equality operator #wish I could use ItemsEqual but I believe it has a problem even though it is supposed to have a non-hashable code path for (image_actual, mask_actual, value_actual), (image_spec, mask_spec, value_spec) in zip(items, items_spec): self.assertTrue(np.all(image_actual == image_spec)) self.assertTrue(np.all(mask_actual == mask_spec)) self.assertEqual(value_actual, value_spec)
def test_kwarg_sets_as_with_an_arg_with_keys(self): obj1 = cv2.imread(path.join(_this_path, 'data', 'object.png')) obj2 = cv2.imread(path.join(_this_path, 'data', 'different_object.png')) value_1 = 1 value_2 = 2 d_content = ImageDict() d_content[obj1] = value_1 d_content[obj2] = value_2 #create and try to update a blank ImageDict d = ImageDict() d.update(**d_content) #todo: this doesn't work. maybe can work around hash requirement? items = ((kp.image, kp.mask, kp.value) for kp in d._keypackages) items_spec = ((obj1, None, value_1), (obj2, None, value_2)) #below works like assertSequenceEqual but gets around numpy's demand for unambiguous equality operator #wish I could use ItemsEqual but I believe it has a problem even though it is supposed to have a non-hashable code path for (image_actual, mask_actual, value_actual), (image_spec, mask_spec, value_spec) in zip(items, items_spec): self.assertTrue(np.all(image_actual == image_spec)) self.assertTrue(np.all(mask_actual == mask_spec)) self.assertEqual(value_actual, value_spec)