-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4226 from rlaverde/test-search-avoided-patterns-3…
….1.x PR: Generalice previous is_instance test to search other avoided patterns
- Loading branch information
Showing
31 changed files
with
139 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © Spyder Project Contributors | ||
# Licensed under the terms of the MIT License | ||
# (see spyder/__init__.py for details) | ||
|
||
import os | ||
import re | ||
import codecs | ||
|
||
import pytest | ||
|
||
root_path = os.path.realpath(os.path.join(os.getcwd(), 'spyder')) | ||
|
||
|
||
@pytest.mark.parametrize("pattern,exclude_patterns,message", [ | ||
("isinstance\(.*,.*str\)", ['py3compat.py'], | ||
("Don't use builtin isinstance() function," | ||
"use spyder.py3compat.is_text_string() instead")), | ||
(r"^[\s\#]*\bprint\(((?!file=).)*\)", ['.*test.*', 'example.py', 'binaryornot'], | ||
("Don't use print() functions, ", | ||
"for debuging you could use debug_print instead")), | ||
(r"^[\s\#]*\bprint\s+(?!>>)((?!#).)*", ['.*test.*'], | ||
("Don't use print __builtin__, ", | ||
"for debuging you could use debug_print instead")), | ||
]) | ||
def test_dont_use(pattern, exclude_patterns, message): | ||
""" | ||
This test is used for discouraged using of some expresions that could | ||
introduce errors, and encourage use spyder function instead. | ||
If you want to skip some line from this test just use: | ||
# spyder: test-skip | ||
""" | ||
pattern = re.compile(pattern + "((?!# spyder: test-skip)\s)*$") | ||
|
||
found = 0 | ||
for dir_name, _, file_list in os.walk(root_path): | ||
for fname in file_list: | ||
exclude = any([re.search(ex, fname) for ex in exclude_patterns]) | ||
exclude = exclude or any([re.search(ex, dir_name) for ex in exclude_patterns]) | ||
|
||
if fname.endswith('.py') and not exclude: | ||
file = os.path.join(dir_name, fname) | ||
|
||
with codecs.open(file, encoding="utf-8") as f: | ||
for i, line in enumerate(f): | ||
for match in re.finditer(pattern, line): | ||
print("{}\nline:{}, {}".format(file, i + 1, line)) | ||
found += 1 | ||
|
||
assert found == 0, "{}\n{} errors found".format(message, found) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.