Commit dfe75e9a authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Fix for IPython ≥ 8

IPython8 changed format of output tracebacks (see
https://github.com/ipython/ipython/commit/02660f35 and further). Adding
test support for later versions would add maintenance cost on pygolang
side, but testing this is actually not needed, since we activate
IPython-related patch only on py2 and for py2 the latest ipython version
is ipython5.

-> So simply skip this test if we see we have IPython ≥ 8.
   Skip it only on py3 just in case.

For the reference here is how diff in between running
golang_test_defer_excchain.py on IPython7 and IPython8 looks:

    diff --git a/golang/testprog/7 b/golang/testprog/8
    index 5c31ed2..8fea57b 100644
    --- a/golang/testprog/7
    +++ b/golang/testprog/8
    @@ -1,101 +1,91 @@
    -[22;0t]0;IPython: golang/testprog---------------------------------------------------------------------------
    +---------------------------------------------------------------------------
     RuntimeError                              Traceback (most recent call last)
    -~/src/tools/go/pygolang-master/golang/__init__.py in _(f, *argv, **kw)
    -    102         with __goframe__:
    ---> 103             return f(*argv, **kw)
    -    104
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:103, in _func.<locals>._(f, *argv, **kw)
    +    102 with __goframe__:
    +--> 103     return f(*argv, **kw)

    -~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py in main()
    -     41     defer(d1)
    ----> 42     raise RuntimeError("err")
    -     43
    +File ~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py:42, in main()
    +     41 defer(d1)
    +---> 42 raise RuntimeError("err")

     RuntimeError: err

     During handling of the above exception, another exception occurred:

     RuntimeError                              Traceback (most recent call last)
    -~/src/tools/go/pygolang-master/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
    -    179             with __goframe__:
    ---> 180                 d()
    -    181
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:180, in _GoFrame.__exit__(__goframe__, exc_type, exc_val, exc_tb)
    +    179     with __goframe__:
    +--> 180         d()
    +    182 return __goframe__.recovered

    -~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py in d1()
    +File ~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py:31, in d1()
          30 def d1():
     ---> 31     raise RuntimeError("d1: aaa")
    -     32 def d2():

     RuntimeError: d1: aaa

     During handling of the above exception, another exception occurred:

     ZeroDivisionError                         Traceback (most recent call last)
    -~/src/tools/go/pygolang-master/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
    -    179             with __goframe__:
    ---> 180                 d()
    -    181
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:180, in _GoFrame.__exit__(__goframe__, exc_type, exc_val, exc_tb)
    +    179     with __goframe__:
    +--> 180         d()
    +    182 return __goframe__.recovered

    -~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py in d2()
    +File ~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py:33, in d2()
          32 def d2():
     ---> 33     1/0
    -     34 def d3():

     ZeroDivisionError: division by zero

     During handling of the above exception, another exception occurred:

     RuntimeError                              Traceback (most recent call last)
    -/usr/lib/python3.11/runpy.py in run_module(mod_name, init_globals, run_name, alter_sys)
    +File <frozen runpy>:226, in run_module(mod_name, init_globals, run_name, alter_sys)

    -/usr/lib/python3.11/runpy.py in _run_module_code(code, init_globals, mod_name, mod_spec, pkg_name, script_name)
    +File <frozen runpy>:98, in _run_module_code(code, init_globals, mod_name, mod_spec, pkg_name, script_name)

    -/usr/lib/python3.11/runpy.py in _run_code(code, run_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
    +File <frozen runpy>:88, in _run_code(code, run_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)

    -~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py in <module>
    -     43
    +File ~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py:45
    +     42     raise RuntimeError("err")
          44 if __name__ == "__main__":
     ---> 45     main()

    -~/src/tools/go/py3.venv/lib/python3.11/site-packages/decorator.py in fun(*args, **kw)
    -    230             if not kwsyntax:
    -    231                 args, kw = fix(args, kw, sig)
    ---> 232             return caller(func, *(extras + args), **kw)
    -    233     fun.__name__ = func.__name__
    -    234     fun.__doc__ = func.__doc__
    +File ~/src/tools/go/py3.venv/lib/python3.11/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    +    230 if not kwsyntax:
    +    231     args, kw = fix(args, kw, sig)
    +--> 232 return caller(func, *(extras + args), **kw)

    -~/src/tools/go/pygolang-master/golang/__init__.py in _(f, *argv, **kw)
    -    100         # run f under separate frame, where defer will register calls.
    -    101         __goframe__ = _GoFrame()
    ---> 102         with __goframe__:
    -    103             return f(*argv, **kw)
    -    104
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:102, in _func.<locals>._(f, *argv, **kw)
    +     99 def _(f, *argv, **kw):
    +    100     # run f under separate frame, where defer will register calls.
    +    101     __goframe__ = _GoFrame()
    +--> 102     with __goframe__:
    +    103         return f(*argv, **kw)

    -~/src/tools/go/pygolang-master/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
    -    177
    -    178             # even if d panics - we have to call other defers
    ---> 179             with __goframe__:
    -    180                 d()
    -    181
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:179, in _GoFrame.__exit__(__goframe__, exc_type, exc_val, exc_tb)
    +    176     d = __goframe__.deferv.pop()
    +    178     # even if d panics - we have to call other defers
    +--> 179     with __goframe__:
    +    180         d()
    +    182 return __goframe__.recovered

    -~/src/tools/go/pygolang-master/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
    -    177
    -    178             # even if d panics - we have to call other defers
    ---> 179             with __goframe__:
    -    180                 d()
    -    181
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:179, in _GoFrame.__exit__(__goframe__, exc_type, exc_val, exc_tb)
    +    176     d = __goframe__.deferv.pop()
    +    178     # even if d panics - we have to call other defers
    +--> 179     with __goframe__:
    +    180         d()
    +    182 return __goframe__.recovered

    -~/src/tools/go/pygolang-master/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
    -    178             # even if d panics - we have to call other defers
    -    179             with __goframe__:
    ---> 180                 d()
    -    181
    -    182         return __goframe__.recovered
    +File ~/src/tools/go/pygolang-master/golang/__init__.py:180, in _GoFrame.__exit__(__goframe__, exc_type, exc_val, exc_tb)
    +    178     # even if d panics - we have to call other defers
    +    179     with __goframe__:
    +--> 180         d()
    +    182 return __goframe__.recovered

    -~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py in d3()
    -     33     1/0
    +File ~/src/tools/go/pygolang-master/golang/testprog/golang_test_defer_excchain.py:35, in d3()
          34 def d3():
     ---> 35     raise RuntimeError("d3: bbb")
    -     36
    -     37 @func

     RuntimeError: d3: bbb
parent c1e41ac8
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2022 Nexedi SA and Contributors.
# Copyright (C) 2018-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -23,7 +23,7 @@ from __future__ import print_function, absolute_import
from golang import go, chan, select, default, nilchan, _PanicError, func, panic, \
defer, recover, u
from golang import sync
from pytest import raises, mark, fail
from pytest import raises, mark, fail, skip
from _pytest._code import Traceback
from os.path import dirname
import os, sys, inspect, importlib, traceback, doctest
......@@ -1654,6 +1654,13 @@ def test_defer_excchain_dump():
# ----//---- (ipython)
def test_defer_excchain_dump_ipython():
# ipython 8 changed traceback output significantly
# we do not need to test it because we acticate ipython-related patch only
# on py2 for which latest ipython version is 5.
import IPython
if six.PY3 and IPython.version_info >= (8,0):
skip("ipython is patched only on py2; ipython8 changed traceback format")
tbok = readfile(dir_testprog + "/golang_test_defer_excchain.txt-ipython")
retcode, stdout, stderr = _pyrun(["-m", "IPython", "--quick", "--colors=NoColor",
"-m", "golang_test_defer_excchain"],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment