def test_get_predictions_uses_model_appropriately(self, mock_path, _Image, _np, _load, _image): mock_path.exists.return_value = True main.get_predictions(self.model_path, self.img_path, self.target_size) _load.assert_called_once_with(self.model_path) _load.return_value.predict.assert_called_once()
def test_get_predictions_input_is_preprocessed(self, mock_path, _Image, _np, _load, _image, _preprocess): mock_path.exists.return_value = True main.get_predictions(self.model_path, self.img_path, self.target_size) _preprocess.assert_called_once_with(_np.expand_dims.return_value) _load.return_value.predict.assert_called_once_with( _preprocess.return_value)
def test_get_predictions_loads_image_appropriately(self, mock_path, _Image, _np, _load, _image): mock_path.exists.return_value = True _Image.open.return_value.size = (6, 6) main.get_predictions(self.model_path, self.img_path, self.target_size) _Image.open.assert_called_once_with(self.img_path) _Image.open.return_value.resize.assert_called_once_with( self.target_size) _image.img_to_array.assert_called_once_with( _Image.open.return_value.resize.return_value)
def test_get_predictions_raises_error_if_model_file_doesnot_exist_only( self, mock_path, _Image, _np, _load, _image): # if model path exist, valueerror should not be raised mock_path.exists.return_value = True try: main.get_predictions(self.model_path, self.img_path, self.target_size) except ValueError: self.fail( "No value error should have been raised while model path existing" ) # if model path does not exist, valueerror should be raised mock_path.exists.return_value = False with self.assertRaises(ValueError) as ve: main.get_predictions('dummy_path', 'dummy_path', self.target_size)
def test_get_predictions_returns_right_preds_and_its_sorting_index( self, mock_path, _Image, _np, _load, _image, _preprocess): mock_path.exists.return_value = True expected_preds = np.array([2, 3, 1]) _load.return_value.predict.return_value.flatten.return_value = expected_preds preds, sorrting_index = main.get_predictions(self.model_path, self.img_path, self.target_size) expected_sorting_index = np.array([1, 0, 2]) np.testing.assert_array_equal(preds, expected_preds) np.testing.assert_array_equal(sorrting_index, expected_sorting_index)