Exemple #1
0
    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 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(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) + ']')