def test_modify_hyperparameters(self, lp_mock, io_mock): """If a primitive method modifies the hyperparameters, changes should not persist.""" def primitive(a_list_param): a_list_param.append('b') io_mock.return_value = primitive lp_mock.return_value = { 'name': 'a_primitive', 'primitive': 'a_primitive', 'produce': { 'args': [], 'output': [] } } mlblock = MLBlock('a_primitive') hyperparameters = { 'a_list_param': ['a'] } mlblock._hyperparameters = hyperparameters mlblock.produce() assert 'b' not in hyperparameters['a_list_param']
def test_get_hyperparameters(self): """get_hyperparameters has to return a deepcopy of the _hyperparameters attribute.""" mlblock = MLBlock('given_primitive_name') hyperparameters = {'a_list_param': ['a']} mlblock._hyperparameters = hyperparameters returned = mlblock.get_hyperparameters() assert returned == hyperparameters assert returned is not hyperparameters returned['a_list_param'].append('b') assert 'b' not in hyperparameters['a_list_param']
def test_get_hyperparameters(self, load_primitive_mock, import_object_mock): """get_hyperparameters has to return a copy of the _hyperparameters attribute.""" load_primitive_mock.return_value = { 'primitive': 'a_primitive_name', 'produce': { 'args': [], 'output': [] } } mlblock = MLBlock('given_primitive_name') hyperparameters = dict() mlblock._hyperparameters = hyperparameters returned = mlblock.get_hyperparameters() assert returned == hyperparameters assert returned is not hyperparameters