def test___init___users_values(self, mock_super): # setup tunable = MagicMock(spec_set=Tunable) instance = MagicMock() instance._metamodel_kwargs = {'a': 'test'} instance._acquisition_kwargs = {'a': 'acquisition_test'} instance.__init_metamodel__ = MagicMock() instance.__init_acquisition__ = MagicMock() # run BaseMetaModelTuner.__init__( instance, tunable, maximize=False, num_candidates=5, min_trials=20, ) # assert assert instance.num_candidates == 5 assert instance.min_trials == 20 instance.__init_metamodel__.assert_called_once_with(a='test') instance.__init_acquisition__.assert_called_once_with( a='acquisition_test')
def test_record(self, mock_super): # setup instance = MagicMock() instance.trials = np.array([2]) instance.scores = 1 instance.min_trials = 1 # run BaseMetaModelTuner.record(instance, 1, 1) # assert mock_super.return_value.record.assert_called_once_with(1, 1) instance._fit.assert_called_once_with(np.array([2]), 1)
def test___init___default_values(self, mock_super): # setup tunable = MagicMock(spec_set=Tunable) instance = MagicMock() instance.__init_metamodel__ = MagicMock() instance.__init_acquisition__ = MagicMock() # run BaseMetaModelTuner.__init__(instance, tunable) # assert assert instance.num_candidates == 1000 assert instance.min_trials == 5 instance.__init_metamodel__.assert_called_once_with() instance.__init_acquisition__.assert_called_once_with()
def test__proposemin_trials_gt__trials_set(self): # setup instance = MagicMock() instance.min_trials = 1 instance._trials_set.__len__.return_value = 0 instance._sample.return_value = 'sample' # run result = BaseMetaModelTuner._propose(instance, 1, True) # assert instance._sample.assert_called_once_with(1, True) assert result == 'sample'
def test__propose_min_trials_lt__trials_set_allow_duplicates(self): # setup instance = MagicMock() instance.tunable.cardinality = 3 instance._min_trials = 0 instance._num_candidates = 10 instance._trials_set.__len__.return_value = 1 instance._sample.return_value = np.array([1]) instance._predict.return_value = 'predicted' instance._acquire.return_value = 0 # run result = BaseMetaModelTuner._propose(instance, 1, True) # assert instance._sample.assert_called_once_with(10, True) instance._predict.assert_called_once_with(np.array([1])) assert result == 1