def valid(self, data): missing = [] # Curry check_value with container for missing properties curried_check = functools.partial(self.check_value, missing=missing) # Walk over the acquired data to check a value is set for each property utils.walk_and_apply(data, curried_check) # Set the list of missing properties as instance variable self.missing = missing return missing
def valid(self, data): missing = [] # Curry check_value with container for missing properties curried_check = functools.partial(self.check_value, missing=missing) # Walk over the acquired data to check a value is set for each property utils.walk_and_apply(data, curried_check) if missing: raise MinimumDataFailure( 'Properties: {}; have no value'.format(', '.join(missing)) ) return missing
def map_to_config(self, source): """ Return dict of values extracted from given source based on self.config """ # Curry the lookup_value function with the source tree func = functools.partial(self.lookup_value, source) # Apply the curried function to the config dict return utils.walk_and_apply(self.config, func)
def compile_config(self, config): """ Walk over configuration and replace values with functions """ return utils.walk_and_apply(config, self.compile_lookups)
def test_walk_dict(self): out = utils.walk_and_apply(self.given, self.function) self.assertEqual(self.expected, out)