Skip to content

Commit 6e2e83a

Browse files
committed
Simplify debug-statemetns tests
1 parent 904a061 commit 6e2e83a

File tree

2 files changed

+12
-55
lines changed

2 files changed

+12
-55
lines changed

testing/resources/file_with_debug.notpy

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/debug_statement_hook_test.py

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,34 @@
44

55
import ast
66

7-
import pytest
8-
97
from pre_commit_hooks.debug_statement_hook import debug_statement_hook
108
from pre_commit_hooks.debug_statement_hook import DebugStatement
119
from pre_commit_hooks.debug_statement_hook import ImportStatementParser
1210
from testing.util import get_resource_path
1311

1412

15-
@pytest.fixture
16-
def ast_with_no_debug_imports():
17-
return ast.parse(
18-
"""
19-
import foo
20-
import bar
21-
import baz
22-
from foo import bar
23-
""",
24-
)
25-
26-
27-
@pytest.fixture
28-
def ast_with_debug_import_form_1():
29-
return ast.parse(
30-
"""
31-
32-
import ipdb; ipdb.set_trace()
33-
34-
""",
35-
)
36-
37-
38-
@pytest.fixture
39-
def ast_with_debug_import_form_2():
40-
return ast.parse(
41-
"""
42-
43-
from pudb import set_trace; set_trace()
44-
45-
""",
46-
)
47-
48-
49-
def test_returns_no_debug_statements(ast_with_no_debug_imports):
13+
def test_no_debug_imports():
5014
visitor = ImportStatementParser()
51-
visitor.visit(ast_with_no_debug_imports)
15+
visitor.visit(ast.parse('import os\nfrom foo import bar\n'))
5216
assert visitor.debug_import_statements == []
5317

5418

55-
def test_returns_one_form_1(ast_with_debug_import_form_1):
19+
def test_finds_debug_import_attribute_access():
5620
visitor = ImportStatementParser()
57-
visitor.visit(ast_with_debug_import_form_1)
58-
assert visitor.debug_import_statements == [
59-
DebugStatement('ipdb', 3, 0),
60-
]
21+
visitor.visit(ast.parse('import ipdb; ipdb.set_trace()'))
22+
assert visitor.debug_import_statements == [DebugStatement('ipdb', 1, 0)]
6123

6224

63-
def test_returns_one_form_2(ast_with_debug_import_form_2):
25+
def test_finds_debug_import_from_import():
6426
visitor = ImportStatementParser()
65-
visitor.visit(ast_with_debug_import_form_2)
66-
assert visitor.debug_import_statements == [
67-
DebugStatement('pudb', 3, 0),
68-
]
27+
visitor.visit(ast.parse('from pudb import set_trace; set_trace()'))
28+
assert visitor.debug_import_statements == [DebugStatement('pudb', 1, 0)]
6929

7030

71-
def test_returns_one_for_failing_file():
72-
ret = debug_statement_hook([get_resource_path('file_with_debug.notpy')])
31+
def test_returns_one_for_failing_file(tmpdir):
32+
f_py = tmpdir.join('f.py')
33+
f_py.write('def f():\n import pdb; pdb.set_trace()')
34+
ret = debug_statement_hook([f_py.strpath])
7335
assert ret == 1
7436

7537

0 commit comments

Comments
 (0)