-
-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathtest_bare_except_fix.py
More file actions
28 lines (22 loc) · 963 Bytes
/
test_bare_except_fix.py
File metadata and controls
28 lines (22 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import ast
import os
def test_no_bare_except_in_import_runner():
"""Test that import_runner.py does not contain bare except clauses."""
file_path = os.path.join(os.path.dirname(__file__), "..", "import_runner.py")
with open(file_path, "r") as f:
source = f.read()
tree = ast.parse(source)
bare_excepts = []
for node in ast.walk(tree):
if isinstance(node, ast.ExceptHandler):
if node.type is None:
bare_excepts.append(node.lineno)
assert len(bare_excepts) == 0, f"Found bare except clauses at lines: {bare_excepts}"