From 6bcb572b12067f8bea917bd40135b6b10d135cce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20Zingil=C3=A9?= Date: Mon, 8 Dec 2014 17:44:52 +0100 Subject: [PATCH] prevent NoneType if no text in stdout or stderr MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I66fce65024750129fa5bf2ce8eea717e10ef21d0 Signed-off-by: Nicolas Zingilé --- src/result-format | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/result-format b/src/result-format index 9e6a580..f18f9a6 100755 --- a/src/result-format +++ b/src/result-format @@ -42,11 +42,12 @@ def printsatats(xmltree, suitename="", setname=""): Returns: A string with the information """ - stringbuf = "" + stringbuf = "" xpathtotal = "" - xpathpass = "" - xpathfail = "" - xpathna = "" + xpathpass = "" + xpathfail = "" + xpathna = "" + xpathblock = "" if not suitename: xpathtotal = "count(//suite/set/testcase" @@ -56,14 +57,15 @@ def printsatats(xmltree, suitename="", setname=""): else: xpathtotal = "count(//suite[@name='" + suitename + "']/set[@name='" + setname + "']/testcase" - xpathpass = xpathtotal + "[@result='PASS'])" - xpathfail = xpathtotal + "[@result='FAIL'])" - xpathna = xpathtotal + "[@result='N/A'])" + xpathpass = xpathtotal + "[@result='PASS'])" + xpathfail = xpathtotal + "[@result='FAIL'])" + xpathna = xpathtotal + "[@result='N/A'])" + xpathblock = xpathtotal + "[@result='BLOCK'])" xpathtotal += ")" stringbuf += "\nTotal cases : " + str(int((xmltree.xpath(xpathtotal)))) stringbuf += "\nPass cases : " + str(int((xmltree.xpath(xpathpass)))) stringbuf += "\nFail cases : " + str(int((xmltree.xpath(xpathfail)))) - stringbuf += "\nN/A cases : " + str(int((xmltree.xpath(xpathna)))) + stringbuf += "\nN/A cases : " + str(int((xmltree.xpath(xpathna))) + int((xmltree.xpath(xpathblock)))) return stringbuf @@ -120,8 +122,16 @@ def format_result(resultxml, outputdir): filedesc.write('\n\ntest id : ' + atcase.get('id')) filedesc.write('\nobjective : ' + atcase.get('purpose')) filedesc.write('\nresult : ' + atcase.get('result')) - filedesc.write('\nstdout : ' + atcase.find('result_info/stdout').text.decode('string_escape')) - filedesc.write('stderr : ' + atcase.find('result_info/stderr').text.decode('string_escape')) + stdout = atcase.find('result_info/stdout').text + stderr = atcase.find('result_info/stderr').text + if stdout is note None: + filedesc.write('\nstdout : ' + atcase.find('result_info/stdout').text.decode('string_escape')) + else: + filedesc.write('\nstdout : ') + if stderr is not None: + filedesc.write('stderr : ' + atcase.find('result_info/stderr').text.decode('string_escape')) + else: + filedesc.write('\nstderr : ') def main (): parser = argparse.ArgumentParser(description='Tool to convert a testkit xml file in a txt format') -- 2.7.4