def test_file_filters(patterns, filename, expected_match): from meld.filters import FilterEntry filters = [ FilterEntry.new_from_gsetting(("name", True, p), FilterEntry.SHELL) for p in patterns ] # All of the dirdiff logic is "does this match any filter", so # that's what we test here, even if it looks a bit weird. match = any(f.filter.match(filename) for f in filters) assert match == expected_match
def test_filter_text(text, ignored_ranges, expected_text): from meld.filediff import FileDiff from meld.filters import FilterEntry filter_patterns = [ '#.*', '/\*.*\*/', 'a(.*)b', 'x(.*)y(.*)z', '\$\w+:([^\n$]+)\$' ] filters = [ FilterEntry.new_from_gsetting(("name", True, f), FilterEntry.REGEX) for f in filter_patterns ] filediff = mock.MagicMock() filediff.text_filters = filters filter_text = FileDiff._filter_text buf = Gtk.TextBuffer() buf.create_tag("inline") buf.create_tag("dimmed") buf.set_text(text) start, end = buf.get_bounds() text = filter_text( filediff, buf.get_text(start, end, False), buf, start, end) # Find ignored ranges tag = buf.get_tag_table().lookup("dimmed") toggles = [] it = start.copy() if it.toggles_tag(tag): toggles.append(it.get_offset()) while it.forward_to_tag_toggle(tag): toggles.append(it.get_offset()) toggles = list(zip(toggles[::2], toggles[1::2])) print("Text:", text) print("Toggles:", toggles) assert toggles == ignored_ranges assert text == expected_text
def __init__(self, **kwargs): super().__init__(**kwargs) self.model = self.treeview.get_model() self.pattern_column.set_cell_data_func(self.validity_renderer, self.valid_icon_celldata) for filter_params in settings.get_value(self.settings_key): filt = FilterEntry.new_from_gsetting(filter_params, self.filter_type) if filt is None: continue valid = filt.filter is not None self.model.append( [filt.label, filt.active, filt.filter_string, valid]) for signal in ('row-changed', 'row-deleted', 'row-inserted', 'rows-reordered'): self.model.connect(signal, self._update_filter_string) self.setup_sensitivity_handling()
def __init__(self, **kwargs): super().__init__(self, **kwargs) FilterList.init_template(self) self.model = self.treeview.get_model() self.pattern_column.set_cell_data_func( self.validity_renderer, self.valid_icon_celldata) for filter_params in settings.get_value(self.settings_key): filt = FilterEntry.new_from_gsetting( filter_params, self.filter_type) if filt is None: continue valid = filt.filter is not None self.model.append( [filt.label, filt.active, filt.filter_string, valid]) for signal in ('row-changed', 'row-deleted', 'row-inserted', 'rows-reordered'): self.model.connect(signal, self._update_filter_string) self.setup_sensitivity_handling()
def __init__(self, key, filter_type): default_entry = [_("label"), False, _("pattern"), True] super().__init__("EditableList.ui", "list_vbox", ["EditableListStore"], "EditableList", default_entry) self.key = key self.filter_type = filter_type self.pattern_column.set_cell_data_func(self.validity_renderer, self.valid_icon_celldata) for filter_params in settings.get_value(self.key): filt = FilterEntry.new_from_gsetting(filter_params, filter_type) if filt is None: continue valid = filt.filter is not None self.model.append( [filt.label, filt.active, filt.filter_string, valid]) for signal in ('row-changed', 'row-deleted', 'row-inserted', 'rows-reordered'): self.model.connect(signal, self._update_filter_string) self._update_sensitivity()
def __init__(self, key, filter_type): default_entry = [_("label"), False, _("pattern"), True] ListWidget.__init__(self, "EditableList.ui", "list_vbox", ["EditableListStore"], "EditableList", default_entry) self.key = key self.filter_type = filter_type self.pattern_column.set_cell_data_func(self.validity_renderer, self.valid_icon_celldata) for filter_params in settings.get_value(self.key): filt = FilterEntry.new_from_gsetting(filter_params, filter_type) if filt is None: continue valid = filt.filter is not None self.model.append([filt.label, filt.active, filt.filter_string, valid]) for signal in ('row-changed', 'row-deleted', 'row-inserted', 'rows-reordered'): self.model.connect(signal, self._update_filter_string) self._update_sensitivity()
def on_pattern_edited(self, ren, path, text): filt = FilterEntry.compile_filter(text, self.filter_type) valid = filt is not None self.model[path][2] = text self.model[path][3] = valid
def on_pattern_edited(self, ren, path, text): valid = FilterEntry.check_filter(text, self.filter_type) self.model[path][2] = text self.model[path][3] = valid
def test_bad_regex_compilation(pattern): from meld.filters import FilterEntry f = FilterEntry.new_from_gsetting(("name", True, pattern), FilterEntry.REGEX) assert f.filter is None
def test_bad_regex_compilation(pattern): from meld.filters import FilterEntry f = FilterEntry.new_from_gsetting( ("name", True, pattern), FilterEntry.REGEX) assert f.filter is None