-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Bear is added to find bugs in python file. Closes #2151
- Loading branch information
1 parent
fd5a5a7
commit 6d4ae18
Showing
7 changed files
with
103 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ addons: | |
- php-codesniffer | ||
- r-base | ||
- verilator | ||
- pychecker | ||
|
||
cache: | ||
pip: true | ||
|
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,40 @@ | ||
import shlex | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.DistributionRequirement import ( | ||
DistributionRequirement) | ||
|
||
|
||
@linter(executable='pychecker', | ||
output_format='regex', | ||
output_regex=r'(?P<filename>\w+\.py):(?P<line>\d+): ' | ||
r'(?P<message>.*)') | ||
class PyCheckerBear: | ||
""" | ||
Find bugs in your Python source code. | ||
The code for each function, class, and method is checked for possible | ||
problems. Checks for unused globals and locals(module or variable), unused | ||
method arguments and using a variable before setting it or if you are | ||
redefining a function/class/method in the same scope. | ||
""" | ||
LANGUAGES = {'Python', 'Python 2', 'Python 3'} | ||
REQUIREMENTS = {DistributionRequirement(apt_get='pychecker')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Unused method/function arguments', | ||
'No doc string', 'Redefining'} | ||
SEE_MORE = 'http://pychecker.sourceforge.net/' | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
pychecker_cli_options: str = ''): | ||
""" | ||
:param pychecker_cli_options: Command line options you wish to be | ||
passed to pychecker. | ||
""" | ||
args = () | ||
if pychecker_cli_options: | ||
args += tuple(shlex.split(pychecker_cli_options)) | ||
|
||
return args + (filename,) |
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,51 @@ | ||
from queue import Queue | ||
import os.path | ||
|
||
from coalib.settings.Section import Section | ||
from coalib.results.Result import Result | ||
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
|
||
from bears.python.PyCheckerBear import PyCheckerBear | ||
|
||
|
||
def get_testfile_path(file): | ||
return os.path.join(os.path.dirname(__file__), | ||
'pychecker_test_files', file) | ||
|
||
|
||
def load_testfiles(name): | ||
with open(get_testfile_path(name)) as f1: | ||
contents = f1.read().splitlines(True) | ||
|
||
return contents | ||
|
||
|
||
@generate_skip_decorator(PyCheckerBear) | ||
class PyCheckerBearTest(LocalBearTestHelper): | ||
|
||
def setUp(self): | ||
self.uut = PyCheckerBear(Section('name'), Queue()) | ||
self.good_file = get_testfile_path('good_file.py') | ||
self.bad_file = get_testfile_path('bad_file.py') | ||
self.maxDiff = None | ||
|
||
def test_good_file(self): | ||
self.check_results(self.uut, load_testfiles('good_file.py'), | ||
[], | ||
self.good_file) | ||
|
||
def test_bad_file(self): | ||
self.check_results(self.uut, load_testfiles('bad_file.py'), | ||
[Result.from_values('PyCheckerBear', | ||
'Parameter (c) not used', | ||
self.bad_file, | ||
line=1)], | ||
self.bad_file) | ||
|
||
def test_cli_options(self): | ||
self.check_results(self.uut, load_testfiles('bad_file.py'), | ||
[], | ||
self.bad_file, | ||
settings={'pychecker_cli_options': '--argsused=off'} | ||
) |
Empty file.
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,5 @@ | ||
def multiply(a, b, c): | ||
return a * b | ||
|
||
|
||
result = multiply(1, 2, 3) |
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,5 @@ | ||
def multiply(a, b, c): | ||
return a * b * c | ||
|
||
|
||
result = multiply(1, 2, 3) |