Improve the coverage of testing/code
This commit is contained in:
parent
a31967431f
commit
1e8e17c01e
|
@ -32,10 +32,8 @@ def test_code_with_class():
|
||||||
pytest.raises(TypeError, "_pytest._code.Code(A)")
|
pytest.raises(TypeError, "_pytest._code.Code(A)")
|
||||||
|
|
||||||
|
|
||||||
if True:
|
|
||||||
|
|
||||||
def x():
|
def x():
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
def test_code_fullsource():
|
def test_code_fullsource():
|
||||||
|
@ -48,7 +46,7 @@ def test_code_source():
|
||||||
code = _pytest._code.Code(x)
|
code = _pytest._code.Code(x)
|
||||||
src = code.source()
|
src = code.source()
|
||||||
expected = """def x():
|
expected = """def x():
|
||||||
pass"""
|
raise NotImplementedError()"""
|
||||||
assert str(src) == expected
|
assert str(src) == expected
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,9 +83,9 @@ def test_unicode_handling():
|
||||||
raise Exception(value)
|
raise Exception(value)
|
||||||
|
|
||||||
excinfo = pytest.raises(Exception, f)
|
excinfo = pytest.raises(Exception, f)
|
||||||
str(excinfo)
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
text_type(excinfo)
|
text_type(excinfo)
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
bytes(excinfo)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info[0] >= 3, reason="python 2 only issue")
|
@pytest.mark.skipif(sys.version_info[0] >= 3, reason="python 2 only issue")
|
||||||
|
@ -105,25 +103,25 @@ def test_unicode_handling_syntax_error():
|
||||||
|
|
||||||
def test_code_getargs():
|
def test_code_getargs():
|
||||||
def f1(x):
|
def f1(x):
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
c1 = _pytest._code.Code(f1)
|
c1 = _pytest._code.Code(f1)
|
||||||
assert c1.getargs(var=True) == ("x",)
|
assert c1.getargs(var=True) == ("x",)
|
||||||
|
|
||||||
def f2(x, *y):
|
def f2(x, *y):
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
c2 = _pytest._code.Code(f2)
|
c2 = _pytest._code.Code(f2)
|
||||||
assert c2.getargs(var=True) == ("x", "y")
|
assert c2.getargs(var=True) == ("x", "y")
|
||||||
|
|
||||||
def f3(x, **z):
|
def f3(x, **z):
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
c3 = _pytest._code.Code(f3)
|
c3 = _pytest._code.Code(f3)
|
||||||
assert c3.getargs(var=True) == ("x", "z")
|
assert c3.getargs(var=True) == ("x", "z")
|
||||||
|
|
||||||
def f4(x, *y, **z):
|
def f4(x, *y, **z):
|
||||||
pass
|
raise NotImplementedError()
|
||||||
|
|
||||||
c4 = _pytest._code.Code(f4)
|
c4 = _pytest._code.Code(f4)
|
||||||
assert c4.getargs(var=True) == ("x", "y", "z")
|
assert c4.getargs(var=True) == ("x", "y", "z")
|
||||||
|
@ -188,11 +186,14 @@ class TestReprFuncArgs(object):
|
||||||
|
|
||||||
tw = TWMock()
|
tw = TWMock()
|
||||||
|
|
||||||
args = [("unicode_string", u"São Paulo"), ("utf8_string", "S\xc3\xa3o Paulo")]
|
args = [("unicode_string", u"São Paulo"), ("utf8_string", b"S\xc3\xa3o Paulo")]
|
||||||
|
|
||||||
r = ReprFuncArgs(args)
|
r = ReprFuncArgs(args)
|
||||||
r.toterminal(tw)
|
r.toterminal(tw)
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"
|
assert (
|
||||||
|
tw.lines[0]
|
||||||
|
== r"unicode_string = São Paulo, utf8_string = b'S\xc3\xa3o Paulo'"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"
|
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
# flake8: noqa
|
# flake8: noqa
|
||||||
# disable flake check on this file because some constructs are strange
|
# disable flake check on this file because some constructs are strange
|
||||||
# or redundant on purpose and can't be disable on a line-by-line basis
|
# or redundant on purpose and can't be disable on a line-by-line basis
|
||||||
|
@ -41,15 +42,11 @@ def test_source_str_function():
|
||||||
|
|
||||||
|
|
||||||
def test_unicode():
|
def test_unicode():
|
||||||
try:
|
x = Source(u"4")
|
||||||
unicode
|
|
||||||
except NameError:
|
|
||||||
return
|
|
||||||
x = Source(unicode("4"))
|
|
||||||
assert str(x) == "4"
|
assert str(x) == "4"
|
||||||
co = _pytest._code.compile(unicode('u"\xc3\xa5"', "utf8"), mode="eval")
|
co = _pytest._code.compile(u'u"å"', mode="eval")
|
||||||
val = eval(co)
|
val = eval(co)
|
||||||
assert isinstance(val, unicode)
|
assert isinstance(val, six.text_type)
|
||||||
|
|
||||||
|
|
||||||
def test_source_from_function():
|
def test_source_from_function():
|
||||||
|
@ -632,7 +629,7 @@ def test_issue55():
|
||||||
assert str(s) == ' round_trip("""\n""")'
|
assert str(s) == ' round_trip("""\n""")'
|
||||||
|
|
||||||
|
|
||||||
def XXXtest_multiline():
|
def test_multiline():
|
||||||
source = getstatement(
|
source = getstatement(
|
||||||
0,
|
0,
|
||||||
"""\
|
"""\
|
||||||
|
|
Loading…
Reference in New Issue