Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Put in place a bit better integration tests

Now all testscripts are run and the result of cleanjs is
compared to an expected result
  • Loading branch information...
commit d07fd37eb33e5b9f319c1967c5dd24ef6186e511 1 parent 9b175bc
Patrick Brosset authored
View
2  .gitignore
@@ -1,2 +1,2 @@
*.pyc
-tests/scripts/reports/*.html
+testscripts/reports/*.html
View
15 cleanjs_cmdline.py
@@ -11,6 +11,17 @@
# This tool works on the command line, so needs to use commant line arguments
import sys
+
+if len(sys.argv) != 3:
+ print ""
+ print "This command line tool requires 2 arguments:"
+ print " - the javascript file path to be checked"
+ print " - the path and filename of the report HTML file that will be created"
+ print ""
+ print "Usage example: $ python cleanjs_cmdline.py path/to/myFile.js path/to/myFileReport.html"
+ print ""
+ exit()
+
file_name = sys.argv[1]
report_name = sys.argv[2]
@@ -24,4 +35,6 @@
# Displaying the messages to an output
from reporters import htmlwithcode
-htmlwithcode.output_messages(result, file_data, report_name)
+htmlwithcode.output_messages(result, file_data, report_name)
+
+print "Your file has been cleanjs'd! Check the report here " + report_name
View
1  reviewers/general.py
@@ -81,6 +81,7 @@ def review(self, file_data, message_bag):
# Tricking the PYTHONPATH because relative imports don't work when running the file standalone
import sys
+ sys.path.append("./")
sys.path.append("../")
# Creating the reviewer instance, giving it the parsed file
View
17 reviewers/helpers/wordmeaning.py
@@ -88,10 +88,11 @@ def check_word_meaning_in_remote_dict(word):
if __name__ == "__main__":
import os
- assert check_word_meaning_in_remote_dict("test") == True, 1
- assert check_word_meaning_in_remote_dict("mgr") == False, 2
- assert check_word_meaning_in_remote_dict("ouhgzoihg") == False, 3
- assert check_word_meaning_in_remote_dict("chicken") == True, 4
+ # TODO: turn these off for now, this is too slow for running unit tests
+ #assert check_word_meaning_in_remote_dict("test") == True, 1
+ #assert check_word_meaning_in_remote_dict("mgr") == False, 2
+ #assert check_word_meaning_in_remote_dict("ouhgzoihg") == False, 3
+ #assert check_word_meaning_in_remote_dict("chicken") == True, 4
# FIXME: apparently first need to create the file with "w" mode, and then open it for read/write
mock_dict_file = open("unit_test_mock_file.txt", "w")
@@ -105,10 +106,10 @@ def check_word_meaning_in_remote_dict(word):
assert check_word_meaning_in_local_dict("test", dictionary_file=mock_dict_file) == True, 7
- assert check_word_meaning_with_dict("something", dictionary_file=mock_dict_file) == True, 8
- assert check_word_meaning_with_dict("function", dictionary_file=mock_dict_file) == True, 9
- assert check_word_meaning_with_dict("nooooooo", dictionary_file=mock_dict_file) == False, 10
- assert check_word_meaning_with_dict("table", dictionary_file=mock_dict_file) == True, 11
+ #assert check_word_meaning_with_dict("something", dictionary_file=mock_dict_file) == True, 8
+ #assert check_word_meaning_with_dict("function", dictionary_file=mock_dict_file) == True, 9
+ #assert check_word_meaning_with_dict("nooooooo", dictionary_file=mock_dict_file) == False, 10
+ #assert check_word_meaning_with_dict("table", dictionary_file=mock_dict_file) == True, 11
assert check_word_meaning_with_letter_ratio("cfghtr", dictionary_file=mock_dict_file) == False, 12
assert check_word_meaning_with_letter_ratio("abeciw", dictionary_file=mock_dict_file) == True, 13
View
59 run_tests.py
@@ -0,0 +1,59 @@
+import os
+
+def run_unit_tests(dir):
+ for item in os.listdir(dir):
+ if item[-3:] == ".py" and item[0:8] != "cleanjs_" and item != "run_tests.py" and item != "jsparser.py":
+ os.system("python " + os.path.join(dir, item))
+
+ try:
+ run_unit_tests(os.path.join(dir, item))
+ except:
+ pass
+
+def ensure_dir(dir_name):
+ if not os.path.exists(dir_name):
+ os.makedirs(dir_name)
+
+def run_integration_tests():
+ script_dir = "testscripts"
+ report_dir = script_dir + os.sep + "reports"
+ ensure_dir(report_dir)
+
+ from testscripts import expected
+ expected_results = expected.results
+ actual_results = {}
+
+ for item in os.listdir(script_dir):
+ if item[-3:] == ".js":
+ # Gather data about the file to be reviewed
+ from parsers import fileparser
+ file_data = fileparser.get_file_data_from_file(script_dir + os.sep + item)
+
+ # Review the file
+ from reviewers import reviewer
+ result = reviewer.review(file_data)
+
+ rating = result["rating"]
+ messages = result["message_bag"].get_messages()
+
+ actual_results[item] = {
+ "rating": rating,
+ "messages": []
+ }
+ for m in messages:
+ actual_results[item]["messages"].append({
+ "type": m.type,
+ "reviewer": m.reviewer,
+ "line": m.line
+ })
+
+ assert expected_results == actual_results, "Integration tests did not output the same number or type of messages"
+ print "ALL FILES OK"
+
+print ""
+print "-- RUNNING ALL UNIT TESTS"
+run_unit_tests(".")
+
+print ""
+print "-- RUNNING ALL INTEGRATION TESTS"
+run_integration_tests()
View
32 tests/runtests.py
@@ -1,32 +0,0 @@
-import os
-
-def run_unit_tests(dir):
- for item in os.listdir(dir):
- if item[-3:] == ".py" and item[0:8] != "cleanjs_" and item != "runtests.py" and item != "jsparser.py":
- os.system("python " + os.path.join(dir, item))
-
- try:
- run_unit_tests(os.path.join(dir, item))
- except:
- pass
-
-def ensure_dir(dir_name):
- if not os.path.exists(dir_name):
- os.makedirs(dir_name)
-
-def run_full_tests():
- script_dir = "scripts"
- report_dir = script_dir + os.sep + "reports"
- ensure_dir(report_dir)
-
- for item in os.listdir("scripts"):
- if item[-3:] == ".js":
- print "-- RUNNING CLEANJS ON " + item
- os.system("python .." + os.sep + "cleanjs_cmdline.py scripts" + os.sep + item + " " + report_dir + os.sep + item + "-report.html")
-
-print ""
-print "-- RUNNING ALL UNIT TETS"
-run_unit_tests("..")
-
-print ""
-run_full_tests()
View
0  tests/scripts/CommentedClass.js → testscripts/CommentedClass.js
File renamed without changes
View
0  tests/scripts/ImageResizer.js → testscripts/ImageResizer.js
File renamed without changes
View
0  tests/scripts/SmartInputDetector.js → testscripts/SmartInputDetector.js
File renamed without changes
View
0  testscripts/__init__.py
No changes.
View
887 testscripts/expected.py
@@ -0,0 +1,887 @@
+results = {
+ "CommentedClass.js": {
+ "rating": "A",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 5
+ }
+ ]
+ },
+ "gettersetter.js": {
+ "rating": "A+",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ }
+ ]
+ },
+ "goodfile.js": {
+ "rating": "A+",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 2
+ }
+ ]
+ },
+ "ImageResizer.js": {
+ "rating": "B",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 5
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 22
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 28
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 28
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 46
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 54
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 54
+ }
+ ]
+ },
+ "simple.js": {
+ "rating": "F-",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 4
+ },
+ {
+ "type": "error",
+ "reviewer": "comments",
+ "line": 10
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 10
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 12
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 17
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 17
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 17
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 18
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 22
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 24
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 24
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 24
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 26
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 26
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 28
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 30
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": 33
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 36
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 43
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 43
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 43
+ },
+ {
+ "type": "error",
+ "reviewer": "complexity",
+ "line": 47
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 49
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 50
+ },
+ {
+ "type": "error",
+ "reviewer": "comments",
+ "line": 50
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 58
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 59
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 64
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 69
+ }
+ ]
+ },
+ "SmartInputDetector.js": {
+ "rating": "B",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 10
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 32
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 43
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 43
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 58
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 63
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 63
+ }
+ ]
+ },
+ "sproutcore-ajax.js": {
+ "rating": "F-",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 1
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 1
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 1
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 6
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 27
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 29
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 29
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 43
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 52
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": 71
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 133
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 150
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": 158
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 165
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 165
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 169
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 179
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 179
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 179
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 193
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 193
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 193
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 203
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 203
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 203
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 214
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 214
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 214
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 217
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 217
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 225
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 235
+ },
+ {
+ "type": "warning",
+ "reviewer": "code size",
+ "line": 269
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 269
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 269
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 355
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 360
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 409
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 417
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 423
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 427
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 467
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 541
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 568
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 568
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 572
+ },
+ {
+ "type": "error",
+ "reviewer": "comments",
+ "line": 579
+ },
+ {
+ "type": "warning",
+ "reviewer": "comments",
+ "line": 582
+ },
+ {
+ "type": "warning",
+ "reviewer": "complexity",
+ "line": 601
+ }
+ ]
+ },
+ "syntaxerror.js": {
+ "rating": "C+",
+ "messages": [
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "info",
+ "reviewer": "general",
+ "line": None
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "code size",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "comments",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "naming",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "unused",
+ "line": 1
+ },
+ {
+ "type": "error",
+ "reviewer": "syntax",
+ "line": 11
+ }
+ ]
+ }
+}
View
0  tests/scripts/gettersetter.js → testscripts/gettersetter.js
File renamed without changes
View
0  tests/scripts/goodfile.js → testscripts/goodfile.js
File renamed without changes
View
0  tests/scripts/simple.js → testscripts/simple.js
File renamed without changes
View
0  tests/scripts/sproutcore-ajax.js → testscripts/sproutcore-ajax.js
File renamed without changes
View
0  tests/scripts/syntaxerror.js → testscripts/syntaxerror.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.