def test_file_output(self):
        shutil.rmtree(self.working_directory, ignore_errors=True)
        os.mkdir(self.working_directory)

        queue_mock = unittest.mock.Mock()

        context = BackendContext(
            temporary_directory=os.path.join(self.working_directory, 'tmp'),
            output_directory=os.path.join(self.working_directory, 'out'),
            delete_tmp_folder_after_terminate=True,
            delete_output_folder_after_terminate=True,
        )
        with unittest.mock.patch.object(
                Backend, 'load_datamanager') as load_datamanager_mock:
            load_datamanager_mock.return_value = get_multiclass_classification_datamanager(
            )

            backend = Backend(context)

            ae = AbstractEvaluator(
                backend=backend,
                output_y_hat_optimization=False,
                queue=queue_mock,
                metric=accuracy,
                port=self.port,
            )
            ae.model = sklearn.dummy.DummyClassifier()

            rs = np.random.RandomState()
            ae.Y_optimization = rs.rand(33, 3)
            predictions_ensemble = rs.rand(33, 3)
            predictions_test = rs.rand(25, 3)
            predictions_valid = rs.rand(25, 3)

            ae.file_output(
                Y_optimization_pred=predictions_ensemble,
                Y_valid_pred=predictions_valid,
                Y_test_pred=predictions_test,
            )

            self.assertTrue(
                os.path.exists(
                    os.path.join(self.working_directory, 'tmp',
                                 '.auto-sklearn', 'runs', '1_0_None')))

            shutil.rmtree(self.working_directory, ignore_errors=True)
Exemplo n.º 2
0
    def test_add_additional_components(self):
        shutil.rmtree(self.working_directory, ignore_errors=True)
        os.mkdir(self.working_directory)

        queue_mock = unittest.mock.Mock()

        context = BackendContext(
            temporary_directory=os.path.join(self.working_directory, 'tmp'),
            delete_tmp_folder_after_terminate=True,
        )
        with unittest.mock.patch.object(
                Backend, 'load_datamanager') as load_datamanager_mock:
            load_datamanager_mock.return_value = get_multiclass_classification_datamanager(
            )
            backend = Backend(context)

            with unittest.mock.patch.object(_addons['classification'],
                                            'add_component') as _:

                # If the components in the argument `additional_components` are an empty dict
                # there is no call to `add_component`, if there's something in it, `add_component
                # is called (2nd case)
                for fixture, case in ((0, dict()), (1, dict(abc='def'))):

                    thirdparty_components_patch = unittest.mock.Mock()
                    thirdparty_components_patch.components = case
                    additional_components = dict(
                        classification=thirdparty_components_patch)
                    AbstractEvaluator(
                        backend=backend,
                        output_y_hat_optimization=False,
                        queue=queue_mock,
                        metric=accuracy,
                        port=self.port,
                        additional_components=additional_components,
                    )
                    self.assertEqual(
                        _addons['classification'].add_component.call_count,
                        fixture)