Exemplo n.º 1
0
    def test_symbols_build_symbols(self, test_input, expected,
                                   python_syntax: PythonSyntax):
        desired_symbols = python_syntax.get_desired_symbols(test_input)
        target_symbol, target_line, symbol_list = python_syntax.parse_symbols(
            desired_symbols)

        assert python_syntax.build_symbols(target_line,
                                           symbol_list) == expected
Exemplo n.º 2
0
    def test_empty_symbols_build_symbols(self, python_syntax: PythonSyntax):
        '''
        Test that empty symbol list from the view, an empty parsed symbol tuple will raise an error.
        `build_symbols` can't execute becuse it needs the parsed symbols to not be empty
        '''
        view = View(Selection(4), [])
        desired_symbols = python_syntax.get_desired_symbols(view)

        with pytest.raises(ValueError):
            target_symbol, target_line, symbol_list = python_syntax.parse_symbols(
                desired_symbols)
            python_syntax.build_symbols(target_line, symbol_list)
Exemplo n.º 3
0
    def test_symbol_message(self, python_syntax: PythonSyntax):
        symbol.sublime = type('sublime', (object, ), {'status_message': None})
        symbol.sublime.status_message = Mock(
            side_effect=lambda msg: print(msg))

        symbols = [
            (Region(0, 1), 'Foo:'),
            (Region(2, 3), '    method1(…)'),
            (Region(3, 4), '    method2(…)'),
        ]

        view = View(Selection(4), symbols,
                    'Packages/Python/Python.sublime-syntax')

        view.ignored_packages.append('MagicPython')

        python_syntax.on_selection_modified(view)

        symbol.sublime.status_message.assert_called_with('[ Foo ↦ method2() ]')
Exemplo n.º 4
0
    def test_no_message_on_invalid_syntax(self, test_input,
                                          python_syntax: PythonSyntax):
        '''
            Test that in the presence of a syntax that is not
            'Packages/Python/Python.sublime-syntax', getting symbols will not work
        '''
        symbol.sublime = type('sublime', (object, ), {'status_message': None})
        symbol.sublime.status_message = Mock(
            side_effect=lambda msg: print(msg))

        symbols = [
            (Region(0, 1), 'Foo:'),
            (Region(2, 3), '    method1(…)'),
            (Region(3, 4), '    method2(…)'),
        ]

        view = View(Selection(4), symbols, test_input)

        python_syntax.on_selection_modified(view)

        assert python_syntax.on_selection_modified(view) is None
Exemplo n.º 5
0
    def test_symbol_message_on_invalid_syntax(self,
                                              python_syntax: PythonSyntax):
        '''
            Test that when using the inbuilt Python Syntax as primary syntax and
            MagicPython syntax is not disabled (added to the ignored package list),
            a status bar messaged is shown saying that MagicPython should be disabled
        '''
        symbol.sublime = type('sublime', (object, ), {'status_message': None})
        symbol.sublime.status_message = Mock(
            side_effect=lambda msg: print(msg))

        symbols = [
            (Region(0, 1), 'Foo:'),
            (Region(2, 3), '    method1(…)'),
            (Region(3, 4), '    method2(…)'),
        ]

        view = View(Selection(4), symbols,
                    'Packages/Python/Python.sublime-syntax')

        python_syntax.on_selection_modified(view)

        symbol.sublime.status_message.assert_called_with(
            '[ Disable the MagicPython syntax package !!]')
Exemplo n.º 6
0
def python_syntax():
    '''Returns a instance of PythonSyntax class'''
    return PythonSyntax()
Exemplo n.º 7
0
 def test_get_symbolname_on_invalid_inputs(self, test_input, expected,
                                           python_syntax: PythonSyntax):
     assert python_syntax.get_symbolname(test_input) == expected