Exemplo n.º 1
0
 def test_apply_pygments_without_lexer(self):
     """Testing RawDiffChunkGenerator._apply_pygments without valid lexer"""
     chunk_generator = RawDiffChunkGenerator(old=[],
                                             new=[],
                                             orig_filename='file1',
                                             modified_filename='file2')
     self.assertIsNone(
         chunk_generator._apply_pygments(data='This is **bold**',
                                         filename='test'))
Exemplo n.º 2
0
    def test_get_move_info_with_no_move(self):
        """Testing RawDiffChunkGenerator._get_move_info with no move range"""
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertIsNone(generator._get_move_info(500, {
            8: 100,
            9: 101,
            10: 200,
            11: 201,
        }))
Exemplo n.º 3
0
 def test_apply_pygments_with_lexer(self):
     """Testing RawDiffChunkGenerator._apply_pygments with valid lexer"""
     chunk_generator = RawDiffChunkGenerator(old=[],
                                             new=[],
                                             orig_filename='file1',
                                             modified_filename='file2')
     self.assertEqual(
         chunk_generator._apply_pygments(data='This is **bold**\n',
                                         filename='test.md'),
         ['This is <span class="gs">**bold**</span>'])
    def test_get_move_info_with_no_move(self):
        """Testing RawDiffChunkGenerator._get_move_info with no move range"""
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertIsNone(generator._get_move_info(500, {
            8: 100,
            9: 101,
            10: 200,
            11: 201,
        }))
Exemplo n.º 5
0
    def test_get_move_info_with_new_range_no_preceding(self):
        """Testing RawDiffChunkGenerator._get_move_info with new move range and
        no adjacent preceding move range
        """
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertEqual(
            generator._get_move_info(10, {
                8: 100,
                10: 200,
                11: 201,
            }), (200, True))
Exemplo n.º 6
0
    def test_get_move_info_with_existing_range(self):
        """Testing RawDiffChunkGenerator._get_move_info with existing move
        range
        """
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertEqual(
            generator._get_move_info(11, {
                8: 100,
                9: 101,
                10: 200,
                11: 201,
            }), (201, False))
    def test_get_move_info_with_new_range_no_preceding(self):
        """Testing RawDiffChunkGenerator._get_move_info with new move range and
        no adjacent preceding move range
        """
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertEqual(
            generator._get_move_info(10, {
                8: 100,
                10: 200,
                11: 201,
            }),
            (200, True))
    def test_get_move_info_with_existing_range(self):
        """Testing RawDiffChunkGenerator._get_move_info with existing move
        range
        """
        generator = RawDiffChunkGenerator([], [], 'file1', 'file2')

        self.assertEqual(
            generator._get_move_info(11, {
                8: 100,
                9: 101,
                10: 200,
                11: 201,
            }),
            (201, False))
    def generator(self):
        """Create a dummy generator for tests that need it.

        This generator will be void of any content. It's intended for
        use in tests that need to operate on its utility functions.
        """
        return RawDiffChunkGenerator('', '', '', '')
    def test_get_chunks(self):
        """Testing RawDiffChunkGenerator.get_chunks"""
        old = (b'This is line 1\n'
               b'Another line\n'
               b'Line 3.\n'
               b'la de da.\n')

        new = (b'This is line 1\n' b'Line 3.\n' b'la de doo.\n')

        generator = RawDiffChunkGenerator(old, new, 'file1', 'file2')
        chunks = list(generator.get_chunks())

        self.assertEqual(len(chunks), 4)
        self.assertEqual(chunks[0]['change'], 'equal')
        self.assertEqual(chunks[1]['change'], 'delete')
        self.assertEqual(chunks[2]['change'], 'equal')
        self.assertEqual(chunks[3]['change'], 'replace')
Exemplo n.º 11
0
    def test_get_chunks_with_enable_syntax_highlighting_false(self):
        """Testing RawDiffChunkGenerator.get_chunks with
        enable_syntax_highlighting=False
        """
        old = b'This is **bold**'
        new = b'This is *italic*'

        generator = RawDiffChunkGenerator(old=old,
                                          new=new,
                                          orig_filename='file1.md',
                                          modified_filename='file2.md',
                                          enable_syntax_highlighting=False)
        chunks = list(generator.get_chunks())

        self.assertEqual(len(chunks), 1)
        self.assertEqual(
            chunks[0], {
                'change':
                'replace',
                'collapsable':
                False,
                'index':
                0,
                'lines': [
                    [
                        1,
                        1,
                        'This is **bold**',
                        [(9, 16)],
                        1,
                        'This is *italic*',
                        [(9, 16)],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines':
                1,
            })
Exemplo n.º 12
0
    def generator(self):
        """Create a dummy generator for tests that need it.

        This generator will be void of any content. It's intended for
        use in tests that need to operate on its utility functions.
        """
        return RawDiffChunkGenerator(old=b'',
                                     new=b'',
                                     orig_filename='',
                                     modified_filename='')
    def test_get_chunks(self):
        """Testing RawDiffChunkGenerator.get_chunks"""
        old = (
            b'This is line 1\n'
            b'Another line\n'
            b'Line 3.\n'
            b'la de da.\n'
        )

        new = (
            b'This is line 1\n'
            b'Line 3.\n'
            b'la de doo.\n'
        )

        generator = RawDiffChunkGenerator(old, new, 'file1', 'file2')
        chunks = list(generator.get_chunks())

        self.assertEqual(len(chunks), 4)
        self.assertEqual(chunks[0]['change'], 'equal')
        self.assertEqual(chunks[1]['change'], 'delete')
        self.assertEqual(chunks[2]['change'], 'equal')
        self.assertEqual(chunks[3]['change'], 'replace')
Exemplo n.º 14
0
    def test_generate_chunks_with_encodings(self):
        """Testing RawDiffChunkGenerator.generate_chunks with explicit
        encodings for old and new
        """
        old = ('This is line 1\n'
               'Another line\n'
               'Line 3.\n'
               'la de da.\n').encode('utf-8')

        new = ('This is line 1\n' 'Line 3.\n' 'la de doo.\n').encode('utf-16')

        generator = RawDiffChunkGenerator(old=old,
                                          new=new,
                                          orig_filename='file1',
                                          modified_filename='file2')
        chunks = list(
            generator.generate_chunks(old=old,
                                      new=new,
                                      old_encoding_list=['utf-8'],
                                      new_encoding_list=['utf-16']))

        self.assertEqual(len(chunks), 4)
        self.assertEqual(
            chunks[0], {
                'change':
                'equal',
                'collapsable':
                False,
                'index':
                0,
                'lines': [
                    [
                        1,
                        1,
                        'This is line 1',
                        [],
                        1,
                        'This is line 1',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines':
                1,
            })
        self.assertEqual(
            chunks[1], {
                'change': 'delete',
                'collapsable': False,
                'index': 1,
                'lines': [
                    [
                        2,
                        2,
                        'Another line',
                        [],
                        '',
                        '',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines': 1,
            })
        self.assertEqual(
            chunks[2], {
                'change': 'equal',
                'collapsable': False,
                'index': 2,
                'lines': [
                    [
                        3,
                        3,
                        'Line 3.',
                        [],
                        2,
                        'Line 3.',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines': 1,
            })
        self.assertEqual(
            chunks[3], {
                'change':
                'replace',
                'collapsable':
                False,
                'index':
                3,
                'lines': [
                    [
                        4,
                        4,
                        'la de da.',
                        [(7, 8)],
                        3,
                        'la de doo.',
                        [(7, 9)],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines':
                1,
            })
Exemplo n.º 15
0
    def test_get_chunks(self):
        """Testing RawDiffChunkGenerator.get_chunks"""
        old = (b'This is line 1\n'
               b'Another line\n'
               b'Line 3.\n'
               b'la de da.\n')

        new = (b'This is line 1\n' b'Line 3.\n' b'la de doo.\n')

        generator = RawDiffChunkGenerator(old, new, 'file1', 'file2')
        chunks = list(generator.get_chunks())

        self.assertEqual(len(chunks), 4)
        self.assertEqual(
            chunks[0], {
                'change':
                'equal',
                'collapsable':
                False,
                'index':
                0,
                'lines': [
                    [
                        1,
                        1,
                        'This is line 1',
                        [],
                        1,
                        'This is line 1',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines':
                1,
            })
        self.assertEqual(
            chunks[1], {
                'change': 'delete',
                'collapsable': False,
                'index': 1,
                'lines': [
                    [
                        2,
                        2,
                        'Another line',
                        [],
                        '',
                        '',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines': 1,
            })
        self.assertEqual(
            chunks[2], {
                'change': 'equal',
                'collapsable': False,
                'index': 2,
                'lines': [
                    [
                        3,
                        3,
                        'Line 3.',
                        [],
                        2,
                        'Line 3.',
                        [],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines': 1,
            })
        self.assertEqual(
            chunks[3], {
                'change':
                'replace',
                'collapsable':
                False,
                'index':
                3,
                'lines': [
                    [
                        4,
                        4,
                        'la de da.',
                        [(7, 8)],
                        3,
                        'la de doo.',
                        [(7, 9)],
                        False,
                    ],
                ],
                'meta': {
                    'left_headers': [],
                    'right_headers': [],
                    'whitespace_chunk': False,
                    'whitespace_lines': [],
                },
                'numlines':
                1,
            })