Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for code quality #72

Merged
merged 3 commits into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
61 changes: 61 additions & 0 deletions pydatastructs/utils/tests/test_code_quality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os, re, sys

def _list_files():
root_path = os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
os.pardir, os.pardir))
py_files = []
for (dirpath, _, filenames) in os.walk(root_path):
for _file in filenames:
if re.match(r".*\.py$", _file):
py_files.append(os.path.join(dirpath, _file))
return py_files

def test_trailing_white_spaces():
py_files = _list_files()
for file_path in py_files:
file = open(file_path, "r")
line = file.readline()
while line != "":
if line.endswith(" \n") or line.endswith("\t\n") \
or line.endswith(" ") or line.endswith("\t"):
assert False, "%s contains trailing whitespace at %s"\
%(file_path, line)
line = file.readline()
file.close()

def test_final_new_lines():
py_files = _list_files()
for file_path in py_files:
file = open(file_path, "r")
lines = []
line = file.readline()
while line != "":
lines.append(line)
line = file.readline()
if lines:
if lines[-1][-1] != "\n":
assert False, "%s doesn't contain new line at the end."%(file_path)
if lines[-1] == "\n" and lines[-2][-1] == "\n":
assert False, "%s contains multiple new lines at the end."%(file_path)
file.close()

def test_comparison_True_False_None():
py_files = _list_files()
for file_path in py_files:
if file_path.find("test_code_quality.py") == -1:
file = open(file_path, "r")
line = file.readline()
while line != "":
if ((line.find("== True") != -1) or
(line.find("== False") != -1) or
(line.find("== None") != -1) or
(line.find("!= True") != -1) or
(line.find("!= False") != -1) or
(line.find("!= None") != -1)):
assert False, "%s compares True/False/None using by "\
"value, should be done by reference at %s"\
%(file_path, line)
line = file.readline()
file.close()