def test_wildcard_filter_all_but(self): filters = """ -* +blues """ tag_filter = TagGenreFilter(filters) self.assertTrue(tag_filter.skip('jazz')) self.assertTrue(tag_filter.skip('rock')) self.assertFalse(tag_filter.skip('blues'))
def test_whitespaces_filter(self): filters = """ - jazz b* - * ro ck - /^di sco$/ """ tag_filter = TagGenreFilter(filters) self.assertTrue(tag_filter.skip('jazz blues')) self.assertTrue(tag_filter.skip('blues ro ck')) self.assertTrue(tag_filter.skip('di sco')) self.assertFalse(tag_filter.skip('bluesro ck'))
def test_uppercased_filter(self): filters = """ -JAZZ* -ROCK -/^DISCO$/ """ tag_filter = TagGenreFilter(filters) self.assertTrue(tag_filter.skip('jazz blues')) self.assertTrue(tag_filter.skip('JAZZ BLUES')) self.assertTrue(tag_filter.skip('rock')) self.assertTrue(tag_filter.skip('ROCK')) self.assertTrue(tag_filter.skip('disco')) self.assertTrue(tag_filter.skip('DISCO'))
def update_test_genres_filter(self): test_text = self.ui.test_genres_filter.toPlainText() filters = self.ui.genres_filter.toPlainText() tagfilter = TagGenreFilter(filters) # FIXME: very simple error reporting, improve self.ui.label_test_genres_filter_error.setText("\n".join([ _("Error line %d: %s") % (lineno + 1, error) for lineno, error in tagfilter.errors.items() ])) def set_line_fmt(lineno, textformat): obj = self.ui.test_genres_filter if lineno < 0: # use current cursor position cursor = obj.textCursor() else: cursor = QTextCursor(obj.document().findBlockByNumber(lineno)) obj.blockSignals(True) cursor.setBlockFormat(textformat) obj.blockSignals(False) set_line_fmt(-1, self.fmt_clear) for lineno, line in enumerate(test_text.splitlines()): line = line.strip() fmt = self.fmt_clear if line: if tagfilter.skip(line): fmt = self.fmt_skip else: fmt = self.fmt_keep set_line_fmt(lineno, fmt)
def test_strict_filter_allowlist_reverseorder(self): filters = """ -jazz +jazz """ tag_filter = TagGenreFilter(filters) self.assertFalse(tag_filter.skip('jazz'))
def test_strict_filter_whitelist(self): filters = """ +jazz -jazz """ tag_filter = TagGenreFilter(filters) self.assertFalse(tag_filter.skip('jazz'))
def test_regex_filter(self): filters = """ -/^j.zz/ -/r[io]ck$/ -/disco+/ +/discoooo/ """ tag_filter = TagGenreFilter(filters) self.assertTrue(tag_filter.skip('jazz')) self.assertTrue(tag_filter.skip('j**z')) self.assertTrue(tag_filter.skip('jazz blues')) self.assertFalse(tag_filter.skip('blues jazz')) self.assertTrue(tag_filter.skip('rock')) self.assertTrue(tag_filter.skip('blues rock')) self.assertTrue(tag_filter.skip('blues rick')) self.assertFalse(tag_filter.skip('rock blues')) self.assertTrue(tag_filter.skip('disco')) self.assertTrue(tag_filter.skip('xdiscox')) self.assertTrue(tag_filter.skip('xdiscooox')) self.assertFalse(tag_filter.skip('xdiscoooox'))
def test_wildcard_filter(self): filters = """ -jazz* -*rock -*disco* -a*b """ tag_filter = TagGenreFilter(filters) self.assertTrue(tag_filter.skip('jazz')) self.assertTrue(tag_filter.skip('jazz blues')) self.assertFalse(tag_filter.skip('blues jazz')) self.assertTrue(tag_filter.skip('rock')) self.assertTrue(tag_filter.skip('blues rock')) self.assertFalse(tag_filter.skip('rock blues')) self.assertTrue(tag_filter.skip('disco')) self.assertTrue(tag_filter.skip('xdisco')) self.assertTrue(tag_filter.skip('discox')) self.assertTrue(tag_filter.skip('ab')) self.assertTrue(tag_filter.skip('axb')) self.assertTrue(tag_filter.skip('axxb')) self.assertFalse(tag_filter.skip('xab'))
def test_strict_filter(self): tag_filter = TagGenreFilter("-jazz") self.assertTrue(tag_filter.skip('jazz'))
def test_no_filter(self): tag_filter = TagGenreFilter("# comment") self.assertFalse(tag_filter.skip('jazz'))