Exemplo n.º 1
0
 def test_pygmentize_args(self):
     """ Testing the pygmentize_args method. """
     processor = CodeExample(self.env)
     args = 'test1'
     pygmentized = 'test1\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
     self.assertEqual(args, processor.pygmentize_args(args, False))
Exemplo n.º 2
0
    def test_expand_macro(self):
        """ Testing the expand_macro method. """
        processor = CodeExample(self.env)
        args = 'test'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))

        args = '##type=bad\ntest'
        expected = '<div ' \
        'class="bad_example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link2">' \
        'SELECT ALL</span>\n\t\n\t<span>INCORRECT EXAMPLE:</span>\n' \
        '</div>\n    \n    <div class="code">' \
        '\n        <pre id="codelink2">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))

        args = '##type=good\ntest'
        expected = '<div ' \
        'class="good_example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link3">' \
        'SELECT ALL</span>\n\t\n\t<span>CORRECT EXAMPLE:</span>\n</div>' \
        '\n    \n    <div class="code">' \
        '\n        <pre id="codelink3">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))
Exemplo n.º 3
0
 def test_get_analyzed_content(self):
     """ Testing getting required range from the text."""
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree\nfour'
     lines = '1-2, 4'
     expected = [(0, 'one'), (1, 'two'), (3, 'four')]
     self.assertEqual(expected, processor.get_analyzed_content(text, lines))
Exemplo n.º 4
0
 def test_get_analyzed_content(self):
     """ Testing getting required range from the text."""
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree\nfour'
     lines = '1-2, 4'
     expected = [(0, 'one'), (1, 'two'), (3, 'four')]
     self.assertEqual(expected, processor.get_analyzed_content(text, lines))
Exemplo n.º 5
0
 def test_pygmentize_args(self):
     """ Testing the pygmentize_args method. """
     processor = CodeExample(self.env)
     args = 'test1'
     pygmentized = 'test1\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
     self.assertEqual(args, processor.pygmentize_args(args, False))
Exemplo n.º 6
0
    def test_expand_macro(self):
        """ Testing the expand_macro method. """
        processor = CodeExample(self.env)
        args = 'test'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))

        args = '##type=bad\ntest'
        expected = '<div ' \
        'class="bad_example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link2">' \
        'SELECT ALL</span>\n\t\n\t<span>INCORRECT EXAMPLE:</span>\n' \
        '</div>\n    \n    <div class="code">' \
        '\n        <pre id="codelink2">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))

        args = '##type=good\ntest'
        expected = '<div ' \
        'class="good_example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link3">' \
        'SELECT ALL</span>\n\t\n\t<span>CORRECT EXAMPLE:</span>\n</div>' \
        '\n    \n    <div class="code">' \
        '\n        <pre id="codelink3">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))
Exemplo n.º 7
0
 def test_csharp_render(self):
     """ Testing the CSharp rendering. """
     processor = CodeExample(self.env)
     content = '#!c#\ndouble test() {}'
     pygmentized = '<span class="kt">double</span> ' \
         '<span class="nf">test</span><span class="p">()</span> ' \
         '<span class="p">{}</span>\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(content, True))
Exemplo n.º 8
0
 def test_pygmentize_with_windows_new_lines(self):
     """ Testing the pygmentize_args method with Windows new lines. """
     processor = CodeExample(self.env)
     args = '#!python\r\ndef Class:\n    pass\n'
     pygmentized = '<span class="k">def</span> ' \
     '<span class="nf">Class</span><span class="p">:</span>\n' \
     '    <span class="k">pass</span>\n\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
Exemplo n.º 9
0
 def test_get_macros(self):
     """ Testing the get_macros method. """
     processor = CodeExample(self.env)
     expected_result = ['CodeExample']
     index = 0
     for macros in processor.get_macros():
         self.assertEqual(macros, expected_result[index])
         index += 1
Exemplo n.º 10
0
 def test_get_macros(self):
     """ Testing the get_macros method. """
     processor = CodeExample(self.env)
     expected_result = ['CodeExample']
     index = 0
     for macros in processor.get_macros():
         self.assertEqual(macros, expected_result[index])
         index += 1
Exemplo n.º 11
0
 def test_csharp_render(self):
     """ Testing the CSharp rendering. """
     processor = CodeExample(self.env)
     content = '#!c#\ndouble test() {}'
     pygmentized = '<span class="kt">double</span> ' \
         '<span class="nf">test</span><span class="p">()</span> ' \
         '<span class="p">{}</span>\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(content, True))
Exemplo n.º 12
0
 def test_pygmentize_with_windows_new_lines(self):
     """ Testing the pygmentize_args method with Windows new lines. """
     processor = CodeExample(self.env)
     args = '#!python\r\ndef Class:\n    pass\n'
     pygmentized = '<span class="k">def</span> ' \
     '<span class="nf">Class</span><span class="p">:</span>\n' \
     '    <span class="k">pass</span>\n\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
Exemplo n.º 13
0
 def test_render_as_lang(self):
     """ Testing the render_as_lang method. """
     processor = CodeExample(self.env)
     lang = 'python'
     content = 'def Class:\n    pass\n'
     pygmentized = '<span class="k">def</span> ' \
     '<span class="nf">Class</span><span class="p">:</span>\n' \
     '    <span class="k">pass</span>\n'
     self.assertEqual(pygmentized, processor.render_as_lang(lang, content))
Exemplo n.º 14
0
 def test_get_quote_without_match(self):
     """ Testing getting quote from the text without regex match. """
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree'
     args = '##regex=four'
     processor._args = args
     processor.extract_options()
     expected = 'two'
     self.assertEqual(text, processor.get_quote(text, args))
Exemplo n.º 15
0
 def test_get_quote(self):
     """ Testing getting quote from the text. """
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree'
     args = '##regex=two\n##lines=1'
     processor._args = args
     processor.extract_options()
     expected = 'two'
     self.assertEqual(expected, processor.get_quote(text, args))
Exemplo n.º 16
0
 def test_render_as_lang(self):
     """ Testing the render_as_lang method. """
     processor = CodeExample(self.env)
     lang = 'python'
     content = 'def Class:\n    pass\n'
     pygmentized = '<span class="k">def</span> ' \
     '<span class="nf">Class</span><span class="p">:</span>\n' \
     '    <span class="k">pass</span>\n'
     self.assertEqual(pygmentized, processor.render_as_lang(lang, content))
Exemplo n.º 17
0
    def test_broken_repos(self):
        """ Testing broken repository. """
        def get_broken_repos():
            raise TracError('')

        processor = CodeExample(self.env)
        processor.get_repos_manager = get_broken_repos
        src = ''
        expected = ''
        self.assertEqual(expected, processor.get_sources(src))
Exemplo n.º 18
0
    def test_broken_repos(self):
        """ Testing broken repository. """

        def get_broken_repos():
            raise TracError('')

        processor = CodeExample(self.env)
        processor.get_repos_manager = get_broken_repos
        src = ''
        expected = ''
        self.assertEqual(expected, processor.get_sources(src))
Exemplo n.º 19
0
    def test_expand_macro_with_unicode(self):
        """ Testing the expand_macro method with unicode symbols. """
        processor = CodeExample(self.env)
        args = 'ТЕСТ'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">ТЕСТ\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))
Exemplo n.º 20
0
    def test_expand_macro_with_unicode(self):
        """ Testing the expand_macro method with unicode symbols. """
        processor = CodeExample(self.env)
        args = 'ТЕСТ'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">ТЕСТ\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))
Exemplo n.º 21
0
 def test_link_updating_with_index(self):
     """ Testing adding anchor to the source link. """
     processor = CodeExample(self.env)
     processor._link = 'path'
     processor._args = "##regex=def"
     processor.extract_options()
     processor.get_quote("test1\ndef\ntest2", "")
     expected = 'path#L2'
     self.assertEqual(expected, processor._link)
Exemplo n.º 22
0
 def test_get_sources_with_missing_file(self):
     """ Testing getting sources with incorrect path. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager(True)
     src = '##path=1'
     processor._args = src
     processor.extract_path()
     self.assertEqual(src, processor.get_sources(src))
Exemplo n.º 23
0
 def test_link_updating_with_index(self):
     """ Testing adding anchor to the source link. """
     processor = CodeExample(self.env)
     processor._link = 'path'
     processor._args = "##regex=def"
     processor.extract_options()
     processor.get_quote("test1\ndef\ntest2", "")
     expected = 'path#L2'
     self.assertEqual(expected, processor._link)
Exemplo n.º 24
0
 def test_get_repo(self):
     """ Testing getting sources. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager()
     src = '##repo=1\n##path=1'
     processor._args = src
     processor.extract_options()
     expected = 'repo:1'
     self.assertEqual(expected, processor.get_sources(src))
Exemplo n.º 25
0
    def test_path_recognition(self):
        """ Testing correct path requirements. """
        processor = CodeExample(self.env)
        args = '##path=test\nТЕСТ'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="system-message">\n    <strong>' \
        'During the example analyzing the following problems' \
        ' appear:</strong>\n    <ul>\n        ' \
        '<li>Path element is not found.</li>\n    '\
        '</ul>\n    </div>' \
        '\n    \n    <div class="code">' \
        '\n        <pre id="codelink1">ТЕСТ\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))
Exemplo n.º 26
0
    def test_macro_with_invalid_lang(self):
        """ Testing the expand_macro method with invalid language. """
        processor = CodeExample(self.env)
        args = '#!python1\ntest'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="system-message">\n    <strong>' \
        'During the example analyzing the following problems appear:' \
        '</strong>\n    ' \
        '<ul>\n        <li>no lexer for alias \'python1\' found</li>' \
        '\n    </ul>\n    </div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))
Exemplo n.º 27
0
    def test_path_recognition(self):
        """ Testing correct path requirements. """
        processor = CodeExample(self.env)
        args = '##path=test\nТЕСТ'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="system-message">\n    <strong>' \
        'During the example analyzing the following problems' \
        ' appear:</strong>\n    <ul>\n        ' \
        '<li>Path element is not found.</li>\n    '\
        '</ul>\n    </div>' \
        '\n    \n    <div class="code">' \
        '\n        <pre id="codelink1">ТЕСТ\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                         processor.expand_macro(formatter, name, args))
Exemplo n.º 28
0
    def test_macro_with_invalid_lang(self):
        """ Testing the expand_macro method with invalid language. """
        processor = CodeExample(self.env)
        args = '#!python1\ntest'
        formatter = Formatter(self.env, self.context)

        name = 'CodeExample'
        expected = '<div ' \
        'class="example">\n  <div class="title">\n\t' \
        '<span class="select_code" id="link1">' \
        'SELECT ALL</span>\n\t\n\t<span>EXAMPLE:</span>\n</div>\n    \n    ' \
        '<div class="system-message">\n    <strong>' \
        'During the example analyzing the following problems appear:' \
        '</strong>\n    ' \
        '<ul>\n        <li>no lexer for alias \'python1\' found</li>' \
        '\n    </ul>\n    </div>\n    \n    ' \
        '<div class="code">' \
        '\n        <pre id="codelink1">test\n</pre>\n    </div>\n</div>'
        self.assertEqual(expected,
                        processor.expand_macro(formatter, name, args))
Exemplo n.º 29
0
 def test_get_sources_with_missing_file(self):
     """ Testing getting sources with incorrect path. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager(True)
     src = '##path=1'
     processor._args = src
     processor.extract_path()
     self.assertEqual(src, processor.get_sources(src))
Exemplo n.º 30
0
 def test_get_quote_without_match(self):
     """ Testing getting quote from the text without regex match. """
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree'
     args = '##regex=four'
     processor._args = args
     processor.extract_options()
     expected = 'two'
     self.assertEqual(text, processor.get_quote(text, args))
Exemplo n.º 31
0
 def test_get_repo(self):
     """ Testing getting sources. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager()
     src = '##repo=1\n##path=1'
     processor._args = src
     processor.extract_options()
     expected = 'repo:1'
     self.assertEqual(expected, processor.get_sources(src))
Exemplo n.º 32
0
 def test_get_quote(self):
     """ Testing getting quote from the text. """
     processor = CodeExample(self.env)
     text = 'one\ntwo\nthree'
     args = '##regex=two\n##lines=1'
     processor._args = args
     processor.extract_options()
     expected = 'two'
     self.assertEqual(expected, processor.get_quote(text, args))
Exemplo n.º 33
0
    def test_import(self):
        """ Testing with pygments not installed. """

        import_stub = self.mocker.replace('__builtin__.__import__')
        self.expect(import_stub(mocker.MATCH(lambda x: x.count('pygments')),
                                  mocker.ANY, mocker.ANY, mocker.ANY)).\
                                  count(0, None)

        def import_errror_raiser(name, globals, locals, fromlist):
            raise ImportError

        self.mocker.call(import_errror_raiser)
        self.mocker.replay()
        import codeexample.code_example_processor
        reload(codeexample.code_example_processor)
        from codeexample.code_example_processor import CodeExample
        self.assertEqual(CodeExample.is_have_pygments(), False)
Exemplo n.º 34
0
    def test_import(self):
        """ Testing with pygments not installed. """

        import_stub = self.mocker.replace('__builtin__.__import__')
        self.expect(import_stub(mocker.MATCH(lambda x: x.count('pygments')),
                                  mocker.ANY, mocker.ANY, mocker.ANY)).\
                                  count(0, None)

        def import_errror_raiser(name, globals, locals, fromlist):
            raise ImportError

        self.mocker.call(import_errror_raiser)
        self.mocker.replay()
        import codeexample.code_example_processor
        reload(codeexample.code_example_processor)
        from codeexample.code_example_processor import CodeExample
        self.assertEqual(CodeExample.is_have_pygments(), False)
Exemplo n.º 35
0
    def test_parse_path(self):
        """ Testing correctness of parsing path. """
        processor = CodeExample(self.env)

        def get_lines(path):
            processor._args = path
            processor.extract_path()
            return processor._path[2]

        def get_focus_line(path):
            processor._args = path
            processor.extract_path()
            return processor._path[3]

        self.assertEqual('100', get_lines('##path=path@rev:100'))
        self.assertEqual('26-30', get_lines('##path=path@rev:26-30'))
        self.assertEqual('26-30,32-34,40',
                         get_lines('##path=path@rev:26-30,32-34,40'))
        self.assertEqual(100, get_focus_line('##path=path@rev:100#L100'))
Exemplo n.º 36
0
 def test_focus_line(self):
     """ Testing generating URL with focus line. """
     processor = CodeExample(self.env)
     processor._link = 'path'
     processor.get_quote('', '', '', 100)
     self.assertEqual('path#L100', processor._link)
Exemplo n.º 37
0
 def test_invalid_lang(self):
     """ Testing the pygmentize_args method with invalid language. """
     processor = CodeExample(self.env)
     args = '#!python1\ntest1\n'
     pygmentized = 'test1\n\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
Exemplo n.º 38
0
 def test_get_range(self):
     """ Testing getting required range from parsed lines. """
     self.assertEqual([26, 27, 28, 29, 30, 32, 33, 34, 40],
                      CodeExample.get_range('26-30,32-34,40'))
Exemplo n.º 39
0
 def test_get_htdocs_dirs(self):
     """ Testing get_htdocs_dirs method. """
     processor = CodeExample(self.env)
     htdocs = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                           '..', 'htdocs'))
     self.assertEqual(processor.get_htdocs_dirs(), [('ce', htdocs)])
Exemplo n.º 40
0
 def test_focus_line(self):
     """ Testing generating URL with focus line. """
     processor = CodeExample(self.env)
     processor._link = 'path'
     processor.get_quote('', '', '', 100)
     self.assertEqual('path#L100', processor._link)
Exemplo n.º 41
0
 def test_invalid_lang(self):
     """ Testing the pygmentize_args method with invalid language. """
     processor = CodeExample(self.env)
     args = '#!python1\ntest1\n'
     pygmentized = 'test1\n\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
Exemplo n.º 42
0
 def test_pygmentize_with_python(self):
     """ Testing the pygmentize_args method with Python code. """
     processor = CodeExample(self.env)
     args = '#!python\ntest1'
     pygmentized = 'test1\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))
Exemplo n.º 43
0
 def test_get_range(self):
     """ Testing getting required range from parsed lines. """
     self.assertEqual([26, 27, 28, 29, 30, 32, 33, 34, 40],
                      CodeExample.get_range('26-30,32-34,40'))
Exemplo n.º 44
0
 def test_get_htdocs_dirs(self):
     """ Testing get_htdocs_dirs method. """
     processor = CodeExample(self.env)
     htdocs = os.path.abspath(
         os.path.join(os.path.dirname(__file__), '..', 'htdocs'))
     self.assertEqual(processor.get_htdocs_dirs(), [('ce', htdocs)])
Exemplo n.º 45
0
 def test_get_sources_with_incorrect_path(self):
     """ Testing getting sources with incorrect path. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager()
     src = 'path1=1'
     self.assertEqual(src, processor.get_sources(src))
Exemplo n.º 46
0
 def test_get_macro_description(self):
     """ Testing the get_macro_description method. """
     processor = CodeExample(self.env)
     description = processor.get_macro_description('CodeExample')
     self.assertTrue(len(description) > 0)
Exemplo n.º 47
0
 def test_get_macro_description(self):
     """ Testing the get_macro_description method. """
     processor = CodeExample(self.env)
     description = processor.get_macro_description('CodeExample')
     self.assertTrue(len(description) > 0)
Exemplo n.º 48
0
 def test_get_sources_with_incorrect_path(self):
     """ Testing getting sources with incorrect path. """
     processor = CodeExample(self.env)
     processor.get_repos_manager = lambda: self.RepositoryManager()
     src = 'path1=1'
     self.assertEqual(src, processor.get_sources(src))
Exemplo n.º 49
0
 def test_pygmentize_with_python(self):
     """ Testing the pygmentize_args method with Python code. """
     processor = CodeExample(self.env)
     args = '#!python\ntest1'
     pygmentized = 'test1\n'
     self.assertEqual(pygmentized, processor.pygmentize_args(args, True))