Skip to content

Commit 15a1dbb

Browse files
authored
Added tests for code quality (#72)
1 parent 6ecac89 commit 15a1dbb

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

pydatastructs/utils/tests/__init__.py

Whitespace-only changes.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os, re, sys
2+
3+
def _list_files():
4+
root_path = os.path.abspath(
5+
os.path.join(
6+
os.path.split(__file__)[0],
7+
os.pardir, os.pardir))
8+
py_files = []
9+
for (dirpath, _, filenames) in os.walk(root_path):
10+
for _file in filenames:
11+
if re.match(r".*\.py$", _file):
12+
py_files.append(os.path.join(dirpath, _file))
13+
return py_files
14+
15+
def test_trailing_white_spaces():
16+
py_files = _list_files()
17+
for file_path in py_files:
18+
file = open(file_path, "r")
19+
line = file.readline()
20+
while line != "":
21+
if line.endswith(" \n") or line.endswith("\t\n") \
22+
or line.endswith(" ") or line.endswith("\t"):
23+
assert False, "%s contains trailing whitespace at %s"\
24+
%(file_path, line)
25+
line = file.readline()
26+
file.close()
27+
28+
def test_final_new_lines():
29+
py_files = _list_files()
30+
for file_path in py_files:
31+
file = open(file_path, "r")
32+
lines = []
33+
line = file.readline()
34+
while line != "":
35+
lines.append(line)
36+
line = file.readline()
37+
if lines:
38+
if lines[-1][-1] != "\n":
39+
assert False, "%s doesn't contain new line at the end."%(file_path)
40+
if lines[-1] == "\n" and lines[-2][-1] == "\n":
41+
assert False, "%s contains multiple new lines at the end."%(file_path)
42+
file.close()
43+
44+
def test_comparison_True_False_None():
45+
py_files = _list_files()
46+
for file_path in py_files:
47+
if file_path.find("test_code_quality.py") == -1:
48+
file = open(file_path, "r")
49+
line = file.readline()
50+
while line != "":
51+
if ((line.find("== True") != -1) or
52+
(line.find("== False") != -1) or
53+
(line.find("== None") != -1) or
54+
(line.find("!= True") != -1) or
55+
(line.find("!= False") != -1) or
56+
(line.find("!= None") != -1)):
57+
assert False, "%s compares True/False/None using by "\
58+
"value, should be done by reference at %s"\
59+
%(file_path, line)
60+
line = file.readline()
61+
file.close()

0 commit comments

Comments
 (0)