def test_delete_last_line_crlf(text, newline, expected_text): filediff = mock.Mock(FileDiff) with mock.patch.multiple( 'meld.meldbuffer', bind_settings=mock.DEFAULT, meldsettings=mock.DEFAULT): with mock.patch('meld.meldbuffer.MeldBuffer.set_style_scheme'): meldbuffer = meld.meldbuffer.MeldBuffer() meldbuffer.set_text(text) def make_last_line_chunk(buf): end = buf.get_line_count() last = end - 1 return DiffChunk('delete', last, end, last, end) start, end = meldbuffer.get_bounds() buf_text = meldbuffer.get_text(start, end, False) print(repr(buf_text)) with mock.patch.object( meldbuffer.data.sourcefile, 'get_newline_type', return_value=newline): filediff.textbuffer = [meldbuffer] filediff.textview = [mock.Mock()] FileDiff.delete_chunk(filediff, 0, make_last_line_chunk(meldbuffer)) start, end = meldbuffer.get_bounds() buf_text = meldbuffer.get_text(start, end, False) print(repr(buf_text)) assert buf_text == expected_text
def test_delete_last_line_crlf(text, newline, expected_text): import meld.meldbuffer from meld.filediff import FileDiff from meld.matchers.myers import DiffChunk filediff = mock.Mock(FileDiff) with mock.patch.multiple( 'meld.meldbuffer', bind_settings=mock.DEFAULT, meldsettings=mock.DEFAULT): with mock.patch('meld.meldbuffer.MeldBuffer.set_style_scheme'): meldbuffer = meld.meldbuffer.MeldBuffer() meldbuffer.set_text(text) def make_last_line_chunk(buf): end = buf.get_line_count() last = end - 1 return DiffChunk('delete', last, end, last, end) start, end = meldbuffer.get_bounds() buf_text = meldbuffer.get_text(start, end, False) print(repr(buf_text)) with mock.patch.object( meldbuffer.data.sourcefile, 'get_newline_type', return_value=newline): filediff.textbuffer = [meldbuffer] filediff.textview = [mock.Mock()] FileDiff.delete_chunk(filediff, 0, make_last_line_chunk(meldbuffer)) start, end = meldbuffer.get_bounds() buf_text = meldbuffer.get_text(start, end, False) print(repr(buf_text)) assert buf_text == expected_text
def append_filediff( self, gfiles, *, encodings=None, merge_output=None, meta=None): assert len(gfiles) in (1, 2, 3) doc = FileDiff(len(gfiles)) self._append_page(doc, "text-x-generic") doc.set_files(gfiles, encodings) if merge_output is not None: doc.set_merge_output_file(merge_output) if meta is not None: doc.set_meta(meta) return doc
def append_filemerge(self, gfiles, merge_output=None): if len(gfiles) != 3: raise ValueError( _("Need three files to auto-merge, got: %r") % [f.get_parse_name() for f in gfiles]) doc = FileDiff(len(gfiles), comparison_mode=FileComparisonMode.AutoMerge) self._append_page(doc) doc.set_files(gfiles) if merge_output is not None: doc.set_merge_output_file(merge_output) return doc
def get_comparison(self): comp = FileDiff.get_comparison(self) return RecentType.Merge, comp[1]
def _connect_buffer_handlers(self): FileDiff._connect_buffer_handlers(self) self.textview[0].set_editable(0) self.textview[2].set_editable(0)