From f5d96743fe1bdd0880e1222775107ebed3c2ac40 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jan 2015 20:13:19 +0300 Subject: [PATCH 01/21] Move IPython prompt and rcsh renderers into a separate module Some applications that use readline use same variants of telling it where highlighting starts and ends. This module will also be used for pdb. --- powerline/bindings/rc/powerline.rc | 2 +- powerline/renderers/ipython/__init__.py | 6 +++--- powerline/renderers/shell/rcsh.py | 9 ++------- powerline/renderers/shell/readline.py | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 powerline/renderers/shell/readline.py diff --git a/powerline/bindings/rc/powerline.rc b/powerline/bindings/rc/powerline.rc index 732d40c8..15b313a9 100644 --- a/powerline/bindings/rc/powerline.rc +++ b/powerline/bindings/rc/powerline.rc @@ -15,7 +15,7 @@ fn _powerline_continuation_prompt { _powerline_prompt --renderer-arg 'local_theme=continuation' $* } fn _powerline_prompt { - $POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell aboveleft -r.rcsh --last-pipe-status $^_POWERLINE_STATUS --last-exit-code $_POWERLINE_STATUS($#_POWERLINE_STATUS) --jobnum $_POWERLINE_JOBNUM --renderer-arg 'client_id='$pid $* + $POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell aboveleft -r.readline --last-pipe-status $^_POWERLINE_STATUS --last-exit-code $_POWERLINE_STATUS($#_POWERLINE_STATUS) --jobnum $_POWERLINE_JOBNUM --renderer-arg 'client_id='$pid $* } fn _powerline_set_prompt { _POWERLINE_STATUS = ( $status ) diff --git a/powerline/renderers/ipython/__init__.py b/powerline/renderers/ipython/__init__.py index 3547fd2e..a84418f1 100644 --- a/powerline/renderers/ipython/__init__.py +++ b/powerline/renderers/ipython/__init__.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) from powerline.renderers.shell import ShellRenderer +from powerline.renderers.shell.readline import ReadlineRenderer from powerline.theme import Theme @@ -45,10 +46,9 @@ class IPythonRenderer(ShellRenderer): ) -class IPythonPromptRenderer(IPythonRenderer): +class IPythonPromptRenderer(IPythonRenderer, ReadlineRenderer): '''Powerline ipython prompt (in and in2) renderer''' - escape_hl_start = '\x01' - escape_hl_end = '\x02' + pass class IPythonNonPromptRenderer(IPythonRenderer): diff --git a/powerline/renderers/shell/rcsh.py b/powerline/renderers/shell/rcsh.py index 4bc01412..75ccb223 100644 --- a/powerline/renderers/shell/rcsh.py +++ b/powerline/renderers/shell/rcsh.py @@ -1,12 +1,7 @@ # vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) -from powerline.renderers.shell import ShellRenderer +from powerline.renderers.shell.readline import ReadlineRenderer -class RcshRenderer(ShellRenderer): - '''Powerline rcsh prompt renderer''' - escape_hl_start = '\x01' - escape_hl_end = '\x02' - -renderer = RcshRenderer +renderer = ReadlineRenderer diff --git a/powerline/renderers/shell/readline.py b/powerline/renderers/shell/readline.py new file mode 100644 index 00000000..a72dff05 --- /dev/null +++ b/powerline/renderers/shell/readline.py @@ -0,0 +1,14 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +from powerline.renderers.shell import ShellRenderer + + +class ReadlineRenderer(ShellRenderer): + '''Renderer useful for some applications that use readline + ''' + escape_hl_start = '\x01' + escape_hl_end = '\x02' + + +renderer = ReadlineRenderer From 36d64bc3da41c12f08883debfc00a510998703f7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jan 2015 20:22:38 +0300 Subject: [PATCH 02/21] Remove unused `get_segment_info` method --- powerline/vim.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/powerline/vim.py b/powerline/vim.py index b93788a8..d4f5c2d6 100644 --- a/powerline/vim.py +++ b/powerline/vim.py @@ -217,10 +217,6 @@ class VimPowerline(Powerline): for args in _local_themes: self.add_local_theme(*args) - @staticmethod - def get_segment_info(): - return {} - def reset_highlight(self): try: self.renderer.reset_highlight() From 7250cd4bd85069aa802a5987fc39466444ca97db Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jan 2015 20:24:45 +0300 Subject: [PATCH 03/21] Use `:py:meth` for referring to methods --- powerline/renderer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/powerline/renderer.py b/powerline/renderer.py index 6d9b56a7..c03c42e8 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -124,8 +124,10 @@ class Renderer(object): 'getcwd': getattr(os, 'getcwdu', os.getcwd), 'home': os.environ.get('HOME'), } - '''Basic segment info. Is merged with local segment information by - ``.get_segment_info()`` method. Keys: + '''Basic segment info + + Is merged with local segment information by :py:meth:`get_segment_info` + method. Keys: ``environ`` Object containing environment variables. Must define at least the @@ -279,9 +281,10 @@ class Renderer(object): string_width)``. Returns a three-tuple if ``output_raw`` is also ``True``: ``(colored_string, colorless_string, string_width)``. :param dict segment_info: - Segment information. See also ``.get_segment_info()`` method. + Segment information. See also :py:meth:`get_segment_info` method. :param matcher_info: - Matcher information. Is processed in ``.get_theme()`` method. + Matcher information. Is processed in :py:meth:`get_segment_info` + method. ''' theme = self.get_theme(matcher_info) return self.do_render( @@ -504,7 +507,7 @@ class Renderer(object): def hl(self, contents, fg=None, bg=None, attrs=None): '''Output highlighted chunk. - This implementation just outputs ``.hlstyle()`` joined with + This implementation just outputs :py:meth:`hlstyle` joined with ``contents``. ''' return self.hlstyle(fg, bg, attrs) + (contents or '') From 9bbec772e063326466f6b175c338f5058e069213 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jan 2015 22:15:26 +0300 Subject: [PATCH 04/21] Add support for pdb prompt Note: pdbpp is not supported, it has lots of problems with unicode<-->str conversion (either explicit or implicit). --- docs/source/develop/segments.rst | 6 +++ docs/source/usage/other.rst | 27 ++++++++++ powerline/bindings/pdb/__init__.py | 54 +++++++++++++++++++ powerline/bindings/pdb/__main__.py | 29 ++++++++++ powerline/config_files/config.json | 4 ++ .../config_files/themes/pdb/default.json | 21 ++++++++ powerline/pdb.py | 19 +++++++ powerline/renderers/pdb.py | 34 ++++++++++++ 8 files changed, 194 insertions(+) create mode 100644 powerline/bindings/pdb/__init__.py create mode 100755 powerline/bindings/pdb/__main__.py create mode 100644 powerline/config_files/themes/pdb/default.json create mode 100644 powerline/pdb.py create mode 100644 powerline/renderers/pdb.py diff --git a/docs/source/develop/segments.rst b/docs/source/develop/segments.rst index 509eb7f7..a16f067d 100644 --- a/docs/source/develop/segments.rst +++ b/docs/source/develop/segments.rst @@ -469,6 +469,12 @@ Ipython Attribute ``prompt_count`` contains the so-called “history count” (equivalent to ``\N`` in ``in_template``). +Pdb +--- + +``pdb`` + Currently active :py:class:`pdb.Pdb` instance. + Segment class ============= diff --git a/docs/source/usage/other.rst b/docs/source/usage/other.rst index cbdab712..69144777 100644 --- a/docs/source/usage/other.rst +++ b/docs/source/usage/other.rst @@ -124,3 +124,30 @@ the used profile: IPython=0.11* is not supported and does not work. IPython<0.10 was not tested (not installable by pip). + +PDB prompt +========== + +To use Powerline with PDB prompt you need to use custom class. Inherit your +class from :py:class:`pdb.Pdb` and decorate it with +:py:func:`powerline.bindings.pdb.use_powerline_prompt`: + +.. code-block:: Python + + import pdb + + from powerline.bindings.pdb import use_powerline_prompt + + @use_powerline_prompt + class MyPdb(pdb.Pdb): + pass + + MyPdb.run('some.code.to.debug()') + +. Alternatively you may use + +.. code-block:: bash + + python -mpowerline.bindings.pdb path/to/script.py + +just like you used ``python -m pdb``. diff --git a/powerline/bindings/pdb/__init__.py b/powerline/bindings/pdb/__init__.py new file mode 100644 index 00000000..8df3886e --- /dev/null +++ b/powerline/bindings/pdb/__init__.py @@ -0,0 +1,54 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +from powerline.pdb import PDBPowerline +from powerline.lib.encoding import get_preferred_output_encoding + + +def use_powerline_prompt(cls): + '''Decorator that installs powerline prompt to the class + + :param pdb.Pdb cls: + Class that should be decorated. + + :return: + ``cls`` argument or a class derived from it. Latter is used to turn + old-style classes into new-style classes. + ''' + encoding = get_preferred_output_encoding() + + @property + def prompt(self): + try: + powerline = self.powerline + except AttributeError: + powerline = PDBPowerline() + powerline.setup(self) + self.powerline = powerline + ret = powerline.render(side='left') + if not isinstance(ret, str): + # Python-2 + ret = ret.encode(encoding) + return ret + + @prompt.setter + def prompt(self, _): + pass + + @prompt.deleter + def prompt(self): + pass + + if not hasattr(cls, '__class__'): + # Old-style class: make it new-style or @property will not work. + old_cls = cls + + class cls(cls, object): + __module__ = cls.__module__ + __doc__ = cls.__doc__ + + cls.__name__ = old_cls.__name__ + + cls.prompt = prompt + + return cls diff --git a/powerline/bindings/pdb/__main__.py b/powerline/bindings/pdb/__main__.py new file mode 100755 index 00000000..78527500 --- /dev/null +++ b/powerline/bindings/pdb/__main__.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import pdb + +from powerline.bindings.pdb import use_powerline_prompt + + +def main(): + '''Run module as a script + + Uses :py:func:`pdb.main` function directly, but prior to that it mocks + :py:class:`pdb.Pdb` class with powerline-specific class instance. + ''' + orig_pdb = pdb.Pdb + + @use_powerline_prompt + class Pdb(pdb.Pdb, object): + def __init__(self): + orig_pdb.__init__(self) + + pdb.Pdb = Pdb + + return pdb.main() + + +if __name__ == '__main__': + main() diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index 9502129a..bd2cf2bb 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -12,6 +12,10 @@ "in2": "in2" } }, + "pdb": { + "colorscheme": "default", + "theme": "default" + }, "shell": { "colorscheme": "default", "theme": "default", diff --git a/powerline/config_files/themes/pdb/default.json b/powerline/config_files/themes/pdb/default.json new file mode 100644 index 00000000..55505f67 --- /dev/null +++ b/powerline/config_files/themes/pdb/default.json @@ -0,0 +1,21 @@ +{ + "segments": { + "left": [ + { + "function": "powerline.segments.common.env.virtualenv", + "priority": 10 + }, + { + "type": "string", + "contents": "In [", + "draw_soft_divider": false, + "highlight_groups": ["virtualenv"] + }, + { + "type": "string", + "contents": "]", + "highlight_groups": ["virtualenv"] + } + ] + } +} diff --git a/powerline/pdb.py b/powerline/pdb.py new file mode 100644 index 00000000..3a986dfb --- /dev/null +++ b/powerline/pdb.py @@ -0,0 +1,19 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +from powerline import Powerline + + +class PDBPowerline(Powerline): + '''PDB-specific powerline bindings + ''' + def init(self, **kwargs): + return super(PDBPowerline, self).init( + ext='pdb', + renderer_module='pdb', + **kwargs + ) + + def do_setup(self, pdb): + self.update_renderer() + self.renderer.set_pdb(pdb) diff --git a/powerline/renderers/pdb.py b/powerline/renderers/pdb.py new file mode 100644 index 00000000..d514e490 --- /dev/null +++ b/powerline/renderers/pdb.py @@ -0,0 +1,34 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +from powerline.renderers.shell.readline import ReadlineRenderer +from powerline.renderer import Renderer + + +class PDBRenderer(ReadlineRenderer): + '''PDB-specific powerline renderer + ''' + pdb = None + + def get_segment_info(self, segment_info, mode): + r = self.segment_info.copy() + r['pdb'] = self.pdb + return r + + def set_pdb(self, pdb): + '''Record currently used :py:class:`pdb.Pdb` instance + + Must be called before first calling :py:meth:`render` method. + + :param pdb.Pdb pdb: + Used :py:class:`pdb.Pdb` instance. This instance will later be used + by :py:meth:`get_segment_info` for patching :ref:`segment_info + ` dictionary. + ''' + self.pdb = pdb + + def render(self, **kwargs): + return Renderer.render(self, **kwargs) + + +renderer = PDBRenderer From b0d295301b36eb1b39736c924919676b263b1510 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 27 Jan 2015 22:38:50 +0300 Subject: [PATCH 05/21] Add some hacks to make code compatible with pdbpp --- powerline/bindings/pdb/__init__.py | 98 +++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 7 deletions(-) diff --git a/powerline/bindings/pdb/__init__.py b/powerline/bindings/pdb/__init__.py index 8df3886e..34040751 100644 --- a/powerline/bindings/pdb/__init__.py +++ b/powerline/bindings/pdb/__init__.py @@ -1,8 +1,98 @@ # vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) +import sys + from powerline.pdb import PDBPowerline from powerline.lib.encoding import get_preferred_output_encoding +from powerline.lib.unicode import unicode + + +if sys.version_info < (3,): + # XXX The below classes make code compatible with PDBpp which uses pyrepl + # which does not expect unicode or something above ASCII. They are + # completely not needed if pdbpp is not used, but that’s not always the + # case. + class PowerlineRenderBytesResult(bytes): + def __new__(cls, s, encoding=None): + encoding = encoding or s.encoding + self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s) + self.encoding = encoding + return self + + for meth in ( + '__contains__', + 'partition', 'rpartition', + 'split', 'rsplit', + 'count', 'join', + ): + exec(( + 'def {0}(self, *args):\n' + ' if any((isinstance(arg, unicode) for arg in args)):\n' + ' return self.__unicode__().{0}(*args)\n' + ' else:\n' + ' return bytes.{0}(self, *args)' + ).format(meth)) + + for meth in ( + 'find', 'rfind', + 'index', 'rindex', + ): + exec(( + 'def {0}(self, *args):\n' + ' if any((isinstance(arg, unicode) for arg in args)):\n' + ' args = [arg.encode(self.encoding) if isinstance(arg, unicode) else arg for arg in args]\n' + ' return bytes.{0}(self, *args)' + ).format(meth)) + + def __len__(self): + return len(self.decode(self.encoding)) + + def __getitem__(self, *args): + return PowerlineRenderBytesResult(bytes.__getitem__(self, *args), encoding=self.encoding) + + def __getslice__(self, *args): + return PowerlineRenderBytesResult(bytes.__getslice__(self, *args), encoding=self.encoding) + + @staticmethod + def add(encoding, *args): + if any((isinstance(arg, unicode) for arg in args)): + return ''.join(( + arg + if isinstance(arg, unicode) + else arg.decode(encoding) + for arg in args + )) + else: + return PowerlineRenderBytesResult(b''.join(args), encoding=encoding) + + def __add__(self, other): + return self.add(self.encoding, self, other) + + def __radd__(self, other): + return self.add(self.encoding, other, self) + + def __unicode__(self): + return PowerlineRenderResult(self) + + class PowerlineRenderResult(unicode): + def __new__(cls, s, encoding=None): + encoding = ( + encoding + or getattr(s, 'encoding', None) + or get_preferred_output_encoding() + ) + if isinstance(s, unicode): + self = unicode.__new__(cls, s) + else: + self = unicode.__new__(cls, s, encoding, 'replace') + self.encoding = encoding + return self + + def __str__(self): + return PowerlineRenderBytesResult(self) +else: + PowerlineRenderResult = str def use_powerline_prompt(cls): @@ -15,8 +105,6 @@ def use_powerline_prompt(cls): ``cls`` argument or a class derived from it. Latter is used to turn old-style classes into new-style classes. ''' - encoding = get_preferred_output_encoding() - @property def prompt(self): try: @@ -25,11 +113,7 @@ def use_powerline_prompt(cls): powerline = PDBPowerline() powerline.setup(self) self.powerline = powerline - ret = powerline.render(side='left') - if not isinstance(ret, str): - # Python-2 - ret = ret.encode(encoding) - return ret + return PowerlineRenderResult(powerline.render(side='left')) @prompt.setter def prompt(self, _): From cac9754fcfeb5728354d260665c7f9205d61fa0c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 13:43:24 +0300 Subject: [PATCH 06/21] Add pdb-specific segments and make default theme use them --- docs/source/configuration/listers.rst | 6 ++ docs/source/configuration/segments/pdb.rst | 7 +++ docs/source/develop/segments.rst | 9 +++ .../colorschemes/pdb/__main__.json | 5 ++ .../colorschemes/pdb/default.json | 8 +++ .../config_files/themes/pdb/default.json | 28 +++++---- powerline/listers/pdb.py | 37 +++++++++++ powerline/renderers/pdb.py | 5 ++ powerline/segments/pdb.py | 61 +++++++++++++++++++ 9 files changed, 155 insertions(+), 11 deletions(-) create mode 100644 docs/source/configuration/segments/pdb.rst create mode 100644 powerline/config_files/colorschemes/pdb/__main__.json create mode 100644 powerline/config_files/colorschemes/pdb/default.json create mode 100644 powerline/listers/pdb.py create mode 100644 powerline/segments/pdb.py diff --git a/docs/source/configuration/listers.rst b/docs/source/configuration/listers.rst index dc544b91..04e5371e 100644 --- a/docs/source/configuration/listers.rst +++ b/docs/source/configuration/listers.rst @@ -23,3 +23,9 @@ Vim listers .. automodule:: powerline.listers.vim :members: + +Pdb listers +----------- + +.. automodule:: powerline.listers.pdb + :members: diff --git a/docs/source/configuration/segments/pdb.rst b/docs/source/configuration/segments/pdb.rst new file mode 100644 index 00000000..b9a104b2 --- /dev/null +++ b/docs/source/configuration/segments/pdb.rst @@ -0,0 +1,7 @@ +************ +PDB segments +************ + +.. automodule:: powerline.segments.pdb + :members: + diff --git a/docs/source/develop/segments.rst b/docs/source/develop/segments.rst index a16f067d..3fea00a2 100644 --- a/docs/source/develop/segments.rst +++ b/docs/source/develop/segments.rst @@ -475,6 +475,15 @@ Pdb ``pdb`` Currently active :py:class:`pdb.Pdb` instance. +``curframe`` + Frame which will be run next. Note: due to the existence of + :py:func:`powerline.listers.pdb.frame_lister` one must not use + ``segment_info['pdb'].curframe``. + +``initial_stack_length`` + Equal to the length of :py:attr:`pdb.Pdb.stack` at the first invocation of + the prompt decremented by one. + Segment class ============= diff --git a/powerline/config_files/colorschemes/pdb/__main__.json b/powerline/config_files/colorschemes/pdb/__main__.json new file mode 100644 index 00000000..b7ce28f0 --- /dev/null +++ b/powerline/config_files/colorschemes/pdb/__main__.json @@ -0,0 +1,5 @@ +{ + "groups": { + "current_context": "current_code_name" + } +} diff --git a/powerline/config_files/colorschemes/pdb/default.json b/powerline/config_files/colorschemes/pdb/default.json new file mode 100644 index 00000000..56f9020f --- /dev/null +++ b/powerline/config_files/colorschemes/pdb/default.json @@ -0,0 +1,8 @@ +{ + "groups": { + "current_line": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] }, + "current_file": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] }, + "current_code_name": { "fg": "gray9", "bg": "gray4", "attrs": ["bold"] }, + "stack_depth": { "fg": "gray1", "bg": "gray10", "attrs": ["bold"] } + } +} diff --git a/powerline/config_files/themes/pdb/default.json b/powerline/config_files/themes/pdb/default.json index 55505f67..dcae1080 100644 --- a/powerline/config_files/themes/pdb/default.json +++ b/powerline/config_files/themes/pdb/default.json @@ -1,20 +1,26 @@ { + "default_module": "powerline.segments.pdb", "segments": { "left": [ { - "function": "powerline.segments.common.env.virtualenv", - "priority": 10 + "function": "stack_depth" }, { - "type": "string", - "contents": "In [", - "draw_soft_divider": false, - "highlight_groups": ["virtualenv"] - }, - { - "type": "string", - "contents": "]", - "highlight_groups": ["virtualenv"] + "type": "segment_list", + "function": "powerline.listers.pdb.frame_lister", + "segments": [ + { + "function": "current_file", + "after": ":" + }, + { + "function": "current_line", + "after": " " + }, + { + "function": "current_code_name" + } + ] } ] } diff --git a/powerline/listers/pdb.py b/powerline/listers/pdb.py new file mode 100644 index 00000000..24e11eaf --- /dev/null +++ b/powerline/listers/pdb.py @@ -0,0 +1,37 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +from powerline.theme import requires_segment_info + + +@requires_segment_info +def frame_lister(pl, segment_info, full_stack=False, maxframes=3): + '''List all frames in segment_info format + + :param bool full_stack: + If true, then all frames in the stack are listed. Normally N first + frames are discarded where N is a number of frames present at the first + invocation of the prompt minus one. + :param int maxframes: + Maximum number of frames to display. + ''' + if full_stack: + initial_stack_length = 0 + frames = segment_info['pdb'].stack + else: + initial_stack_length = segment_info['initial_stack_length'] + frames = segment_info['pdb'].stack[initial_stack_length:] + + if len(frames) > maxframes: + frames = frames[-maxframes:] + + return ( + ( + { + 'curframe': frame[0], + 'initial_stack_length': initial_stack_length, + }, + {} + ) + for frame in frames + ) diff --git a/powerline/renderers/pdb.py b/powerline/renderers/pdb.py index d514e490..828223a5 100644 --- a/powerline/renderers/pdb.py +++ b/powerline/renderers/pdb.py @@ -9,10 +9,13 @@ class PDBRenderer(ReadlineRenderer): '''PDB-specific powerline renderer ''' pdb = None + initial_stack_length = None def get_segment_info(self, segment_info, mode): r = self.segment_info.copy() r['pdb'] = self.pdb + r['initial_stack_length'] = self.initial_stack_length + r['curframe'] = self.pdb.curframe return r def set_pdb(self, pdb): @@ -28,6 +31,8 @@ class PDBRenderer(ReadlineRenderer): self.pdb = pdb def render(self, **kwargs): + if self.initial_stack_length is None: + self.initial_stack_length = len(self.pdb.stack) - 1 return Renderer.render(self, **kwargs) diff --git a/powerline/segments/pdb.py b/powerline/segments/pdb.py new file mode 100644 index 00000000..bd6a38b7 --- /dev/null +++ b/powerline/segments/pdb.py @@ -0,0 +1,61 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import os + +from powerline.theme import requires_segment_info + + +@requires_segment_info +def current_line(pl, segment_info): + '''Displays line number that is next to be run + ''' + return str(segment_info['curframe'].f_lineno) + + +@requires_segment_info +def current_file(pl, segment_info, basename=True): + '''Displays current file name + + :param bool basename: + If true only basename is displayed. + ''' + filename = segment_info['curframe'].f_code.co_filename + if basename: + filename = os.path.basename(filename) + return filename + + +@requires_segment_info +def current_code_name(pl, segment_info): + '''Displays name of the code object of the current frame + ''' + return segment_info['curframe'].f_code.co_name + + +@requires_segment_info +def current_context(pl, segment_info): + '''Displays currently executed context name + + This is similar to :py:func:`current_code_name`, but gives more details. + + Currently it only gives module file name if code_name happens to be + ````. + ''' + name = segment_info['curframe'].f_code.co_name + if name == '': + name = os.path.basename(segment_info['curframe'].f_code.co_filename) + return name + + +@requires_segment_info +def stack_depth(pl, segment_info, full_stack=False): + '''Displays current stack depth + + Result is relative to the stack depth at the time prompt was first run. + + :param bool full_stack: + If true then absolute depth is used. + ''' + return str(len(segment_info['pdb'].stack) - ( + 0 if full_stack else segment_info['initial_stack_length'])) From 47dbdd571ddd18d38dc91b843a2b116010761e3a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 17:58:14 +0300 Subject: [PATCH 07/21] Add pdb integration tests --- tests/test_shells/input.pdb | 94 +++++++++++++ tests/test_shells/pdb-main.py | 24 ++++ tests/test_shells/pdb-script.py | 38 ++++++ tests/test_shells/pdb.ok | 230 ++++++++++++++++++++++++++++++++ tests/test_shells/postproc.py | 16 ++- tests/test_shells/test.sh | 40 +++++- 6 files changed, 436 insertions(+), 6 deletions(-) create mode 100644 tests/test_shells/input.pdb create mode 100644 tests/test_shells/pdb-main.py create mode 100644 tests/test_shells/pdb-script.py create mode 100644 tests/test_shells/pdb.ok diff --git a/tests/test_shells/input.pdb b/tests/test_shells/input.pdb new file mode 100644 index 00000000..9b1aad49 --- /dev/null +++ b/tests/test_shells/input.pdb @@ -0,0 +1,94 @@ +s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_shells/pdb-main.py b/tests/test_shells/pdb-main.py new file mode 100644 index 00000000..37af785f --- /dev/null +++ b/tests/test_shells/pdb-main.py @@ -0,0 +1,24 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import pdb +import os +import sys + +from powerline.bindings.pdb import use_powerline_prompt + + +@use_powerline_prompt +class Pdb(pdb.Pdb): + pass + + +p = Pdb() + + +script = os.path.join(os.path.dirname(__file__), 'pdb-script.py') +with open(script, 'r') as fd: + code = compile(fd.read(), script, 'exec') + + +p.run('exec(code)', globals={'code': code}) diff --git a/tests/test_shells/pdb-script.py b/tests/test_shells/pdb-script.py new file mode 100644 index 00000000..40db5e8d --- /dev/null +++ b/tests/test_shells/pdb-script.py @@ -0,0 +1,38 @@ +# vim:fileencoding=utf-8:noet +def nop(_): + pass + + +class Foo(object): + def __init__(self): + nop('__init__') + self.bar() + self.baz() + self.bra() + + @classmethod + def bar(cls): + nop(cls.__name__) + + @staticmethod + def baz(): + nop(1) + + def bra(self): + nop(self.__class__.__name__) + + +def brah(): + nop('brah') + + +f = Foo() +Foo.bar() +Foo.baz() +Foo.bra(f) + +f.bar() +f.baz() +f.bra() + +brah() diff --git a/tests/test_shells/pdb.ok b/tests/test_shells/pdb.ok new file mode 100644 index 00000000..181ef636 --- /dev/null +++ b/tests/test_shells/pdb.ok @@ -0,0 +1,230 @@ +--Call-- +-> def nop(_): + 2  :1   pdb-script.py:2    +-> def nop(_): + 2  :1   pdb-script.py:2    +-> class Foo(object): + 2  :1   pdb-script.py:6    +--Call-- +-> class Foo(object): + 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   +-> class Foo(object): + 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   +-> def __init__(self): + 3  :1   pdb-script.py:6   pdb-script.py:7 Foo   +-> @classmethod + 3  :1   pdb-script.py:6   pdb-script.py:13 Foo   +-> @staticmethod + 3  :1   pdb-script.py:6   pdb-script.py:17 Foo   +-> def bra(self): + 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   +--Return-- +-> def bra(self): + 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   +-> def brah(): + 2  :1   pdb-script.py:25    +-> f = Foo() + 2  :1   pdb-script.py:29    +--Call-- +-> def __init__(self): + 3  :1   pdb-script.py:29   pdb-script.py:7 __init__   +-> nop('__init__') + 3  :1   pdb-script.py:29   pdb-script.py:8 __init__   +--Call-- +-> def nop(_): + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   +-> self.bar() + 3  :1   pdb-script.py:29   pdb-script.py:9 __init__   +--Call-- +-> @classmethod + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   +-> nop(cls.__name__) + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   +-> self.baz() + 3  :1   pdb-script.py:29   pdb-script.py:10 __init__   +--Call-- +-> @staticmethod + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   +-> nop(1) + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   +-> self.bra() + 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   +--Call-- +-> def bra(self): + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   +--Return-- +-> self.bra() + 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   +-> Foo.bar() + 2  :1   pdb-script.py:30    +--Call-- +-> @classmethod + 3  :1   pdb-script.py:30   pdb-script.py:13 bar   +-> nop(cls.__name__) + 3  :1   pdb-script.py:30   pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 3  :1   pdb-script.py:30   pdb-script.py:15 bar   +-> Foo.baz() + 2  :1   pdb-script.py:31    +--Call-- +-> @staticmethod + 3  :1   pdb-script.py:31   pdb-script.py:17 baz   +-> nop(1) + 3  :1   pdb-script.py:31   pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 3  :1   pdb-script.py:31   pdb-script.py:19 baz   +-> Foo.bra(f) + 2  :1   pdb-script.py:32    +--Call-- +-> def bra(self): + 3  :1   pdb-script.py:32   pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 3  :1   pdb-script.py:32   pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 3  :1   pdb-script.py:32   pdb-script.py:22 bra   +-> f.bar() + 2  :1   pdb-script.py:34    +--Call-- +-> @classmethod + 3  :1   pdb-script.py:34   pdb-script.py:13 bar   +-> nop(cls.__name__) + 3  :1   pdb-script.py:34   pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 3  :1   pdb-script.py:34   pdb-script.py:15 bar   +-> f.baz() + 2  :1   pdb-script.py:35    +--Call-- +-> @staticmethod + 3  :1   pdb-script.py:35   pdb-script.py:17 baz   +-> nop(1) + 3  :1   pdb-script.py:35   pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 3  :1   pdb-script.py:35   pdb-script.py:19 baz   +-> f.bra() + 2  :1   pdb-script.py:36    +--Call-- +-> def bra(self): + 3  :1   pdb-script.py:36   pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 3  :1   pdb-script.py:36   pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 3  :1   pdb-script.py:36   pdb-script.py:22 bra   +-> brah() + 2  :1   pdb-script.py:38    +--Call-- +-> def brah(): + 3  :1   pdb-script.py:38   pdb-script.py:25 brah   +-> nop('brah') + 3  :1   pdb-script.py:38   pdb-script.py:26 brah   +--Call-- +-> def nop(_): + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   +--Return-- +-> nop('brah') + 3  :1   pdb-script.py:38   pdb-script.py:26 brah   +--Return-- +-> brah() + 2  :1   pdb-script.py:38    +--Return-- + 1  :1    +-> self.quitting = True + 0   diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index ff9c5748..7b9d330e 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -34,9 +34,14 @@ IPYPY_DEANSI_RE = re.compile(r'\033(?:\[(?:\?\d+[lh]|[^a-zA-Z]+[a-ln-zA-Z])|[=>] with codecs.open(fname, 'r', encoding='utf-8') as R: with codecs.open(new_fname, 'w', encoding='utf-8') as W: found_cd = False + i = -1 for line in (R if shell != 'fish' else R.read().split('\n')): + i += 1 if not found_cd: - found_cd = ('cd tests/shell/3rd' in line) + if shell == 'pdb': + found_cd = (i > 1) + else: + found_cd = ('cd tests/shell/3rd' in line) continue if 'true is the last line' in line: break @@ -101,4 +106,13 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: elif shell == 'rc': if line == 'read() failed: Connection reset by peer\n': line = '' + elif shell == 'pdb': + if is_pypy: + if line == '\033[?1h\033=\033[?25l\033[1A\n': + line = '' + line = IPYPY_DEANSI_RE.subn('', line)[0] + if line.startswith(('>',)): + line = '' + elif line == '-> self.quitting = 1\n': + line = '-> self.quitting = True\n' W.write(line) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 81b5edb2..7f01e405 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -1,5 +1,7 @@ #!/bin/sh -set -e +. tests/bot-ci/scripts/common/main.sh +set +x + : ${PYTHON:=python} FAIL_SUMMARY="" FAILED=0 @@ -113,10 +115,18 @@ do_run_test() { sleep 0.1s done if ( \ - test "x${SH}" = "xdash" || - ( \ + test "x${SH}" = "xdash" \ + || ( \ test "x${SH}" = "xipython" \ - && ${PYTHON} -c 'import platform, sys; sys.exit(1 - (platform.python_implementation() == "PyPy"))' \ + && test "$PYTHON_IMPLEMENTATION" = "PyPy" \ + ) \ + || ( \ + test "x${SH}" = "xpdb" \ + && ( test "$PYTHON_VERSION_MAJOR" -eq 3 \ + && test "$PYTHON_VERSION_MINOR" -eq 2 \ + && test "$PYTHON_IMPLEMENTATION" = "CPython" \ + ) \ + || test "$PYTHON_IMPLEMENTATION" = "PyPy" ) \ ) ; then # If I do not use this hack for dash then output will look like @@ -126,7 +136,9 @@ do_run_test() { # … # prompt1> prompt2> … while read -r line ; do - screen -S "$SESNAME" -p 0 -X stuff "$line$NL" + if test "$(screen -S "$SESNAME" -p 0 -X stuff "$line$NL")" = "No screen session found." ; then + break + fi sleep 1 done < tests/test_shells/input.$SH else @@ -185,6 +197,9 @@ run_test() { TEST_CLIENT="$2" SH="$3" local attempts=3 + if test -n "$ONLY_SHELL$ONLY_TEST_TYPE$ONLY_TEST_CLIENT" ; then + attempts=1 + fi while test $attempts -gt 0 ; do rm -f tests/shell/${SH}.${TEST_TYPE}.${TEST_CLIENT}.log rm -f tests/shell/${SH}.${TEST_TYPE}.${TEST_CLIENT}.full.log @@ -256,6 +271,9 @@ for pexe in powerline powerline-config ; do fi done +ln -s python tests/shell/path/pdb +PDB_PYTHON=pdb + if test -z "$POWERLINE_RC_EXE" ; then if which rc-status >/dev/null ; then # On Gentoo `rc` executable is from OpenRC. Thus app-shells/rc instals @@ -418,6 +436,18 @@ if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xzsh" ) \ fi fi +if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ) \ + && ( test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xsubclass" ) +then + if ! ( test "$PYTHON_IMPLEMENTATION" = "PyPy" && test "$PYTHON_VERSION_MAJOR" = 2 ) ; then + echo "> pdb subclass" + if ! run_test pdb subclass $PDB_PYTHON "$PWD/tests/test_shells/pdb-main.py" ; then + FAILED=1 + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -m $PWD/tests/test_shells/pdb-main.py" + fi + fi +fi + if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xipython" ; then if which ipython >/dev/null ; then # Define some overrides which should be ignored by IPython. From ef02ab70fb27d45ac495bfc4a140c9a9857c2957 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:10:19 +0300 Subject: [PATCH 08/21] Also test powerline.bindings.pdb module --- tests/test_shells/input.pdb | 7 +- tests/test_shells/pdb.module.ok | 224 ++++++++++++++++++ tests/test_shells/{pdb.ok => pdb.subclass.ok} | 7 - tests/test_shells/test.sh | 24 +- 4 files changed, 241 insertions(+), 21 deletions(-) create mode 100644 tests/test_shells/pdb.module.ok rename tests/test_shells/{pdb.ok => pdb.subclass.ok} (98%) diff --git a/tests/test_shells/input.pdb b/tests/test_shells/input.pdb index 9b1aad49..e9ac498c 100644 --- a/tests/test_shells/input.pdb +++ b/tests/test_shells/input.pdb @@ -86,9 +86,4 @@ s - - - - - - + diff --git a/tests/test_shells/pdb.module.ok b/tests/test_shells/pdb.module.ok new file mode 100644 index 00000000..629d2993 --- /dev/null +++ b/tests/test_shells/pdb.module.ok @@ -0,0 +1,224 @@ + 1  pdb-script.py:2   s +-> class Foo(object): + 1  pdb-script.py:6    +--Call-- +-> class Foo(object): + 2  pdb-script.py:6   pdb-script.py:6 Foo   +-> class Foo(object): + 2  pdb-script.py:6   pdb-script.py:6 Foo   +-> def __init__(self): + 2  pdb-script.py:6   pdb-script.py:7 Foo   +-> @classmethod + 2  pdb-script.py:6   pdb-script.py:13 Foo   +-> @staticmethod + 2  pdb-script.py:6   pdb-script.py:17 Foo   +-> def bra(self): + 2  pdb-script.py:6   pdb-script.py:21 Foo   +--Return-- +-> def bra(self): + 2  pdb-script.py:6   pdb-script.py:21 Foo   +-> def brah(): + 1  pdb-script.py:25    +-> f = Foo() + 1  pdb-script.py:29    +--Call-- +-> def __init__(self): + 2  pdb-script.py:29   pdb-script.py:7 __init__   +-> nop('__init__') + 2  pdb-script.py:29   pdb-script.py:8 __init__   +--Call-- +-> def nop(_): + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   +-> self.bar() + 2  pdb-script.py:29   pdb-script.py:9 __init__   +--Call-- +-> @classmethod + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   +-> nop(cls.__name__) + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   +-> self.baz() + 2  pdb-script.py:29   pdb-script.py:10 __init__   +--Call-- +-> @staticmethod + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   +-> nop(1) + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   +-> self.bra() + 2  pdb-script.py:29   pdb-script.py:11 __init__   +--Call-- +-> def bra(self): + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   +--Return-- +-> self.bra() + 2  pdb-script.py:29   pdb-script.py:11 __init__   +-> Foo.bar() + 1  pdb-script.py:30    +--Call-- +-> @classmethod + 2  pdb-script.py:30   pdb-script.py:13 bar   +-> nop(cls.__name__) + 2  pdb-script.py:30   pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 2  pdb-script.py:30   pdb-script.py:15 bar   +-> Foo.baz() + 1  pdb-script.py:31    +--Call-- +-> @staticmethod + 2  pdb-script.py:31   pdb-script.py:17 baz   +-> nop(1) + 2  pdb-script.py:31   pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 2  pdb-script.py:31   pdb-script.py:19 baz   +-> Foo.bra(f) + 1  pdb-script.py:32    +--Call-- +-> def bra(self): + 2  pdb-script.py:32   pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 2  pdb-script.py:32   pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 2  pdb-script.py:32   pdb-script.py:22 bra   +-> f.bar() + 1  pdb-script.py:34    +--Call-- +-> @classmethod + 2  pdb-script.py:34   pdb-script.py:13 bar   +-> nop(cls.__name__) + 2  pdb-script.py:34   pdb-script.py:15 bar   +--Call-- +-> def nop(_): + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   +--Return-- +-> nop(cls.__name__) + 2  pdb-script.py:34   pdb-script.py:15 bar   +-> f.baz() + 1  pdb-script.py:35    +--Call-- +-> @staticmethod + 2  pdb-script.py:35   pdb-script.py:17 baz   +-> nop(1) + 2  pdb-script.py:35   pdb-script.py:19 baz   +--Call-- +-> def nop(_): + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   +--Return-- +-> nop(1) + 2  pdb-script.py:35   pdb-script.py:19 baz   +-> f.bra() + 1  pdb-script.py:36    +--Call-- +-> def bra(self): + 2  pdb-script.py:36   pdb-script.py:21 bra   +-> nop(self.__class__.__name__) + 2  pdb-script.py:36   pdb-script.py:22 bra   +--Call-- +-> def nop(_): + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   +--Return-- +-> nop(self.__class__.__name__) + 2  pdb-script.py:36   pdb-script.py:22 bra   +-> brah() + 1  pdb-script.py:38    +--Call-- +-> def brah(): + 2  pdb-script.py:38   pdb-script.py:25 brah   +-> nop('brah') + 2  pdb-script.py:38   pdb-script.py:26 brah   +--Call-- +-> def nop(_): + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   +-> pass + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   +--Return-- +-> pass + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   +--Return-- +-> nop('brah') + 2  pdb-script.py:38   pdb-script.py:26 brah   +--Return-- +-> brah() + 1  pdb-script.py:38    +--Return-- + 0   diff --git a/tests/test_shells/pdb.ok b/tests/test_shells/pdb.subclass.ok similarity index 98% rename from tests/test_shells/pdb.ok rename to tests/test_shells/pdb.subclass.ok index 181ef636..41bda2da 100644 --- a/tests/test_shells/pdb.ok +++ b/tests/test_shells/pdb.subclass.ok @@ -221,10 +221,3 @@ --Return-- -> nop('brah')  3  :1   pdb-script.py:38   pdb-script.py:26 brah   ---Return-- --> brah() - 2  :1   pdb-script.py:38    ---Return-- - 1  :1    --> self.quitting = True - 0   diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 7f01e405..830dcb0a 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -122,7 +122,8 @@ do_run_test() { ) \ || ( \ test "x${SH}" = "xpdb" \ - && ( test "$PYTHON_VERSION_MAJOR" -eq 3 \ + && ( \ + test "$PYTHON_VERSION_MAJOR" -eq 3 \ && test "$PYTHON_VERSION_MINOR" -eq 2 \ && test "$PYTHON_IMPLEMENTATION" = "CPython" \ ) \ @@ -436,14 +437,21 @@ if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xzsh" ) \ fi fi -if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ) \ - && ( test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xsubclass" ) -then +if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ; then if ! ( test "$PYTHON_IMPLEMENTATION" = "PyPy" && test "$PYTHON_VERSION_MAJOR" = 2 ) ; then - echo "> pdb subclass" - if ! run_test pdb subclass $PDB_PYTHON "$PWD/tests/test_shells/pdb-main.py" ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -m $PWD/tests/test_shells/pdb-main.py" + if test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xsubclass" ; then + echo "> pdb subclass" + if ! run_test subclass python $PDB_PYTHON "$PWD/tests/test_shells/pdb-main.py" ; then + FAILED=1 + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON $PWD/tests/test_shells/pdb-main.py" + fi + fi + if test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xmodule" ; then + echo "> pdb module" + if ! run_test module python $PDB_PYTHON -mpowerline.bindings.pdb "$PWD/tests/test_shells/pdb-script.py" ; then + FAILED=1 + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -mpowerline.bindings.pdb $PWD/tests/test_shells/pdb-script" + fi fi fi fi From deacb9ab0227abfd2cd32ae5da56ef42a1a9d05d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:21:20 +0300 Subject: [PATCH 09/21] Add some methods to PowerlineRenderResult This is an attempt to fix PDB prompt on PyPy. Does not work. --- powerline/bindings/pdb/__init__.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/powerline/bindings/pdb/__init__.py b/powerline/bindings/pdb/__init__.py index 34040751..48b8a606 100644 --- a/powerline/bindings/pdb/__init__.py +++ b/powerline/bindings/pdb/__init__.py @@ -16,6 +16,8 @@ if sys.version_info < (3,): class PowerlineRenderBytesResult(bytes): def __new__(cls, s, encoding=None): encoding = encoding or s.encoding + if isinstance(s, PowerlineRenderResult): + return s.encode(encoding) self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s) self.encoding = encoding return self @@ -57,12 +59,12 @@ if sys.version_info < (3,): @staticmethod def add(encoding, *args): if any((isinstance(arg, unicode) for arg in args)): - return ''.join(( + return PowerlineRenderResult(''.join(( arg if isinstance(arg, unicode) else arg.decode(encoding) for arg in args - )) + )), encoding) else: return PowerlineRenderBytesResult(b''.join(args), encoding=encoding) @@ -91,6 +93,30 @@ if sys.version_info < (3,): def __str__(self): return PowerlineRenderBytesResult(self) + + def __getitem__(self, *args): + return PowerlineRenderResult(unicode.__getitem__(self, *args)) + + def __getslice__(self, *args): + return PowerlineRenderResult(unicode.__getslice__(self, *args)) + + @staticmethod + def add(encoding, *args): + return PowerlineRenderResult(''.join(( + arg + if isinstance(arg, unicode) + else arg.decode(encoding) + for arg in args + )), encoding) + + def __add__(self, other): + return self.add(self.encoding, self, other) + + def __radd__(self, other): + return self.add(self.encoding, other, self) + + def encode(self, *args, **kwargs): + return PowerlineRenderBytesResult(unicode.encode(self, *args, **kwargs), args[0]) else: PowerlineRenderResult = str From 682a9ab5040e964c6a3aae72f7aac96901770872 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:21:33 +0300 Subject: [PATCH 10/21] Warn that PyPy is not supported --- docs/source/usage/other.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/usage/other.rst b/docs/source/usage/other.rst index 69144777..30f0ad02 100644 --- a/docs/source/usage/other.rst +++ b/docs/source/usage/other.rst @@ -151,3 +151,5 @@ class from :py:class:`pdb.Pdb` and decorate it with python -mpowerline.bindings.pdb path/to/script.py just like you used ``python -m pdb``. + +.. warning: PyPy is not supported, PyPy3 is. From 27291b5e0ea2aa7fb0f8c56f9e2e795b67f909e6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:30:26 +0300 Subject: [PATCH 11/21] Force ASCII-only prompt when using PyPy --- docs/source/usage/other.rst | 5 ++++- powerline/pdb.py | 6 ++++++ powerline/renderers/pdb.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/source/usage/other.rst b/docs/source/usage/other.rst index 30f0ad02..2e7d334d 100644 --- a/docs/source/usage/other.rst +++ b/docs/source/usage/other.rst @@ -152,4 +152,7 @@ class from :py:class:`pdb.Pdb` and decorate it with just like you used ``python -m pdb``. -.. warning: PyPy is not supported, PyPy3 is. +.. warning: + Using PyPy (not PyPy3) forces ASCII-only prompts. In other cases unicode + characters are allowed, even if you use `pdbpp + `_. diff --git a/powerline/pdb.py b/powerline/pdb.py index 3a986dfb..79915818 100644 --- a/powerline/pdb.py +++ b/powerline/pdb.py @@ -1,6 +1,9 @@ # vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) +import sys +import platform + from powerline import Powerline @@ -17,3 +20,6 @@ class PDBPowerline(Powerline): def do_setup(self, pdb): self.update_renderer() self.renderer.set_pdb(pdb) + + if sys.version_info < (3,) and platform.python_implementation() == 'PyPy': + get_encoding = staticmethod(lambda: 'ascii') diff --git a/powerline/renderers/pdb.py b/powerline/renderers/pdb.py index 828223a5..040f0e1a 100644 --- a/powerline/renderers/pdb.py +++ b/powerline/renderers/pdb.py @@ -1,6 +1,9 @@ # vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) +import sys +import platform + from powerline.renderers.shell.readline import ReadlineRenderer from powerline.renderer import Renderer @@ -35,5 +38,13 @@ class PDBRenderer(ReadlineRenderer): self.initial_stack_length = len(self.pdb.stack) - 1 return Renderer.render(self, **kwargs) + if sys.version_info < (3,) and platform.python_implementation() == 'PyPy': + def do_render(self, **kwargs): + # Make sure that only ASCII characters survive + ret = super(PDBRenderer, self).do_render(**kwargs) + ret = ret.encode('ascii', 'replace') + ret = ret.decode('ascii') + return ret + renderer = PDBRenderer From f74320fba81d0388cf41a9781353b1ddd85f18eb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:41:17 +0300 Subject: [PATCH 12/21] Add unit tests for pdb segments --- tests/test_segments.py | 48 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/test_segments.py b/tests/test_segments.py index 73e4bb91..08fc520b 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -7,7 +7,7 @@ import os from functools import partial from collections import namedtuple -from powerline.segments import shell, tmux +from powerline.segments import shell, tmux, pdb from powerline.lib.vcs import get_fallback_create_watcher from powerline.lib.unicode import out_u @@ -1308,6 +1308,52 @@ class TestVim(TestCase): sys.path.pop(0) +class TestPDB(TestCase): + def test_current_line(self): + pl = Pl() + self.assertEqual(pdb.current_line(pl=pl, segment_info={'curframe': Args(f_lineno=10)}), '10') + + def test_current_file(self): + pl = Pl() + cf = lambda **kwargs: pdb.current_file( + pl=pl, + segment_info={'curframe': Args(f_code=Args(co_filename='/tmp/abc.py'))}, + **kwargs + ) + self.assertEqual(cf(), 'abc.py') + self.assertEqual(cf(basename=True), 'abc.py') + self.assertEqual(cf(basename=False), '/tmp/abc.py') + + def test_current_code_name(self): + pl = Pl() + ccn = lambda **kwargs: pdb.current_code_name( + pl=pl, + segment_info={'curframe': Args(f_code=Args(co_name=''))}, + **kwargs + ) + self.assertEqual(ccn(), '') + + def test_current_context(self): + pl = Pl() + cc = lambda **kwargs: pdb.current_context( + pl=pl, + segment_info={'curframe': Args(f_code=Args(co_name='', co_filename='/tmp/abc.py'))}, + **kwargs + ) + self.assertEqual(cc(), 'abc.py') + + def test_stack_depth(self): + pl = Pl() + sd = lambda **kwargs: pdb.stack_depth( + pl=pl, + segment_info={'pdb': Args(stack=[1, 2, 3]), 'initial_stack_length': 1}, + **kwargs + ) + self.assertEqual(sd(), '2') + self.assertEqual(sd(full_stack=False), '2') + self.assertEqual(sd(full_stack=True), '3') + + old_cwd = None From 5bc68b66fe8b830c0f775fbd15d81d1d1e4f6206 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 18:49:41 +0300 Subject: [PATCH 13/21] Define all groups in both default and solarized colorschemes --- powerline/config_files/colorschemes/pdb/__main__.json | 5 ++++- powerline/config_files/colorschemes/pdb/default.json | 5 +---- powerline/config_files/colorschemes/pdb/solarized.json | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 powerline/config_files/colorschemes/pdb/solarized.json diff --git a/powerline/config_files/colorschemes/pdb/__main__.json b/powerline/config_files/colorschemes/pdb/__main__.json index b7ce28f0..01a51fe5 100644 --- a/powerline/config_files/colorschemes/pdb/__main__.json +++ b/powerline/config_files/colorschemes/pdb/__main__.json @@ -1,5 +1,8 @@ { "groups": { - "current_context": "current_code_name" + "current_code_name": "information:additional", + "current_context": "current_code_name", + "current_line": "information:regular", + "current_file": "information:regular" } } diff --git a/powerline/config_files/colorschemes/pdb/default.json b/powerline/config_files/colorschemes/pdb/default.json index 56f9020f..b97acf7f 100644 --- a/powerline/config_files/colorschemes/pdb/default.json +++ b/powerline/config_files/colorschemes/pdb/default.json @@ -1,8 +1,5 @@ { "groups": { - "current_line": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] }, - "current_file": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] }, - "current_code_name": { "fg": "gray9", "bg": "gray4", "attrs": ["bold"] }, - "stack_depth": { "fg": "gray1", "bg": "gray10", "attrs": ["bold"] } + "stack_depth": { "fg": "gray1", "bg": "gray10", "attrs": ["bold"] } } } diff --git a/powerline/config_files/colorschemes/pdb/solarized.json b/powerline/config_files/colorschemes/pdb/solarized.json new file mode 100644 index 00000000..2e1c787c --- /dev/null +++ b/powerline/config_files/colorschemes/pdb/solarized.json @@ -0,0 +1,5 @@ +{ + "groups": { + "stack_depth": { "fg": "solarized:base03", "bg": "solarized:base2", "attrs": ["bold"] } + } +} From 2ef5107628956b0433537e8fdb3534d88f91f0f4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 20:23:10 +0300 Subject: [PATCH 14/21] Import overrides from environment in PDB prompts --- docs/source/configuration/local.rst | 6 + docs/source/usage/other.rst | 2 + powerline/pdb.py | 23 ++++ tests/test_shells/pdb.module.ok | 176 ++++++++++++++-------------- tests/test_shells/pdb.subclass.ok | 176 ++++++++++++++-------------- 5 files changed, 207 insertions(+), 176 deletions(-) diff --git a/docs/source/configuration/local.rst b/docs/source/configuration/local.rst index 3eec3ee0..5ea233f4 100644 --- a/docs/source/configuration/local.rst +++ b/docs/source/configuration/local.rst @@ -239,3 +239,9 @@ In order to keep shell prompt, but avoid launching Python twice to get unused In order to remove additional space from the end of the right prompt in fish that was added in order to support multiline prompt ``$POWERLINE_NO_FISH_ABOVE`` or ``$POWERLINE_NO_SHELL_ABOVE`` variable should be set. + +PDB overrides +============= + +Like shell bindings :ref:`PDB bindings ` take overrides from +:ref:`environment variables `. diff --git a/docs/source/usage/other.rst b/docs/source/usage/other.rst index 2e7d334d..108ec3ed 100644 --- a/docs/source/usage/other.rst +++ b/docs/source/usage/other.rst @@ -125,6 +125,8 @@ the used profile: IPython=0.11* is not supported and does not work. IPython<0.10 was not tested (not installable by pip). +.. _pdb-prompt: + PDB prompt ========== diff --git a/powerline/pdb.py b/powerline/pdb.py index 79915818..b1e13cea 100644 --- a/powerline/pdb.py +++ b/powerline/pdb.py @@ -3,8 +3,11 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct import sys import platform +import os from powerline import Powerline +from powerline.lib.overrides import parse_override_var +from powerline.lib.dict import mergeargs, mergedicts class PDBPowerline(Powerline): @@ -21,5 +24,25 @@ class PDBPowerline(Powerline): self.update_renderer() self.renderer.set_pdb(pdb) + def load_main_config(self): + r = super(PDBPowerline, self).load_main_config() + config_overrides = os.environ.get('POWERLINE_CONFIG_OVERRIDES') + if config_overrides: + mergedicts(r, mergeargs(parse_override_var(config_overrides))) + return r + + def load_theme_config(self, name): + r = super(PDBPowerline, self).load_theme_config(name) + theme_overrides = os.environ.get('POWERLINE_THEME_OVERRIDES') + if theme_overrides: + theme_overrides_dict = mergeargs(parse_override_var(theme_overrides)) + if name in theme_overrides_dict: + mergedicts(r, theme_overrides_dict[name]) + return r + + def get_config_paths(self): + paths = [path for path in os.environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path] + return paths or super(PDBPowerline, self).get_config_paths() + if sys.version_info < (3,) and platform.python_implementation() == 'PyPy': get_encoding = staticmethod(lambda: 'ascii') diff --git a/tests/test_shells/pdb.module.ok b/tests/test_shells/pdb.module.ok index 629d2993..1001dc42 100644 --- a/tests/test_shells/pdb.module.ok +++ b/tests/test_shells/pdb.module.ok @@ -1,224 +1,224 @@ - 1  pdb-script.py:2   s + 1  pdb-script.py:2   s -> class Foo(object): - 1  pdb-script.py:6    + 1  pdb-script.py:6    --Call-- -> class Foo(object): - 2  pdb-script.py:6   pdb-script.py:6 Foo   + 2  pdb-script.py:6   pdb-script.py:6 Foo   -> class Foo(object): - 2  pdb-script.py:6   pdb-script.py:6 Foo   + 2  pdb-script.py:6   pdb-script.py:6 Foo   -> def __init__(self): - 2  pdb-script.py:6   pdb-script.py:7 Foo   + 2  pdb-script.py:6   pdb-script.py:7 Foo   -> @classmethod - 2  pdb-script.py:6   pdb-script.py:13 Foo   + 2  pdb-script.py:6   pdb-script.py:13 Foo   -> @staticmethod - 2  pdb-script.py:6   pdb-script.py:17 Foo   + 2  pdb-script.py:6   pdb-script.py:17 Foo   -> def bra(self): - 2  pdb-script.py:6   pdb-script.py:21 Foo   + 2  pdb-script.py:6   pdb-script.py:21 Foo   --Return-- -> def bra(self): - 2  pdb-script.py:6   pdb-script.py:21 Foo   + 2  pdb-script.py:6   pdb-script.py:21 Foo   -> def brah(): - 1  pdb-script.py:25    + 1  pdb-script.py:25    -> f = Foo() - 1  pdb-script.py:29    + 1  pdb-script.py:29    --Call-- -> def __init__(self): - 2  pdb-script.py:29   pdb-script.py:7 __init__   + 2  pdb-script.py:29   pdb-script.py:7 __init__   -> nop('__init__') - 2  pdb-script.py:29   pdb-script.py:8 __init__   + 2  pdb-script.py:29   pdb-script.py:8 __init__   --Call-- -> def nop(_): - 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   + 3  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   -> self.bar() - 2  pdb-script.py:29   pdb-script.py:9 __init__   + 2  pdb-script.py:29   pdb-script.py:9 __init__   --Call-- -> @classmethod - 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   -> nop(cls.__name__) - 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   --Call-- -> def nop(_): - 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   + 3  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   -> self.baz() - 2  pdb-script.py:29   pdb-script.py:10 __init__   + 2  pdb-script.py:29   pdb-script.py:10 __init__   --Call-- -> @staticmethod - 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   -> nop(1) - 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   --Call-- -> def nop(_): - 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   + 3  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   -> self.bra() - 2  pdb-script.py:29   pdb-script.py:11 __init__   + 2  pdb-script.py:29   pdb-script.py:11 __init__   --Call-- -> def bra(self): - 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   --Call-- -> def nop(_): - 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   + 3  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   --Return-- -> self.bra() - 2  pdb-script.py:29   pdb-script.py:11 __init__   + 2  pdb-script.py:29   pdb-script.py:11 __init__   -> Foo.bar() - 1  pdb-script.py:30    + 1  pdb-script.py:30    --Call-- -> @classmethod - 2  pdb-script.py:30   pdb-script.py:13 bar   + 2  pdb-script.py:30   pdb-script.py:13 bar   -> nop(cls.__name__) - 2  pdb-script.py:30   pdb-script.py:15 bar   + 2  pdb-script.py:30   pdb-script.py:15 bar   --Call-- -> def nop(_): - 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   + 3  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 2  pdb-script.py:30   pdb-script.py:15 bar   + 2  pdb-script.py:30   pdb-script.py:15 bar   -> Foo.baz() - 1  pdb-script.py:31    + 1  pdb-script.py:31    --Call-- -> @staticmethod - 2  pdb-script.py:31   pdb-script.py:17 baz   + 2  pdb-script.py:31   pdb-script.py:17 baz   -> nop(1) - 2  pdb-script.py:31   pdb-script.py:19 baz   + 2  pdb-script.py:31   pdb-script.py:19 baz   --Call-- -> def nop(_): - 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   + 3  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 2  pdb-script.py:31   pdb-script.py:19 baz   + 2  pdb-script.py:31   pdb-script.py:19 baz   -> Foo.bra(f) - 1  pdb-script.py:32    + 1  pdb-script.py:32    --Call-- -> def bra(self): - 2  pdb-script.py:32   pdb-script.py:21 bra   + 2  pdb-script.py:32   pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 2  pdb-script.py:32   pdb-script.py:22 bra   + 2  pdb-script.py:32   pdb-script.py:22 bra   --Call-- -> def nop(_): - 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   + 3  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 2  pdb-script.py:32   pdb-script.py:22 bra   + 2  pdb-script.py:32   pdb-script.py:22 bra   -> f.bar() - 1  pdb-script.py:34    + 1  pdb-script.py:34    --Call-- -> @classmethod - 2  pdb-script.py:34   pdb-script.py:13 bar   + 2  pdb-script.py:34   pdb-script.py:13 bar   -> nop(cls.__name__) - 2  pdb-script.py:34   pdb-script.py:15 bar   + 2  pdb-script.py:34   pdb-script.py:15 bar   --Call-- -> def nop(_): - 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   + 3  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 2  pdb-script.py:34   pdb-script.py:15 bar   + 2  pdb-script.py:34   pdb-script.py:15 bar   -> f.baz() - 1  pdb-script.py:35    + 1  pdb-script.py:35    --Call-- -> @staticmethod - 2  pdb-script.py:35   pdb-script.py:17 baz   + 2  pdb-script.py:35   pdb-script.py:17 baz   -> nop(1) - 2  pdb-script.py:35   pdb-script.py:19 baz   + 2  pdb-script.py:35   pdb-script.py:19 baz   --Call-- -> def nop(_): - 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   + 3  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 2  pdb-script.py:35   pdb-script.py:19 baz   + 2  pdb-script.py:35   pdb-script.py:19 baz   -> f.bra() - 1  pdb-script.py:36    + 1  pdb-script.py:36    --Call-- -> def bra(self): - 2  pdb-script.py:36   pdb-script.py:21 bra   + 2  pdb-script.py:36   pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 2  pdb-script.py:36   pdb-script.py:22 bra   + 2  pdb-script.py:36   pdb-script.py:22 bra   --Call-- -> def nop(_): - 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   + 3  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 2  pdb-script.py:36   pdb-script.py:22 bra   + 2  pdb-script.py:36   pdb-script.py:22 bra   -> brah() - 1  pdb-script.py:38    + 1  pdb-script.py:38    --Call-- -> def brah(): - 2  pdb-script.py:38   pdb-script.py:25 brah   + 2  pdb-script.py:38   pdb-script.py:25 brah   -> nop('brah') - 2  pdb-script.py:38   pdb-script.py:26 brah   + 2  pdb-script.py:38   pdb-script.py:26 brah   --Call-- -> def nop(_): - 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   -> pass - 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   --Return-- -> pass - 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   + 3  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   --Return-- -> nop('brah') - 2  pdb-script.py:38   pdb-script.py:26 brah   + 2  pdb-script.py:38   pdb-script.py:26 brah   --Return-- -> brah() - 1  pdb-script.py:38    + 1  pdb-script.py:38    --Return--  0   diff --git a/tests/test_shells/pdb.subclass.ok b/tests/test_shells/pdb.subclass.ok index 41bda2da..b6f024fd 100644 --- a/tests/test_shells/pdb.subclass.ok +++ b/tests/test_shells/pdb.subclass.ok @@ -1,223 +1,223 @@ --Call-- -> def nop(_): - 2  :1   pdb-script.py:2    + 2  :1   pdb-script.py:2    -> def nop(_): - 2  :1   pdb-script.py:2    + 2  :1   pdb-script.py:2    -> class Foo(object): - 2  :1   pdb-script.py:6    + 2  :1   pdb-script.py:6    --Call-- -> class Foo(object): - 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   -> class Foo(object): - 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:6 Foo   -> def __init__(self): - 3  :1   pdb-script.py:6   pdb-script.py:7 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:7 Foo   -> @classmethod - 3  :1   pdb-script.py:6   pdb-script.py:13 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:13 Foo   -> @staticmethod - 3  :1   pdb-script.py:6   pdb-script.py:17 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:17 Foo   -> def bra(self): - 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   --Return-- -> def bra(self): - 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   + 3  :1   pdb-script.py:6   pdb-script.py:21 Foo   -> def brah(): - 2  :1   pdb-script.py:25    + 2  :1   pdb-script.py:25    -> f = Foo() - 2  :1   pdb-script.py:29    + 2  :1   pdb-script.py:29    --Call-- -> def __init__(self): - 3  :1   pdb-script.py:29   pdb-script.py:7 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:7 __init__   -> nop('__init__') - 3  :1   pdb-script.py:29   pdb-script.py:8 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:8 __init__   --Call-- -> def nop(_): - 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   + 4  pdb-script.py:29   pdb-script.py:8 __init__  pdb-script.py:3 nop   -> self.bar() - 3  :1   pdb-script.py:29   pdb-script.py:9 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:9 __init__   --Call-- -> @classmethod - 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:13 bar   -> nop(cls.__name__) - 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   --Call-- -> def nop(_): - 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   + 5  pdb-script.py:9 __init__  pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   + 4  pdb-script.py:29   pdb-script.py:9 __init__  pdb-script.py:15 bar   -> self.baz() - 3  :1   pdb-script.py:29   pdb-script.py:10 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:10 __init__   --Call-- -> @staticmethod - 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:17 baz   -> nop(1) - 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   --Call-- -> def nop(_): - 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   + 5  pdb-script.py:10 __init__  pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   + 4  pdb-script.py:29   pdb-script.py:10 __init__  pdb-script.py:19 baz   -> self.bra() - 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   --Call-- -> def bra(self): - 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   --Call-- -> def nop(_): - 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   + 5  pdb-script.py:11 __init__  pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   + 4  pdb-script.py:29   pdb-script.py:11 __init__  pdb-script.py:22 bra   --Return-- -> self.bra() - 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   + 3  :1   pdb-script.py:29   pdb-script.py:11 __init__   -> Foo.bar() - 2  :1   pdb-script.py:30    + 2  :1   pdb-script.py:30    --Call-- -> @classmethod - 3  :1   pdb-script.py:30   pdb-script.py:13 bar   + 3  :1   pdb-script.py:30   pdb-script.py:13 bar   -> nop(cls.__name__) - 3  :1   pdb-script.py:30   pdb-script.py:15 bar   + 3  :1   pdb-script.py:30   pdb-script.py:15 bar   --Call-- -> def nop(_): - 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:30   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 3  :1   pdb-script.py:30   pdb-script.py:15 bar   + 3  :1   pdb-script.py:30   pdb-script.py:15 bar   -> Foo.baz() - 2  :1   pdb-script.py:31    + 2  :1   pdb-script.py:31    --Call-- -> @staticmethod - 3  :1   pdb-script.py:31   pdb-script.py:17 baz   + 3  :1   pdb-script.py:31   pdb-script.py:17 baz   -> nop(1) - 3  :1   pdb-script.py:31   pdb-script.py:19 baz   + 3  :1   pdb-script.py:31   pdb-script.py:19 baz   --Call-- -> def nop(_): - 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:31   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 3  :1   pdb-script.py:31   pdb-script.py:19 baz   + 3  :1   pdb-script.py:31   pdb-script.py:19 baz   -> Foo.bra(f) - 2  :1   pdb-script.py:32    + 2  :1   pdb-script.py:32    --Call-- -> def bra(self): - 3  :1   pdb-script.py:32   pdb-script.py:21 bra   + 3  :1   pdb-script.py:32   pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 3  :1   pdb-script.py:32   pdb-script.py:22 bra   + 3  :1   pdb-script.py:32   pdb-script.py:22 bra   --Call-- -> def nop(_): - 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:32   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 3  :1   pdb-script.py:32   pdb-script.py:22 bra   + 3  :1   pdb-script.py:32   pdb-script.py:22 bra   -> f.bar() - 2  :1   pdb-script.py:34    + 2  :1   pdb-script.py:34    --Call-- -> @classmethod - 3  :1   pdb-script.py:34   pdb-script.py:13 bar   + 3  :1   pdb-script.py:34   pdb-script.py:13 bar   -> nop(cls.__name__) - 3  :1   pdb-script.py:34   pdb-script.py:15 bar   + 3  :1   pdb-script.py:34   pdb-script.py:15 bar   --Call-- -> def nop(_): - 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   + 4  pdb-script.py:34   pdb-script.py:15 bar  pdb-script.py:3 nop   --Return-- -> nop(cls.__name__) - 3  :1   pdb-script.py:34   pdb-script.py:15 bar   + 3  :1   pdb-script.py:34   pdb-script.py:15 bar   -> f.baz() - 2  :1   pdb-script.py:35    + 2  :1   pdb-script.py:35    --Call-- -> @staticmethod - 3  :1   pdb-script.py:35   pdb-script.py:17 baz   + 3  :1   pdb-script.py:35   pdb-script.py:17 baz   -> nop(1) - 3  :1   pdb-script.py:35   pdb-script.py:19 baz   + 3  :1   pdb-script.py:35   pdb-script.py:19 baz   --Call-- -> def nop(_): - 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   + 4  pdb-script.py:35   pdb-script.py:19 baz  pdb-script.py:3 nop   --Return-- -> nop(1) - 3  :1   pdb-script.py:35   pdb-script.py:19 baz   + 3  :1   pdb-script.py:35   pdb-script.py:19 baz   -> f.bra() - 2  :1   pdb-script.py:36    + 2  :1   pdb-script.py:36    --Call-- -> def bra(self): - 3  :1   pdb-script.py:36   pdb-script.py:21 bra   + 3  :1   pdb-script.py:36   pdb-script.py:21 bra   -> nop(self.__class__.__name__) - 3  :1   pdb-script.py:36   pdb-script.py:22 bra   + 3  :1   pdb-script.py:36   pdb-script.py:22 bra   --Call-- -> def nop(_): - 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   + 4  pdb-script.py:36   pdb-script.py:22 bra  pdb-script.py:3 nop   --Return-- -> nop(self.__class__.__name__) - 3  :1   pdb-script.py:36   pdb-script.py:22 bra   + 3  :1   pdb-script.py:36   pdb-script.py:22 bra   -> brah() - 2  :1   pdb-script.py:38    + 2  :1   pdb-script.py:38    --Call-- -> def brah(): - 3  :1   pdb-script.py:38   pdb-script.py:25 brah   + 3  :1   pdb-script.py:38   pdb-script.py:25 brah   -> nop('brah') - 3  :1   pdb-script.py:38   pdb-script.py:26 brah   + 3  :1   pdb-script.py:38   pdb-script.py:26 brah   --Call-- -> def nop(_): - 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:2 nop   -> pass - 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   --Return-- -> pass - 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   + 4  pdb-script.py:38   pdb-script.py:26 brah  pdb-script.py:3 nop   --Return-- -> nop('brah') - 3  :1   pdb-script.py:38   pdb-script.py:26 brah   + 3  :1   pdb-script.py:38   pdb-script.py:26 brah   From f9d65fb34db1ea419941a101da02ebd975c31ce4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 20:25:40 +0300 Subject: [PATCH 15/21] Do not wait for too long in do_run_test --- tests/test_shells/test.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 830dcb0a..a84854aa 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -111,8 +111,14 @@ do_run_test() { done # Wait for screen to initialize sleep 1 - while ! screen -S "$SESNAME" -p 0 -X width 300 1 ; do + local attempts=100 + while ! screen -S "$SESNAME" -p 0 -X width 300 1 >/dev/null ; do sleep 0.1s + attempts=$(( attempts - 1 )) + if test $attempts -eq 0 ; then + echo "Waiting for too long: assuming test failed" + return 1 + fi done if ( \ test "x${SH}" = "xdash" \ From d8252f66b7d99caa7f31d9522f8514e8f6fb704b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 21:09:39 +0300 Subject: [PATCH 16/21] Move main() into powerline.bindings.pdb --- powerline/bindings/pdb/__init__.py | 19 +++++++++++++++++++ powerline/bindings/pdb/__main__.py | 22 +--------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/powerline/bindings/pdb/__init__.py b/powerline/bindings/pdb/__init__.py index 48b8a606..4033e611 100644 --- a/powerline/bindings/pdb/__init__.py +++ b/powerline/bindings/pdb/__init__.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) import sys +import pdb from powerline.pdb import PDBPowerline from powerline.lib.encoding import get_preferred_output_encoding @@ -162,3 +163,21 @@ def use_powerline_prompt(cls): cls.prompt = prompt return cls + + +def main(): + '''Run module as a script + + Uses :py:func:`pdb.main` function directly, but prior to that it mocks + :py:class:`pdb.Pdb` class with powerline-specific class instance. + ''' + orig_pdb = pdb.Pdb + + @use_powerline_prompt + class Pdb(pdb.Pdb, object): + def __init__(self): + orig_pdb.__init__(self) + + pdb.Pdb = Pdb + + return pdb.main() diff --git a/powerline/bindings/pdb/__main__.py b/powerline/bindings/pdb/__main__.py index 78527500..768b2f29 100755 --- a/powerline/bindings/pdb/__main__.py +++ b/powerline/bindings/pdb/__main__.py @@ -2,27 +2,7 @@ # vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) -import pdb - -from powerline.bindings.pdb import use_powerline_prompt - - -def main(): - '''Run module as a script - - Uses :py:func:`pdb.main` function directly, but prior to that it mocks - :py:class:`pdb.Pdb` class with powerline-specific class instance. - ''' - orig_pdb = pdb.Pdb - - @use_powerline_prompt - class Pdb(pdb.Pdb, object): - def __init__(self): - orig_pdb.__init__(self) - - pdb.Pdb = Pdb - - return pdb.main() +from powerline.bindings.pdb import main if __name__ == '__main__': From e63a1c7cb50474cb31ec7cb334dd4d6d1046b0e4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 21:18:06 +0300 Subject: [PATCH 17/21] Display the log after long wait --- tests/test_shells/test.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index a84854aa..effd3c45 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -117,6 +117,16 @@ do_run_test() { attempts=$(( attempts - 1 )) if test $attempts -eq 0 ; then echo "Waiting for too long: assuming test failed" + echo "Failed ${SH}. Full output:" + echo '============================================================' + cat tests/shell/${SH}.${TEST_TYPE}.${TEST_CLIENT}.full.log + echo '____________________________________________________________' + if test "x$POWERLINE_TEST_NO_CAT_V" != "x1" ; then + echo "Full output (cat -v):" + echo '============================================================' + cat -v tests/shell/${SH}.${TEST_TYPE}.${TEST_CLIENT}.full.log + echo '____________________________________________________________' + fi return 1 fi done From 0db8154b9aab99880c416af51b54519c57385505 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 31 Jan 2015 21:32:16 +0300 Subject: [PATCH 18/21] Document how to pdb bindings with Python-2.6 and update tests --- docs/source/usage/other.rst | 4 ++++ tests/test_shells/test.sh | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/source/usage/other.rst b/docs/source/usage/other.rst index 108ec3ed..c160339f 100644 --- a/docs/source/usage/other.rst +++ b/docs/source/usage/other.rst @@ -154,6 +154,10 @@ class from :py:class:`pdb.Pdb` and decorate it with just like you used ``python -m pdb``. +.. note: + If you are using Python-2.6 you need to use ``python + -mpowerline.bindings.pdb.__main__``, not what is shown above. + .. warning: Using PyPy (not PyPy3) forces ASCII-only prompts. In other cases unicode characters are allowed, even if you use `pdbpp diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index effd3c45..d436080e 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -464,9 +464,13 @@ if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ; then fi if test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xmodule" ; then echo "> pdb module" - if ! run_test module python $PDB_PYTHON -mpowerline.bindings.pdb "$PWD/tests/test_shells/pdb-script.py" ; then + MODULE="powerline.bindings.pdb" + if test "$PYTHON_MM" = "2.6" ; then + MODULE="powerline.bindings.pdb.__main__" + fi + if ! run_test module python $PDB_PYTHON -m$MODULE "$PWD/tests/test_shells/pdb-script.py" ; then FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -mpowerline.bindings.pdb $PWD/tests/test_shells/pdb-script" + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -m$MODULE $PWD/tests/test_shells/pdb-script" fi fi fi From c3e541d16a9af7be670a620023dd8934a2778090 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 1 Feb 2015 12:08:09 +0300 Subject: [PATCH 19/21] Remove empty lines --- tests/test_shells/postproc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 7b9d330e..32f311d3 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -111,6 +111,8 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: if line == '\033[?1h\033=\033[?25l\033[1A\n': line = '' line = IPYPY_DEANSI_RE.subn('', line)[0] + if line == '\n': + line = '' if line.startswith(('>',)): line = '' elif line == '-> self.quitting = 1\n': From f4e3c3099fdab5401cfa64efdf81962c3dcb6cf2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 1 Feb 2015 12:13:56 +0300 Subject: [PATCH 20/21] Remove everything up until `class Foo(object):` in pdb tests PyPy3 displays prompt two times on the line where `s` is present. --- tests/test_shells/pdb.module.ok | 2 -- tests/test_shells/pdb.subclass.ok | 6 ------ tests/test_shells/postproc.py | 9 +++++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/test_shells/pdb.module.ok b/tests/test_shells/pdb.module.ok index 1001dc42..7554dd6c 100644 --- a/tests/test_shells/pdb.module.ok +++ b/tests/test_shells/pdb.module.ok @@ -1,5 +1,3 @@ - 1  pdb-script.py:2   s --> class Foo(object):  1  pdb-script.py:6    --Call-- -> class Foo(object): diff --git a/tests/test_shells/pdb.subclass.ok b/tests/test_shells/pdb.subclass.ok index b6f024fd..d8eba5ef 100644 --- a/tests/test_shells/pdb.subclass.ok +++ b/tests/test_shells/pdb.subclass.ok @@ -1,9 +1,3 @@ ---Call-- --> def nop(_): - 2  :1   pdb-script.py:2    --> def nop(_): - 2  :1   pdb-script.py:2    --> class Foo(object):  2  :1   pdb-script.py:6    --Call-- -> class Foo(object): diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 32f311d3..d544bf83 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -38,10 +38,11 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: for line in (R if shell != 'fish' else R.read().split('\n')): i += 1 if not found_cd: - if shell == 'pdb': - found_cd = (i > 1) - else: - found_cd = ('cd tests/shell/3rd' in line) + found_cd = ( + 'class Foo(object):' in line + if shell == 'pdb' else + 'cd tests/shell/3rd' in line + ) continue if 'true is the last line' in line: break From d57be8324a224b0b7dbaea232595a338fe04c755 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 2 Feb 2015 00:12:06 +0300 Subject: [PATCH 21/21] Do not alter the way keys are fed with PyPy --- tests/test_shells/test.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index d436080e..fdce0d3e 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -139,11 +139,13 @@ do_run_test() { || ( \ test "x${SH}" = "xpdb" \ && ( \ - test "$PYTHON_VERSION_MAJOR" -eq 3 \ - && test "$PYTHON_VERSION_MINOR" -eq 2 \ - && test "$PYTHON_IMPLEMENTATION" = "CPython" \ + ( \ + test "$PYTHON_VERSION_MAJOR" -eq 3 \ + && test "$PYTHON_VERSION_MINOR" -eq 2 \ + && test "$PYTHON_IMPLEMENTATION" = "CPython" \ + ) \ + || test "$PYTHON_IMPLEMENTATION" = "PyPy" \ ) \ - || test "$PYTHON_IMPLEMENTATION" = "PyPy" ) \ ) ; then # If I do not use this hack for dash then output will look like