def __iter__(self): for batch_of_ids in split_batches(self.ids, self.batch_size): self.title_articles_lookup.clear() for article in (self.session.query(Article).filter( Article.id.in_(batch_of_ids)).all()): self.title_articles_lookup[prepare_title( article.title)].append(article.id) for title in self.title_articles_lookup: yield title
def test_prepare_title_handles_empty_titles(self): assert prepare_title(None) == ""
def test_prepare_title_lowercases(self): assert prepare_title("UPPER") == "upper"
def test_prepare_title_replaces_invalid_characters_with_single_space(self): assert prepare_title("invalid%&*^˙∆¬stuff") == "invalid stuff" assert prepare_title("ba!!!!d3") == "ba d3"
def test_prepare_title_removes_extra_spaces(self): assert prepare_title("extra spaces here") == "extra spaces here" assert prepare_title("trailing space ") == "trailing space"