def test(self): with open(self._join_data_path('test_file1.py')) as f: text1 = f.read() with open(self._join_data_path('test_file2.py')) as f: text2 = f.read() raw_text_document1 = RawTextDocument(text1) raw_text_document2 = RawTextDocument(text2) two_way_file_diff_factory = TwoWayFileDiffFactory() file_diff = two_way_file_diff_factory.process(raw_text_document1, raw_text_document2) file_diff.pretty_print() file_diff.print_unidiff() print('=' * 10) replace_group = file_diff[1] print(replace_group) print(replace_group[1].chunk1) print(list(replace_group[1].chunk1.line_iterator())) print(list(replace_group[1].chunk2.line_iterator())) print(list(replace_group[1].chunk1.line_slice_iterator()))
def test(self): with open(self._join_data_path('test_file1.py')) as f: text1 = f.read() with open(self._join_data_path('test_file2.py')) as f: text2 = f.read() lexer = get_lexer_for_filename('data/test_file1.py', stripnl=False) raw_text_document1 = RawTextDocument(text1) raw_text_document2 = RawTextDocument(text2) file_diff = TwoWayFileDiffFactory().process(raw_text_document1, raw_text_document2) document_model1, document_model2 = TextDocumentDiffModelFactory( ).process(file_diff) highlighted_text1 = HighlightedText(raw_text_document1, lexer) print('Document 1:') self._pretty_print(document_model1) print('\nHighlighted Document 1:') highlighted_document1 = highlight_document(document_model1, highlighted_text1) self._pretty_print(highlighted_document1)
def test_line_of(self): text_buffer = "01\n34\n6" raw_text_document = RawTextDocument(text_buffer) self.assertEqual(raw_text_document.line_of(0), 0) self.assertEqual(raw_text_document.line_of(4), 1) self.assertEqual(raw_text_document.line_of(6), 2)
def test_line_of(self): text_buffer = "01\n34\n6" raw_text_document = RawTextDocument(text_buffer) self.assertEqual(raw_text_document.line_of(0), 0) self.assertEqual(raw_text_document.line_of(4), 1) self.assertEqual(raw_text_document.line_of(6), 2)
def test_light_view(self): text_buffer = 'azertyuiopqsdfghjklm' raw_text_document = RawTextDocument(text_buffer) raw_text_document.light_view_mode = True flat_slice = FlatSlice(5, 10) view = raw_text_document[flat_slice] self.assertEqual(str(view), text_buffer[flat_slice()])
def _test_text(self, text_buffer, line_slice, sub_string): raw_text_document = RawTextDocument(text_buffer) lines = raw_text_document.lines(new_line_separator=False) self.assertEqual(len(lines), len(text_buffer.splitlines())) lines = raw_text_document.lines() self.assertEqual(len(text_buffer), sum([len(x) for x in lines])) self.assertEqual(raw_text_document.substring(FlatSlice(5, 10)), text_buffer[5:10]) self.assertEqual(raw_text_document.substring(line_slice), sub_string)
def test_light_view(self): text_buffer = 'azertyuiopqsdfghjklm' raw_text_document = RawTextDocument(text_buffer) raw_text_document.light_view_mode = True flat_slice = FlatSlice(5, 10) view = raw_text_document[flat_slice] self.assertEqual(str(view), text_buffer[flat_slice()])
def test(self): test_file_path = os.path.join(os.path.dirname(__file__), 'data', 'test_file1.py') with open(test_file_path) as f: text = f.read() raw_text_document = RawTextDocument(text) lexer = get_lexer_for_filename(test_file_path, stripnl=False) highlighted_text = HighlightedText(raw_text_document, lexer) for fragment in highlighted_text: print(repr(fragment), '[' + raw_text_document.substring(fragment.slice) + ']')
def test(self): test_file_path = os.path.join(os.path.dirname(__file__), 'data', 'test_file1.py') with open(test_file_path) as f: text = f.read() raw_text_document = RawTextDocument(text) lexer = get_lexer_for_filename(test_file_path, stripnl=False) highlighted_text = HighlightedText(raw_text_document, lexer) for fragment in highlighted_text: print(repr(fragment), '[' + raw_text_document.substring(fragment.slice) + ']')
def test_empty(self): text1 = '' with open(self._join_data_path('test_file2.py')) as f: text2 = f.read() raw_text_document1 = RawTextDocument(text1) raw_text_document2 = RawTextDocument(text2) two_way_file_diff_factory = TwoWayFileDiffFactory() file_diff = two_way_file_diff_factory.process(raw_text_document1, raw_text_document2) file_diff.pretty_print() file_diff.print_unidiff()
def test_view(self): text_buffer = '' for i in range(10): text_buffer += 'azerty' + str(i) + '\n' raw_text_document = RawTextDocument(text_buffer) view = raw_text_document[LineSlice(1, 3)] self.assertEqual(str(view).splitlines(), text_buffer.splitlines()[1:3]) self.assertEqual(view.substring(FlatSlice(0, 6)), 'azerty') text_buffer = "012\n45\n78\n01" raw_text_document = RawTextDocument(text_buffer) view = raw_text_document[FlatSlice(5, 11)] self.assertEqual( str(view).splitlines(), [x.strip() for x in view.lines()])
def diff_text_documents(self, show=False): OLD, NEW = list(range(2)) for i in (OLD, NEW): if self._paths[i] is None: self._texts[i] = '' elif self._texts[i] is None: self._texts[i] = self._read_file(self._paths[i]) lexers = [ self._get_lexer(path, text) for path, text in zip(self._paths, self._texts) ] raw_text_documents = [RawTextDocument(text) for text in self._texts] highlight = self._highlight_action.isChecked() number_of_lines_of_context = self._lines_of_context_combobox.currentData( ) self._highlighted_documents = [] if not show: file_diff = TwoWayFileDiffFactory().process( *raw_text_documents, number_of_lines_of_context=number_of_lines_of_context, ) document_models = TextDocumentDiffModelFactory().process(file_diff) for raw_text_document, document_model, lexer in zip( raw_text_documents, document_models, lexers): if lexer is not None and highlight: highlighted_text = HighlightedText(raw_text_document, lexer) highlighted_document = highlight_document( document_model, highlighted_text) else: highlighted_document = document_model self._highlighted_documents.append(highlighted_document) else: # Only show the document # Fixme: broken, chunk_type is ??? # self._diff_view.set_document_models(self._highlighted_documents, complete_mode) # File "/home/gv/fabrice/unison-osiris/git-python/CodeReview/DiffWidget.py", line 333, in set_document_models # cursor.begin_block(side, text_block.frame_type) # File "/home/gv/fabrice/unison-osiris/git-python/CodeReview/DiffWidget.py", line 99, in begin_block # if ((side == LEFT and frame_type == chunk_type.insert) or # File "/home/gv/fabrice/unison-osiris/git-python/CodeReview/Tools/EnumFactory.py", line 107, in __eq__ # return self._value == int(other) # TypeError: int() argument must be a string or a number, not 'NoneType' for raw_text_document, lexer in zip(raw_text_documents, self._lexers): highlighted_document = highlight_text(raw_text_document, lexer) self._highlighted_documents.append(highlighted_document) if self._metadatas is not None: for highlighted_document, metadata in zip( self._highlighted_documents, self._metadatas): highlighted_document.metadata = metadata
def _test_text(self, text_buffer, line_slice, sub_string): raw_text_document = RawTextDocument(text_buffer) lines = raw_text_document.lines(new_line_separator=False) self.assertEqual(len(lines), len(text_buffer.splitlines())) lines = raw_text_document.lines() self.assertEqual(len(text_buffer), sum([len(x) for x in lines])) self.assertEqual(raw_text_document.substring(FlatSlice(5, 10)), text_buffer[5:10]) self.assertEqual(raw_text_document.substring(line_slice), sub_string)
def test_empty(self): raw_text_document = RawTextDocument('')