def __call__(self, page, text, lang, *args, **kwargs): page_langs = page_languages(text, list) # Whether the language is already present if lang in page_langs: return text text = self.category_sorting(page, text, page_langs) follow = '' for x in page_langs: if self.data[x]['pos'] > self.data[lang]['pos']: pos = self.data[x]['pos'] follow = x break if follow: m = re.search(r'== {{langue\|%s' % (follow), text).start() else: m = re.search('{{clé de tri\|([^}]+)}}', text) if m: m = m.start() t = self.func(page, text, lang, *args, **kwargs) # Reformation of the text if not text: return t if m: return text[:m] + t + '\n' + text[m:] m = len(text) return text[:m] + '\n\n' + t + text[m:]
def test_success(self): assert page_languages(self.text, set) == set({'da', 'no', 'sv'}) assert page_languages(self.text, list) == ['da', 'no', 'sv']
def test_correct_return_type(self): assert isinstance(page_languages(self.text, set), set) assert isinstance(page_languages(self.text, list), list)
def test_no_type(self): assert page_languages(self.text, str) == None assert page_languages(self.text, 'toto') == None assert page_languages(self.text, typ='toto') == None
def test_no_text(self): assert page_languages('', set) == set({}) assert page_languages('', list) == list() assert page_languages('', 'toto') == None
def langs(self, text): text_langs = page_languages(text, set) return self.supported.intersection(text_langs)