예제 #1
0
def test_nested_scopes_2():
    a = 1
    def g():
        b = 2
        assert a == b
    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg == 'assert 1 == 2'
예제 #2
0
def test_assert_exprinfo():
    def g():
        a = 1
        b = 2
        assert a == b
    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg == 'assert 1 == 2'
예제 #3
0
def test_interpretable_escapes_newlines():
    class X(object):
        def __repr__(self):
            return '1\n2'
    def g():
        assert X() == 'XXX'

    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg == "assert 1\\n2 == 'XXX'\n +  where 1\\n2 = <class 'py.__.magic.testing.test_exprinfo.X'>()"
예제 #4
0
def test_nested_scopes():
    def g():
        a = 1
        def h():
            return a
        b = 2
        assert h() == b
    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg.startswith('assert 1 == 2\n +  where 1 = ')
예제 #5
0
def test_assert_func_argument_type_error():
    def f ():
        pass
    def g():
        f(1)
    excinfo = getexcinfo(TypeError, g)
    msg = getmsg(excinfo)
    assert msg.find("takes no argument") != -1

    class A:
        def f():
            pass
    def g():
        A().f()
    excinfo = getexcinfo(TypeError, g)
    msg = getmsg(excinfo)
    assert msg.find("takes no argument") != -1

    def g():
        A.f()
    excinfo = getexcinfo(TypeError, g)
    msg = getmsg(excinfo)
    assert msg.find("must be called with A") != -1
예제 #6
0
def test_twoarg_comparison_does_not_call_nonzero():
    # this arises e.g. in numpy array comparisons 
    class X(object):
        def __eq__(self, other):
            return self

        def __nonzero__(self):
            raise ValueError

        def all(self):
            return False

    def f():
        a = X()
        b = X()
        assert (a == b).all()

    excinfo = getexcinfo(AssertionError, f)
    msg = getmsg(excinfo)
    print msg
    assert "re-run" not in msg
    assert "ValueError" not in msg
예제 #7
0
def test_exprinfo_funccall_keywords():
    def g():
        assert global_f(v=11) == 67
    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg == 'assert 66 == 67\n +  where 66 = global_f(v=11)'
예제 #8
0
def test_exprinfo_funccall():
    def g():
        assert global_f() == 43
    excinfo = getexcinfo(AssertionError, g)
    msg = getmsg(excinfo)
    assert msg == 'assert 42 == 43\n +  where 42 = global_f()'