예제 #1
0
def test_patch_file(capsys):
    p = Patcher()
    p.loads("""
from setuptools import setup
setup(package='foobar')
    """)
    p.patch_run(function='setuptools.setup', handler=pyintercept.print_)
    out, _err = capsys.readouterr()
    assert out == "()\n{'package': 'foobar'}\n"
예제 #2
0
def test_patch_file(capsys):
    p = Patcher()
    p.loads("""
from setuptools import setup
setup(package='foobar')
    """)
    p.patch_run(function='setuptools.setup', handler=pyintercept.print_)
    out, _err = capsys.readouterr()
    assert out == "()\n{'package': 'foobar'}\n"
예제 #3
0
def test_patch_local_function(capsys):
    def double(origfn, i):
        print(i * 3)
    p = Patcher()
    p.loads("""
def double(i):
  print(i * 2)
double(1)
double(2)
    """)
    p.patch_run(function='double', handler=double)
    out, _err = capsys.readouterr()
    assert out == '3\n6\n'
예제 #4
0
def test_patch_local_function(capsys):
    def double(origfn, i):
        print(i * 3)

    p = Patcher()
    p.loads("""
def double(i):
  print(i * 2)
double(1)
double(2)
    """)
    p.patch_run(function='double', handler=double)
    out, _err = capsys.readouterr()
    assert out == '3\n6\n'
예제 #5
0
def test_not_loaded():
    p = Patcher()
    with pytest.raises(AssertionError):
        p.patch_run(function='x')
예제 #6
0
def test_not_loaded():
    p = Patcher()
    with pytest.raises(AssertionError):
        p.patch_run(function='x')