-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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,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() |