Exemplo n.º 1
0
 def test_not_setup(self):
     _impl = term.impl
     try:
         term.impl = None
         term.reset()
     finally:
         term.impl = _impl
Exemplo n.º 2
0
 def test_not_setup(self):
     _impl = term.impl
     try:
         term.impl = None
         term.reset()
     finally:
         term.impl = _impl
Exemplo n.º 3
0
def main():
    log.debug('Starting up')
    term.init()
    term.settitle('Mutants Of Melimnor    (PyWeek #13: Mutate!)')
    try:
        event.fire('setup')
        game.start()

    except game.GameShutdown:
        term.reset()
    except KeyboardInterrupt:
        term.reset()
        raise
    except Exception, e:
        log.exception(e)
        raise
Exemplo n.º 4
0
 def tearDown(self):
     term.move_cursor(x=0, y=max(0, self.height-8))
     term.reset()
Exemplo n.º 5
0
def print_tb(tb, nlines=5, ncols=80):
    """Pretty print the traceback TB.  NLINES of Python source lines are
    displayed.  All output lines are fitted within NCOLS column."""
    f = tb.tb_frame
    lineno = tb.tb_lineno
    co = f.f_code
    filename = co.co_filename
    name = co.co_name

    # display frame header
    name_str = term.blue(name, True)
    filename_str = term.green(filename)
    _print('----', name_str, filename_str)

    # display source lines
    linecache.checkcache(filename)
    errline = ''
    for n in range(lineno - nlines + 1, lineno + 1):
        line = linecache.getline(filename, n, f.f_globals).rstrip()
        if line is not None:
            lineno_str = term.gray('{:5} '.format(n))
            _print(lineno_str, end='')
            if n == lineno:
                line_str = term.red(line)
                errline = line
            else:
                line_str = term.reset(line)
            _print(line_str)

    def _by_location(key):
        pos = errline.find(key)
        if 0 <= pos <= 255:
            # keys matching the error line come first
            return chr(pos)
        elif key.startswith('__'):
            # keys starting with __ come last
            return '~' + key
        else:
            # sorted in the alphabetical order
            return key

    # dump all local variables in the frame
    keys = sorted(f.f_locals.keys(), key=_by_location)
    for key in keys:
        key_str = term.yellow('{:>20}'.format(key))
        if key in set([
                'linecache', 'pdb', 'sys', 'os', 're', 'term', 'traceback',
                '__builtins__'
        ]):
            _print(key_str, '= ...')
            continue
        else:
            val_str = trimmed_str(repr(f.f_locals[key]), ncols - 20)
            _print(key_str, '=', val_str)

        # dump all attributes for objects
        attr = getattr(f.f_locals[key], '__dict__', None)
        if attr:
            keys = sorted(attr.keys(), key=_by_location)
            for key in keys:
                key_str = term.cyan('{:>28}'.format(key))
                val_str = trimmed_str(repr(attr[key]), ncols - 28)
                _print(key_str, val_str)
Exemplo n.º 6
0
 def tearDown(self):
     term.move_cursor(x=0, y=max(0, self.height - 8))
     term.reset()