Blame auto_test.py

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