Skip to content

Commit 6506f01

Browse files
committed
testing/test_source: use unqualified imports
1 parent a1df458 commit 6506f01

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

testing/code/test_source.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
import py.path
1515

16-
import _pytest._code
1716
import pytest
18-
from _pytest._code import getfslineno
17+
from _pytest._code import Code
18+
from _pytest._code import Frame
1919
from _pytest._code import Source
20+
from _pytest._code import getfslineno
2021

2122

2223
def test_source_str_function() -> None:
@@ -35,7 +36,7 @@ def test_source_str_function() -> None:
3536

3637

3738
def test_source_from_function() -> None:
38-
source = _pytest._code.Source(test_source_str_function)
39+
source = Source(test_source_str_function)
3940
assert str(source).startswith("def test_source_str_function() -> None:")
4041

4142

@@ -44,21 +45,21 @@ class TestClass:
4445
def test_method(self):
4546
pass
4647

47-
source = _pytest._code.Source(TestClass().test_method)
48+
source = Source(TestClass().test_method)
4849
assert source.lines == ["def test_method(self):", " pass"]
4950

5051

5152
def test_source_from_lines() -> None:
5253
lines = ["a \n", "b\n", "c"]
53-
source = _pytest._code.Source(lines)
54+
source = Source(lines)
5455
assert source.lines == ["a ", "b", "c"]
5556

5657

5758
def test_source_from_inner_function() -> None:
5859
def f():
5960
raise NotImplementedError()
6061

61-
source = _pytest._code.Source(f)
62+
source = Source(f)
6263
assert str(source).startswith("def f():")
6364

6465

@@ -220,7 +221,7 @@ def test_getstartingblock_singleline() -> None:
220221
class A:
221222
def __init__(self, *args) -> None:
222223
frame = sys._getframe(1)
223-
self.source = _pytest._code.Frame(frame).statement
224+
self.source = Frame(frame).statement
224225

225226
x = A("x", "y")
226227

@@ -250,8 +251,8 @@ def f():
250251
def g():
251252
pass # pragma: no cover
252253

253-
f_source = _pytest._code.Source(f)
254-
g_source = _pytest._code.Source(g)
254+
f_source = Source(f)
255+
g_source = Source(g)
255256
assert str(f_source).strip() == "def f():\n raise NotImplementedError()"
256257
assert str(g_source).strip() == "def g():\n pass # pragma: no cover"
257258

@@ -268,7 +269,7 @@ def f():
268269
pass
269270
"""
270271
'''
271-
assert str(_pytest._code.Source(f)) == expected.rstrip()
272+
assert str(Source(f)) == expected.rstrip()
272273

273274

274275
def test_deindent() -> None:
@@ -288,7 +289,7 @@ def g():
288289
def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None:
289290
# this test fails because the implicit inspect.getsource(A) below
290291
# does not return the "x = 1" last line.
291-
source = _pytest._code.Source(
292+
source = Source(
292293
"""
293294
class A(object):
294295
def method(self):
@@ -297,7 +298,7 @@ def method(self):
297298
)
298299
path = tmpdir.join("a.py")
299300
path.write(source)
300-
s2 = _pytest._code.Source(tmpdir.join("a.py").pyimport().A)
301+
s2 = Source(tmpdir.join("a.py").pyimport().A)
301302
assert str(source).strip() == str(s2).strip()
302303

303304

@@ -386,26 +387,26 @@ def test_code_of_object_instance_with_call() -> None:
386387
class A:
387388
pass
388389

389-
pytest.raises(TypeError, lambda: _pytest._code.Source(A()))
390+
pytest.raises(TypeError, lambda: Source(A()))
390391

391392
class WithCall:
392393
def __call__(self) -> None:
393394
pass
394395

395-
code = _pytest._code.Code(WithCall())
396+
code = Code(WithCall())
396397
assert "pass" in str(code.source())
397398

398399
class Hello:
399400
def __call__(self) -> None:
400401
pass
401402

402-
pytest.raises(TypeError, lambda: _pytest._code.Code(Hello))
403+
pytest.raises(TypeError, lambda: Code(Hello))
403404

404405

405406
def getstatement(lineno: int, source) -> Source:
406407
from _pytest._code.source import getstatementrange_ast
407408

408-
src = _pytest._code.Source(source)
409+
src = Source(source)
409410
ast, start, end = getstatementrange_ast(lineno, src)
410411
return src[start:end]
411412

@@ -637,7 +638,7 @@ def test_getstartingblock_multiline() -> None:
637638
class A:
638639
def __init__(self, *args):
639640
frame = sys._getframe(1)
640-
self.source = _pytest._code.Frame(frame).statement
641+
self.source = Frame(frame).statement
641642

642643
# fmt: off
643644
x = A('x',

0 commit comments

Comments
 (0)