Skip to content

Commit 1e8e17c

Browse files
committed
Improve the coverage of testing/code
1 parent a319674 commit 1e8e17c

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

testing/code/test_code.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class A(object):
3232
pytest.raises(TypeError, "_pytest._code.Code(A)")
3333

3434

35-
if True:
36-
37-
def x():
38-
pass
35+
def x():
36+
raise NotImplementedError()
3937

4038

4139
def test_code_fullsource():
@@ -48,7 +46,7 @@ def test_code_source():
4846
code = _pytest._code.Code(x)
4947
src = code.source()
5048
expected = """def x():
51-
pass"""
49+
raise NotImplementedError()"""
5250
assert str(src) == expected
5351

5452

@@ -85,9 +83,9 @@ def f():
8583
raise Exception(value)
8684

8785
excinfo = pytest.raises(Exception, f)
88-
str(excinfo)
89-
if sys.version_info[0] < 3:
90-
text_type(excinfo)
86+
text_type(excinfo)
87+
if sys.version_info < (3,):
88+
bytes(excinfo)
9189

9290

9391
@pytest.mark.skipif(sys.version_info[0] >= 3, reason="python 2 only issue")
@@ -105,25 +103,25 @@ def f():
105103

106104
def test_code_getargs():
107105
def f1(x):
108-
pass
106+
raise NotImplementedError()
109107

110108
c1 = _pytest._code.Code(f1)
111109
assert c1.getargs(var=True) == ("x",)
112110

113111
def f2(x, *y):
114-
pass
112+
raise NotImplementedError()
115113

116114
c2 = _pytest._code.Code(f2)
117115
assert c2.getargs(var=True) == ("x", "y")
118116

119117
def f3(x, **z):
120-
pass
118+
raise NotImplementedError()
121119

122120
c3 = _pytest._code.Code(f3)
123121
assert c3.getargs(var=True) == ("x", "z")
124122

125123
def f4(x, *y, **z):
126-
pass
124+
raise NotImplementedError()
127125

128126
c4 = _pytest._code.Code(f4)
129127
assert c4.getargs(var=True) == ("x", "y", "z")
@@ -188,11 +186,14 @@ def test_not_raise_exception_with_mixed_encoding(self):
188186

189187
tw = TWMock()
190188

191-
args = [("unicode_string", u"São Paulo"), ("utf8_string", "S\xc3\xa3o Paulo")]
189+
args = [("unicode_string", u"São Paulo"), ("utf8_string", b"S\xc3\xa3o Paulo")]
192190

193191
r = ReprFuncArgs(args)
194192
r.toterminal(tw)
195193
if sys.version_info[0] >= 3:
196-
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"
194+
assert (
195+
tw.lines[0]
196+
== r"unicode_string = São Paulo, utf8_string = b'S\xc3\xa3o Paulo'"
197+
)
197198
else:
198199
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"

testing/code/test_source.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# flake8: noqa
23
# disable flake check on this file because some constructs are strange
34
# or redundant on purpose and can't be disable on a line-by-line basis
@@ -41,15 +42,11 @@ def test_source_str_function():
4142

4243

4344
def test_unicode():
44-
try:
45-
unicode
46-
except NameError:
47-
return
48-
x = Source(unicode("4"))
45+
x = Source(u"4")
4946
assert str(x) == "4"
50-
co = _pytest._code.compile(unicode('u"\xc3\xa5"', "utf8"), mode="eval")
47+
co = _pytest._code.compile(u'u"å"', mode="eval")
5148
val = eval(co)
52-
assert isinstance(val, unicode)
49+
assert isinstance(val, six.text_type)
5350

5451

5552
def test_source_from_function():
@@ -632,7 +629,7 @@ def test_issue55():
632629
assert str(s) == ' round_trip("""\n""")'
633630

634631

635-
def XXXtest_multiline():
632+
def test_multiline():
636633
source = getstatement(
637634
0,
638635
"""\

0 commit comments

Comments
 (0)