def test_rank_sections_by_supersedes_no_matching_sections(): fallback = _create_creator("desired", "desired", []) assert utils.rank_sections_by_supersedes( [ _create_creator("foo", "foo", []), ], {ParsedSectionName("desired")}, ) == [] assert utils.rank_sections_by_supersedes( [ fallback, _create_creator("foo", "foo", []), ], {ParsedSectionName("desired")}, ) == [fallback[1]] assert utils.rank_sections_by_supersedes( [ fallback, _create_creator("foo", "foo", []), _create_creator("desired", "bar", []), # will create "bar", not "desired"! ], {ParsedSectionName("desired")}, ) == [fallback[1]]
def get_ranked_sections( available_raw_sections: Iterable[SectionName], filter_parsed_section: Optional[Set[ParsedSectionName]], ) -> List[SectionPlugin]: """ Get the raw sections [that will be parsed into the required section] ordered by supersedings """ return rank_sections_by_supersedes( ((name, get_section_plugin(name)) for name in available_raw_sections), filter_parsed_section, )
def test_rank_section_by_supersedes_with_supersedings(): available = [ _create_creator("ding", "dong", ["moo"]), # filter this out! _create_creator("foo1", "desired", ["ding", "moo", "foo3"]), # one of three is relevant _create_creator("foo2", "desired", ["zfoo4", "afoo5"]), # only two, but all relevant _create_creator("foo3", "desired", ["ding"]), _create_creator("zfoo4", "desired", []), _create_creator("afoo5", "desired", []), ] assert utils.rank_sections_by_supersedes( available, {ParsedSectionName("desired")}, ) == [available[i][1] for i in (2, 1, 5, 3, 4)]