[Blends-commit] [SCM] website branch, master, updated. fc36f225bc05067b8829c74cf45070acb818d676
Akshita Jha
akshita-guest at users.alioth.debian.org
Tue Jul 28 18:47:15 UTC 2015
The following commit has been merged in the master branch:
commit fc36f225bc05067b8829c74cf45070acb818d676
Author: Akshita Jha <akshita-guest at users.alioth.debian.org>
Date: Wed Jul 29 00:16:34 2015 +0530
Add test_script.py : Checks for differences between the old tasks files and new tasks files of a blend. Output: webtools_py3/tests/<Blend>/<tasks_file.diff>
diff --git a/webtools_py3/test_output.py b/webtools_py3/test_output.py
new file mode 100755
index 0000000..9dec16a
--- /dev/null
+++ b/webtools_py3/test_output.py
@@ -0,0 +1,146 @@
+#!/usr/bin/python3
+
+import sys
+from os import listdir, makedirs
+from os.path import isfile, isdir, join
+
+from html.parser import HTMLParser
+from html.entities import name2codepoint
+import difflib
+import re
+
+from blendstasktools_udd import ReadConfig
+
+
+# parse the HTML Output
+class BlendsHTMLParser(HTMLParser):
+ def __init__(self):
+ HTMLParser.__init__(self, convert_charrefs=True)
+ self.tmp = ''
+ self.data = []
+
+ def handle_starttag(self, tag, attrs):
+ #self.tmp.append("start_tag : %s" %tag.strip())
+ self.tmp = self.tmp + " <start_tag> : %s" %tag.strip()
+ for attr in attrs:
+ #self.tmp.append("attr : %s" %str(attr).strip())
+ self.tmp = self.tmp + " <attr> : %s" %str(attr).strip()
+
+ def handle_endtag(self, tag):
+ #self.tmp.append("end_tag : %s" %tag.strip())
+ self.tmp = self.tmp + " <end_tag> : %s" %tag.strip()
+ self.data.append(self.tmp)
+ self.tmp = ''
+
+ def handle_data(self, data):
+ #self.tmp.append("data : %s" %data.strip())
+ self.tmp = self.tmp + " <data> : %s" %data.strip()
+
+ def handle_comment(self, data):
+ #self.tmp.append("comment : %s" %data.strip())
+ self.tmp = self.tmp + " <comment> : %s" %data.strip()
+
+ def handle_decl(self, data):
+ #self.tmp.append("decl : %s" %data.strip())
+ self.tmp = self.tmp + " <decl> : %s" %data.strip()
+
+
+# check the differencce in the task files
+def check_diff(blend, tasks_files, outputdir):
+
+ for f in tasks_files:
+ fp = open(outputdir+'/tasks/'+f)
+ old_html = fp.read()
+ fp.close()
+
+ fp = open(outputdir+'/tasks_udd/'+f)
+ new_html = fp.read()
+ fp.close()
+
+ tmp_dir = './tests/' + blend + "/"
+ if not isdir(tmp_dir):
+ makedirs(tmp_dir)
+
+ # create a .diff file which contains the differences
+ tmp_diff = tmp_dir + f + '.diff'
+
+ # final_old_data is a list containing parsed old task files data
+ parser1 = BlendsHTMLParser()
+ parser1.feed(old_html)
+ old_data = parser1.data
+ final_old_data = []
+ for od in old_data:
+ tmp = ''
+ if od != '':
+ tmp = re.sub('\s+',' ',od) + '\n' # remove extra spaces
+ if tmp != ' ' or tmp != '' or tmp != '\n':
+ final_old_data.append(tmp)
+
+ # final_new_data is a list containing parsed new task files data
+ parser2 = BlendsHTMLParser()
+ parser2.feed(new_html)
+ new_data = parser2.data
+ final_new_data = []
+ for nd in new_data:
+ tmp = ''
+ if nd != '':
+ tmp = re.sub('\s+',' ',nd) + '\n' # remove extra spaces
+ if tmp != ' ' or tmp != '' or tmp != '\n':
+ final_new_data.append(tmp)
+
+
+ if final_old_data == final_new_data:
+ print("Both the task files are identical")
+
+
+ fp = open(tmp_diff,'w')
+ lines = []
+ for line in difflib.unified_diff(old_data, new_data, fromfile='tasks/'+f, tofile='tasks_udd/'+f, lineterm=""):
+ line = line + '\n'
+ lines.append(line)
+
+ fp.writelines(lines)
+ fp.close()
+
+
+# get the names of tasks files in dir_path
+def task_file(dir_path):
+ tasks_files = []
+ if isdir(dir_path):
+ for f in listdir(dir_path):
+ if isfile(join(dir_path, f)):
+ tmp = f.split('.')
+ # get names of task files which are in english
+ if tmp[1] == 'en':
+ tasks_files.append(f)
+ else:
+ print("%s is not a file " %f)
+ else:
+ print("%s is not a directory" %dir_path)
+ return tasks_files
+
+
+def main():
+ if len(sys.argv) <= 1:
+ print("Usage: ./test_output.py <Blend>\nOutput directory : ./tests/<Blend>/<task_file.diff>")
+ exit(-1)
+
+ blend = sys.argv[1]
+
+ data = ReadConfig(blend)
+ outputdir = data['outputdir']
+
+ # get names of old task files
+ old_tasks_files = task_file(outputdir + '/tasks')
+ # get names of new task files
+ new_tasks_files = task_file(outputdir + '/tasks_udd')
+
+ # check whether the tasks files created are same or not
+ if old_tasks_files == new_tasks_files:
+ check_diff(blend, new_tasks_files, outputdir)
+ else:
+ print('Tasks files created are not the same')
+
+
+if __name__ == '__main__':
+ main()
--
Static and dynamic websites for Debian Pure Blends
More information about the Blends-commit
mailing list