def test_empty_parse_symbols(status_symbol: StatusSymbol) -> None: view = View(Selection(4), []) desired_symbols = status_symbol.get_desired_symbols(view) parsed_symbol = status_symbol.parse_symbols(desired_symbols) assert parsed_symbol == ()
def test_empty_desired_symbols(self, status_symbol: StatusSymbol) -> None: ''' Test that an empty symbols list produces an empty list of desired symbols ''' view = View(Selection(0), []) assert status_symbol.get_desired_symbols(view) == []
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)
def test_parse_symbols(status_symbol: StatusSymbol) -> None: symbols = [ (Region(0, 1), 'Foo:'), (Region(2, 3), ' method1(…)'), (Region(3, 4), ' method2(…)'), ] view = View(Selection(4), symbols) desired_symbols = status_symbol.get_desired_symbols(view) parsed_symbol = status_symbol.parse_symbols(desired_symbols) target_symbol, *rest_symbols = desired_symbols assert parsed_symbol == (target_symbol, target_symbol[1], rest_symbols)
def test_non_empty_desired_symbols(self, status_symbol: StatusSymbol) -> None: ''' Test that an non empty symbols list produces the same symbol list but reveresed ''' symbols = [ (Region(0, 1), 'Foo:'), (Region(2, 3), ' method1(…)'), (Region(3, 4), ' method2(…)'), ] view = View(Selection(4), symbols) expected = list(reversed(symbols)) assert status_symbol.get_desired_symbols(view) == expected
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() ]')
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
def test_filtered_desired_symbols(self, status_symbol: StatusSymbol) -> None: ''' Test that an non empty symbols list with a specific selected region produces a reversed symbol list with symbols which have a starting region above the selected region ''' symbols = [ (Region(0, 1), 'Foo:'), (Region(2, 3), ' method1(…)'), (Region(3, 4), ' method2(…)'), (Region(4, 5), ' method3(…)'), ] view = View(Selection(3), symbols) expected = list( reversed([ (Region(0, 1), 'Foo:'), (Region(2, 3), ' method1(…)'), ])) assert status_symbol.get_desired_symbols(view) == expected
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 !!]')