Permalink
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...
1 parent 9b175bc commit d07fd37eb33e5b9f319c1967c5dd24ef6186e511 Patrick Brosset committed Jan 27, 2012
View
@@ -1,2 +1,2 @@
*.pyc
-tests/scripts/reports/*.html
+testscripts/reports/*.html
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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()
File renamed without changes.
No changes.
Oops, something went wrong. Retry.

0 comments on commit d07fd37

Please sign in to comment.