Changeset dfa2468 in rtems-tools


Ignore:
Timestamp:
Mar 16, 2016, 10:39:39 AM (3 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, master
Children:
0c0b2d4
Parents:
4bcf18b
Message:

tester: Fix reraising an exception with Python2 and Python3.

Updates #2619.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/rt/test.py

    r4bcf18b rdfa2468  
    5050from . import options
    5151from . import report
     52
     53#
     54# The following fragment is taken from https://bitbucket.org/gutworth/six
     55# to raise an exception. The python2 code cause a syntax error with python3.
     56#
     57# Copyright (c) 2010-2016 Benjamin Peterson
     58#
     59# Permission is hereby granted, free of charge, to any person obtaining a copy
     60# of this software and associated documentation files (the "Software"), to deal
     61# in the Software without restriction, including without limitation the rights
     62# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     63# copies of the Software, and to permit persons to whom the Software is
     64# furnished to do so, subject to the following conditions:
     65#
     66# The above copyright notice and this permission notice shall be included in all
     67# copies or substantial portions of the Software.
     68#
     69# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     70# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     71# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     72# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     73# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     74# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     75# SOFTWARE.
     76#
     77# Taken from six.
     78#
     79if sys.version_info[0] == 3:
     80    def _test_reraise(tp, value, tb = None):
     81        raise value.with_traceback(tb)
     82else:
     83    def exec_(_code_, _globs_ = None, _locs_ = None):
     84        if _globs_ is None:
     85            frame = sys._getframe(1)
     86            _globs_ = frame.f_globals
     87            if _locs_ is None:
     88                _locs_ = frame.f_locals
     89            del frame
     90        elif _locs_ is None:
     91            _locs_ = _globs_
     92        exec("""exec _code_ in _globs_, _locs_""")
     93
     94    exec_("""def _test_reraise(tp, value, tb = None):
     95    raise tp, value, tb
     96""")
    5297
    5398class test(object):
     
    121166    def reraise(self):
    122167        if self.result is not None:
    123             with_tb = getattr(self.result[1], 'with_traceback', None)
    124             if with_tb:
    125                 raise self.result[1].with_traceback(self.result[2])
    126             raise (self.result[0], self.result[1], self.result[2])
     168            _test_reraise(*self.result)
    127169
    128170    def kill(self):
Note: See TracChangeset for help on using the changeset viewer.