Skip to content

Commit

Permalink
Added tests for code quality (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 authored Dec 29, 2019
1 parent 6ecac89 commit 15a1dbb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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()

0 comments on commit 15a1dbb

Please sign in to comment.