def retrieve_dependency_graph(specification, exact_match=False, factory=None): """ Gets the best matching generator from a dependency graph generator factory and retrieve the dependency from it. @param specification: A specification @param exact_match: the parameter is passed to the factory. @param factory: The dependency graph factory to be used. If None, the dependency graph factory is retrieved from the configuration. @type factory: DependencyGraphGeneratorFactory or NoneType """ if factory == None: factory = config_dependency_graph_factory assert isinstance(factory, DependencyGraphGeneratorFactory) assert isinstance(specification, DependencyGraphSpecification) generator = IterTools.first( factory.get_dependency_graph_generators(specification, max_count=1)) if generator: assert isinstance(generator, DependencyGraphGenerator) return generator.retrieve_graph() else: return None
def get_omitted_modules_by_type(physical_module_describer, module_list_supply, dependency_filter_config_class): assert isinstance_or_duck(physical_module_describer, PhysicalModuleDescriber) assert isinstance_or_duck(module_list_supply, ModuleListSupply) key_func = lambda (module, size): tuple( PhysicalModuleTypes.names( physical_module_describer.get_physical_module_types(module))) grouped_modules = IterTools.sort_and_group( key_func, ModuleListHelper.get_omitted_modules_with_size( module_list_supply, dependency_filter_config_class)) return ((x, tuple(y)) for (x, y) in grouped_modules)
def __local_output_aggregate_to_input_aggregate_iteritems(self): individuals = ifilter(self.is_file_in_input_aggregates, self.__individual_to_input_aggregate_map) selected = (( individual, self.__filtered_input_aggregate_for_individual(individual)) for individual in individuals if self.__filtered_input_aggregate_for_individual( individual) in self.__selected_input_aggregates) second_of = lambda element: compatnext(islice(element, 1, 2)) key_func = lambda ( individual, input_aggregate ): self.__local_output_aggregate_for_individual_func(individual) return ((output_aggregate, set(imap(second_of, elements))) for output_aggregate, elements in IterTools.sort_and_group( key_func, selected))
def test_quantify_4(self): self.assertEquals(14, IterTools.quantify(range(15)))
def test_quantify_3(self): self.assertEquals(1, IterTools.quantify(iter([1])))
def test_quantify_2(self): self.assertEquals(0, IterTools.quantify([0]))
def test_sort_and_group_dicts_null(self): self.assertEquals([], list(IterTools.sort_and_group_dicts('a', [])))
def get_rows(self): return IterTools.sort_and_group_dicts([GenerationLogColumns.DESCRIPTION, GenerationLogColumns.EXTRA], self.__entries)
def test_first(self): testee = (x for x in range(2)) self.assertEquals(0, IterTools.first(testee)) self.assertEquals(1, IterTools.first(testee)) self.assertRaises(StopIteration, IterTools.first, testee) self.assertEquals(0, IterTools.first(testee, 0))
def test_count_3(self): self.assertEquals(1, IterTools.count(iter([1])))
def test_sort_and_group_2(self): self.assertEquals([('A', ['Abcd', 'Aloha']), ('B', ['Bar'])], [(x, list(y)) for (x,y) in IterTools.sort_and_group(lambda string: string[0], ('Abcd', 'Aloha', 'Bar'))])
def has_errors(self): self.__logger.info("test of has error irregularities") self.__logger.info(list(self._irregularities)) return IterTools.count(1 for (level, _message) in self._irregularities if level == logging.ERROR)
def generation_log_group_models_factory(generation_log): key_column = GenerationLogColumns.SECTION groups = IterTools.sort_and_group_dicts(key_column, generation_log) return ((key, GenerationLogTableModel(group)) for (key, group) in groups)
def test_count_1(self): self.assertEquals(0, IterTools.count([]))
def test_sort_and_group_null(self): self.assertEquals([], list(IterTools.sort_and_group(lambda x: x, ())))
def test_count_2(self): self.assertEquals(1, IterTools.count([0]))
def test_sort_and_group_dicts_two_keys(self): self.assertEquals([((0, 0), [{'a': 0, 'b': 0, 'c': 0}]), ((1, 0), [{'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 2, 'c': 0}])], list((x, sorted(y)) for (x,y) in IterTools.sort_and_group_dicts(['a', 'c'], [{'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 2, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}])))
def test_count_4(self): self.assertEquals(15, IterTools.count(range(15)))
def test_sort_and_group_dicts_no_key(self): self.assertEquals([((), [{'a': 0, 'b': 0}, {'a': 1, 'b': 1}, {'a': 1, 'b': 2}])], list((x, sorted(y)) for (x,y) in IterTools.sort_and_group_dicts([], [{'a': 0, 'b': 0}, {'a': 1, 'b': 2}, {'a': 1, 'b': 1}])))
def test_empty(self): target_dict = frozendict() self.assertEquals(0, len(target_dict)) self.assertEquals(0, IterTools.quantify(target_dict.iteritems(), lambda x: 1))
def uppercount(in_str): return 0 - IterTools.quantify(imap(lambda ch: ch.isupper(), in_str))