Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Authors: Sylvain MARIE <sylvain.marie@se.com> 

2# + All contributors to <https://github.com/smarie/python-pytest-steps> 

3# 

4# License: 3-clause BSD, <https://github.com/smarie/python-pytest-steps/blob/master/LICENSE> 

5import sys 

6 

7PY3 = sys.version_info[0] >= 3 

8PY34 = sys.version_info[0:2] >= (3, 4) 

9 

10if PY3: 10 ↛ 13line 10 didn't jump to line 13, because the condition on line 10 was never false

11 string_types = str, 

12else: 

13 string_types = basestring, # noqa 

14 

15 

16# reraise see https://stackoverflow.com/a/34463112/7262247 

17if PY3: 17 ↛ 33line 17 didn't jump to line 33, because the condition on line 17 was never false

18 def reraise(tp, value, tb=None): 

19 try: 

20 if value is None: 20 ↛ 21line 20 didn't jump to line 21, because the condition on line 20 was never true

21 value = tp() 

22 # else: 

23 # # HACK to fix bug 

24 # value = tp(*value) 

25 if value.__traceback__ is not tb: 25 ↛ 26line 25 didn't jump to line 26, because the condition on line 25 was never true

26 raise value.with_traceback(tb) 

27 raise value 

28 finally: 

29 value = None 

30 tb = None 

31 

32else: 

33 def exec_(_code_, _globs_=None, _locs_=None): 

34 """Execute code in a namespace.""" 

35 if _globs_ is None: 

36 frame = sys._getframe(1) 

37 _globs_ = frame.f_globals 

38 if _locs_ is None: 

39 _locs_ = frame.f_locals 

40 del frame 

41 elif _locs_ is None: 

42 _locs_ = _globs_ 

43 exec("""exec _code_ in _globs_, _locs_""") # noqa 

44 

45 exec_("""def reraise(tp, value, tb=None): 

46 try: 

47 raise tp, value, tb 

48 finally: 

49 tb = None 

50""") 

51 

52 

53# def with_metaclass(meta, *bases): 

54# """Create a base class with a metaclass.""" 

55# # This requires a bit of explanation: the basic idea is to make a dummy 

56# # metaclass for one level of class instantiation that replaces itself with 

57# # the actual metaclass. 

58# class metaclass(type): 

59# 

60# def __new__(cls, name, this_bases, d): 

61# return meta(name, bases, d) 

62# 

63# @classmethod 

64# def __prepare__(cls, name, this_bases): 

65# return meta.__prepare__(name, bases) 

66# return type.__new__(metaclass, 'temporary_class', (), {})