-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matthew Peveler <[email protected]>
- Loading branch information
1 parent
3507550
commit 77ea79e
Showing
5 changed files
with
129 additions
and
77 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Utility functions for the pylint_runner module. | ||
""" | ||
|
||
import os | ||
import re | ||
|
||
|
||
def get_files_from_dir(current_dir, ignore_folders=None): | ||
""" | ||
Recursively walk through a directory and get all python files and then | ||
walk through any potential directories that are found off current | ||
directory, so long as not within self.IGNORE_FOLDERS | ||
:return: all python files that were found off current_dir | ||
""" | ||
if ignore_folders is None: | ||
ignore_folders = [] | ||
|
||
if current_dir[-1] != "/" and current_dir != ".": | ||
current_dir += "/" | ||
|
||
files = [] | ||
|
||
for dir_file in os.listdir(current_dir): | ||
if current_dir != ".": | ||
file_path = current_dir + dir_file | ||
else: | ||
file_path = dir_file | ||
|
||
if os.path.isfile(file_path): | ||
file_split = os.path.splitext(dir_file) | ||
if len(file_split) == 2 and file_split[0] != "" \ | ||
and file_split[1] == ".py": | ||
files.append(file_path) | ||
elif (os.path.isdir(dir_file) or os.path.isdir(file_path)) \ | ||
and dir_file not in ignore_folders: | ||
path = dir_file + os.path.sep | ||
if current_dir not in ["", "."]: | ||
path = os.path.join(current_dir.rstrip(os.path.sep), path) | ||
files += get_files_from_dir(path) | ||
return files | ||
|
||
|
||
def get_pylint_kwargs(pylint_version): | ||
""" Get the correct keyword arguments for the pylint runner. """ | ||
pylint_version = pylint_version.split('.')[:3] | ||
pylint_version[2] = re.sub(r'[a-z-].*', '', pylint_version[2]) | ||
pylint_version = [int(x) for x in pylint_version] | ||
if pylint_version < [2, 5, 1]: | ||
return {"do_exit": False} | ||
return {"exit": False} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
""" | ||
Tests for pylint_runner | ||
""" | ||
|
||
def _assert_list_equals(list1, list2): | ||
assert len(list1) == len(list2) | ||
assert sorted(list1) == sorted(list2) |
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,63 @@ | ||
# pylint: disable=missing-docstring | ||
from pylint_runner.utils import get_files_from_dir, get_pylint_kwargs | ||
|
||
import os | ||
import pytest | ||
from . import _assert_list_equals | ||
|
||
testdata = [ | ||
("1.0.0", {"do_exit": False}), | ||
("2.0.0", {"do_exit": False}), | ||
("2.5.0", {"do_exit": False}), | ||
("2.5.1", {"exit": False}), | ||
("2.5.1-dev", {"exit": False}), | ||
("2.16.0.dev0", {"exit": False}), | ||
("2.6.0", {"exit": False}), | ||
("3.0.0b0", {"exit": False}), | ||
("3.0.0", {"exit": False}), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("value,expected", testdata) | ||
def test_get_pylint_kwargs(value, expected): | ||
assert get_pylint_kwargs(value) == expected | ||
|
||
|
||
def test_get_files(): | ||
# make sure we use root of pylint_runner module | ||
os.chdir(os.path.dirname(os.path.realpath(__file__)) + '/../') | ||
actual = get_files_from_dir(os.curdir) | ||
expected = [ | ||
'pylint_runner/__init__.py', | ||
'pylint_runner/main.py', | ||
'pylint_runner/utils.py', | ||
'setup.py', | ||
'tests/__init__.py', | ||
'tests/test_runner.py', | ||
'tests/test_utils.py', | ||
'tests/tests/dummy.py' | ||
] | ||
_assert_list_equals(expected, actual) | ||
|
||
|
||
def test_get_files_current_dir(): | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
actual = get_files_from_dir(path) | ||
expected = [ | ||
path + '/__init__.py', | ||
path + '/test_runner.py', | ||
path + '/test_utils.py', | ||
path + '/tests/dummy.py' | ||
] | ||
_assert_list_equals(expected, actual) | ||
|
||
|
||
def test_get_files_ignore(): | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
actual = get_files_from_dir(path, ignore_folders=['tests']) | ||
expected = [ | ||
path + '/__init__.py', | ||
path + '/test_runner.py', | ||
path + '/test_utils.py' | ||
] | ||
_assert_list_equals(expected, actual) |