Coverage for src/pytest_cases/common_mini_six.py: 75%

6 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-09-26 21:52 +0000

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

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

3# 

4# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/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# if PY3: 

17# def reraise(tp, value, tb=None): 

18# try: 

19# if value is None: 

20# value = tp() 

21# else: 

22# # HACK to fix bug 

23# value = tp(*value) 

24# if value.__traceback__ is not tb: 

25# raise value.with_traceback(tb) 

26# raise value 

27# finally: 

28# value = None 

29# tb = None 

30# 

31# else: 

32# def exec_(_code_, _globs_=None, _locs_=None): 

33# """Execute code in a namespace.""" 

34# if _globs_ is None: 

35# frame = sys._getframe(1) 

36# _globs_ = frame.f_globals 

37# if _locs_ is None: 

38# _locs_ = frame.f_locals 

39# del frame 

40# elif _locs_ is None: 

41# _locs_ = _globs_ 

42# exec("""exec _code_ in _globs_, _locs_""") 

43# 

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

45# try: 

46# raise tp, value, tb 

47# finally: 

48# tb = None 

49# """) 

50 

51 

52# def with_metaclass(meta, *bases): 

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

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

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

56# # the actual metaclass. 

57# class metaclass(type): 

58# 

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

60# return meta(name, bases, d) 

61# 

62# @classmethod 

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

64# return meta.__prepare__(name, bases) 

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