Skip to content

Commit 283dc43

Browse files
committed
Moved py.code code over to py.test
This is dependent on a feature branch of the py repository Fix #103
1 parent 84eacf3 commit 283dc43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4553
-144
lines changed

_pytest/assertion/newinterpret.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import ast
88

9-
import py
9+
import _pytest.code
1010
from _pytest.assertion import util
1111
from _pytest.assertion.reinterpret import BuiltinAssertionError
1212

@@ -63,7 +63,7 @@ def interpret(source, frame, should_fail=False):
6363

6464
def run(offending_line, frame=None):
6565
if frame is None:
66-
frame = py.code.Frame(sys._getframe(1))
66+
frame = _pytest.code.Frame(sys._getframe(1))
6767
return interpret(offending_line, frame)
6868

6969
def getfailure(e):

_pytest/assertion/oldinterpret.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import inspect
2+
import sys
13
import traceback
24
import types
3-
import py
4-
import sys, inspect
5+
56
from compiler import parse, ast, pycodegen
7+
8+
import _pytest.code
9+
import py
610
from _pytest.assertion.util import format_explanation, BuiltinAssertionError
711

812
passthroughex = py.builtin._sysex
@@ -456,7 +460,7 @@ def report_failure(e):
456460
def check(s, frame=None):
457461
if frame is None:
458462
frame = sys._getframe(1)
459-
frame = py.code.Frame(frame)
463+
frame = _pytest.code.Frame(frame)
460464
expr = parse(s, 'eval')
461465
assert isinstance(expr, ast.Expression)
462466
node = Interpretable(expr.node)
@@ -480,7 +484,7 @@ def interpret(source, frame, should_fail=False):
480484
module = Interpretable(parse(source, 'exec').node)
481485
#print "got module", module
482486
if isinstance(frame, types.FrameType):
483-
frame = py.code.Frame(frame)
487+
frame = _pytest.code.Frame(frame)
484488
try:
485489
module.run(frame)
486490
except Failure:
@@ -499,9 +503,9 @@ def interpret(source, frame, should_fail=False):
499503

500504
def getmsg(excinfo):
501505
if isinstance(excinfo, tuple):
502-
excinfo = py.code.ExceptionInfo(excinfo)
506+
excinfo = _pytest.code.ExceptionInfo(excinfo)
503507
#frame, line = gettbline(tb)
504-
#frame = py.code.Frame(frame)
508+
#frame = _pytest.code.Frame(frame)
505509
#return interpret(line, frame)
506510

507511
tb = excinfo.traceback[-1]
@@ -525,7 +529,7 @@ def getfailure(e):
525529
def run(s, frame=None):
526530
if frame is None:
527531
frame = sys._getframe(1)
528-
frame = py.code.Frame(frame)
532+
frame = _pytest.code.Frame(frame)
529533
module = Interpretable(parse(s, 'exec').node)
530534
try:
531535
module.run(frame)

_pytest/assertion/reinterpret.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import sys
2+
3+
import _pytest.code
24
import py
35
from _pytest.assertion.util import BuiltinAssertionError
6+
47
u = py.builtin._totext
58

69

@@ -22,7 +25,7 @@ def __init__(self, *args):
2225
"<[broken __repr__] %s at %0xd>"
2326
% (toprint.__class__, id(toprint)))
2427
else:
25-
f = py.code.Frame(sys._getframe(1))
28+
f = _pytest.code.Frame(sys._getframe(1))
2629
try:
2730
source = f.code.fullsource
2831
if source is not None:

_pytest/assertion/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utilities for assertion debugging"""
22
import pprint
33

4+
import _pytest.code
45
import py
56
try:
67
from collections import Sequence
@@ -179,7 +180,7 @@ def isiterable(obj):
179180
explanation = [
180181
u('(pytest_assertion plugin: representation of details failed. '
181182
'Probably an object has a faulty __repr__.)'),
182-
u(py.code.ExceptionInfo())]
183+
u(_pytest.code.ExceptionInfo())]
183184

184185
if not explanation:
185186
return None

_pytest/code/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
""" python inspection/code generation API """
2+
from .assertion import AssertionError as _AssertionError # noqa
3+
from .assertion import _format_explanation # noqa
4+
from .assertion import _reprcompare # noqa
5+
from .assertion import reinterpret as _reinterpret # noqa
6+
from .assertion import reinterpret_old as _reinterpret_old # noqa
7+
from .code import Code # noqa
8+
from .code import ExceptionInfo # noqa
9+
from .code import Frame # noqa
10+
from .code import Traceback # noqa
11+
from .code import getrawcode # noqa
12+
from .code import patch_builtins # noqa
13+
from .code import unpatch_builtins # noqa
14+
from .source import Source # noqa
15+
from .source import compile_ as compile # noqa
16+
from .source import getfslineno # noqa
17+

0 commit comments

Comments
 (0)