Move all tests to test_pytest_assertion

The py.code code is independent of any py.test specifics so we should
avoid creating dependencies on py.test in those parts.

--HG--
branch : trunk
This commit is contained in:
Floris Bruynooghe 2010-09-18 13:03:28 +01:00
parent 0af90e0962
commit abab8f6f63
2 changed files with 44 additions and 45 deletions

View File

@ -1,44 +0,0 @@
import sys
import py
from py._code._assertionnew import interpret
def getframe():
"""Return the frame of the caller as a py.code.Frame object"""
return py.code.Frame(sys._getframe(1))
def pytest_funcarg__hook(request):
class MockHook(object):
def __init__(self):
self.called = False
self.args = tuple()
self.kwargs = dict()
def __call__(self, op, left, right):
self.called = True
self.op = op
self.left = left
self.right = right
return MockHook()
def test_pytest_assert_compare_called(monkeypatch, hook):
monkeypatch.setattr(py._plugin.pytest_assertion,
'pytest_assert_compare', hook)
interpret('assert 0 == 1', getframe())
assert hook.called
def test_pytest_assert_compare_args(monkeypatch, hook):
print hook.called
monkeypatch.setattr(py._plugin.pytest_assertion,
'pytest_assert_compare', hook)
interpret('assert [0, 1] == [0, 2]', getframe())
print hook.called
print hook.left
print hook.right
assert hook.op == '=='
assert hook.left == [0, 1]
assert hook.right == [0, 2]

View File

@ -1,7 +1,30 @@
import sys
import py import py
from py._code._assertionnew import interpret
import py._plugin.pytest_assertion as plugin import py._plugin.pytest_assertion as plugin
def getframe():
"""Return the frame of the caller as a py.code.Frame object"""
return py.code.Frame(sys._getframe(1))
def pytest_funcarg__hook(request):
class MockHook(object):
def __init__(self):
self.called = False
self.args = tuple()
self.kwargs = dict()
def __call__(self, op, left, right):
self.called = True
self.op = op
self.left = left
self.right = right
return MockHook()
def test_functional(testdir): def test_functional(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def test_hello(): def test_hello():
@ -54,7 +77,27 @@ def test_traceback_failure(testdir):
]) ])
class Test_pytest_assert_compare: def test_pytest_assert_compare_called(monkeypatch, hook):
monkeypatch.setattr(py._plugin.pytest_assertion,
'pytest_assert_compare', hook)
interpret('assert 0 == 1', getframe())
assert hook.called
def test_pytest_assert_compare_args(monkeypatch, hook):
print hook.called
monkeypatch.setattr(py._plugin.pytest_assertion,
'pytest_assert_compare', hook)
interpret('assert [0, 1] == [0, 2]', getframe())
print hook.called
print hook.left
print hook.right
assert hook.op == '=='
assert hook.left == [0, 1]
assert hook.right == [0, 2]
class TestAssertCompare:
def test_different_types(self): def test_different_types(self):
assert plugin.pytest_assert_compare('==', [0, 1], 'foo') is None assert plugin.pytest_assert_compare('==', [0, 1], 'foo') is None