Blame auto_test.py

Packit ae0799
# !/usr/bin/python
Packit ae0799
# -*- coding: UTF-8 -i*-
Packit ae0799
# Copyright (C) 2013-14, Sneha Kore <skore@redhat.com>, Pravin Satpute <psatpute@redhat.com>
Packit ae0799
# This script requires hb-shape utility from available in harfbuzz-devel rpm
Packit ae0799
Packit ae0799
# This program is free software: you can redistribute it and/or modify
Packit ae0799
# it under the terms of the GNU General Public License as published by
Packit ae0799
# the Free Software Foundation, either version 3 of the License, or
Packit ae0799
# (at your option) any later version.
Packit ae0799
Packit ae0799
# This program is distributed in the hope that it will be useful,
Packit ae0799
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae0799
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Packit ae0799
# GNU General Public License for more details.
Packit ae0799
Packit ae0799
# You should have received a copy of the GNU General Public License
Packit ae0799
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Packit ae0799
Packit ae0799
import os,sys,subprocess
Packit ae0799
Packit ae0799
def auto_test(txt_file,ttf_file):
Packit ae0799
	inputfile=open(txt_file)
Packit ae0799
	outputfile=open("failed_test_case.txt","w")
Packit ae0799
Packit ae0799
	#Read the test-case input
Packit ae0799
	flines=inputfile.readlines()
Packit ae0799
	count=0
Packit ae0799
Packit ae0799
	#Exceute hb-shape command for each test-case from output file
Packit ae0799
	for string in flines:
Packit ae0799
		words=string.split()
Packit ae0799
		status, output = subprocess.getstatusoutput("hb-shape %s %s"%(ttf_file,words[0]))
Packit ae0799
		# Test to check, wheather test-case from output file & the result, are matching
Packit ae0799
		if words[1] != output:
Packit ae0799
			print(words[0]+ " [FAILURE]\n")
Packit ae0799
			outputfile.write("  *  "+words[0]+"\t"+""+output+"\n")
Packit ae0799
			count=count+1
Packit ae0799
Packit ae0799
	#Count for failed test-cases
Packit ae0799
	print("%d Test Cases Failed out of %d"%(count,len(flines)))
Packit ae0799
	print("failed_test_case.txt file generated !!")
Packit ae0799
	inputfile.close()
Packit ae0799
	outputfile.close()
Packit ae0799
Packit ae0799
if __name__ == "__main__":
Packit ae0799
Packit ae0799
	if len(sys.argv) < 3:
Packit ae0799
		print(" USAGE: python test.py <test file> <font_file> ")
Packit ae0799
	else:
Packit ae0799
		txt_file = sys.argv[1]
Packit ae0799
		font_file = sys.argv[2]
Packit ae0799
		auto_test(txt_file,font_file)