From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 8F39537A4 for ; Thu, 4 Aug 2016 07:38:37 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP; 03 Aug 2016 22:38:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,469,1464678000"; d="scan'208";a="150373602" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga004.fm.intel.com with ESMTP; 03 Aug 2016 22:38:36 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u745cY9L003571; Thu, 4 Aug 2016 13:38:34 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u745cW4n012741; Thu, 4 Aug 2016 13:38:34 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u745cWpL012737; Thu, 4 Aug 2016 13:38:32 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Thu, 4 Aug 2016 13:38:17 +0800 Message-Id: <1470289102-12677-5-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1470289102-12677-1-git-send-email-yong.liu@intel.com> References: <1470289102-12677-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 4/9] framework rst: add class to handle RST report X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Aug 2016 05:38:38 -0000 Each suite will generate its own rst report. So add new class to support that. Signed-off-by: Marvin Liu diff --git a/framework/rst.py b/framework/rst.py index 9b8eb69..ef1825c 100644 --- a/framework/rst.py +++ b/framework/rst.py @@ -30,9 +30,9 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os -import dts import shutil import re +from exception import VerifyFailure """ Generate Rst Test Result Report @@ -54,108 +54,108 @@ Result: path2Plan = 'test_plans' path2Result = 'output' -rstName = "" -rstAnnexName = "" - - -def generate_results_rst(crbName, target, nic, suite, perf=False): - """ - copy desc from #Name#_test_plan.rst to TestResult_#Name#.rst - """ - global rstName, rstAnnexName - - try: - path = [path2Result, crbName, target, nic] - # ensure the level folder exist - for node in range(0, len(path)): - if not os.path.exists('/'.join(path[:node + 1])): - for level in range(node, len(path)): - os.mkdir('/'.join(path[:level + 1])) - break - - rstName = "%s/TestResult_%s.rst" % ('/'.join(path), suite) - rstReport = open(rstName, 'w') - - if perf is True: - rstAnnexName = "%s/TestResult_%s_Annex.rst" % ('/'.join(path), suite) - rstAnnexReport = open(rstAnnexName, 'w') - - f = open("%s/%s_test_plan.rst" % (path2Plan, suite), 'r') - for line in f: - if line[:13] == "Prerequisites": - break - rstReport.write(line) - if perf is True: - rstAnnexReport.write(line) - f.close() - - rstReport.close() - - except Exception as e: - raise dts.VerifyFailure("RST Error: " + str(e)) - - -def clear_all_rst(crbName, target): - path = [path2Result, crbName, target] - shutil.rmtree('/'.join(path), True) - - -def write_title(text): - """ - write case title Test Case: #Name# - ----------------- - """ - line = "\n%s\n" % text - with open(rstName, "a") as f: - f.write(line) - f.write('-' * len(line) + '\n') - -def write_annex_title(text): - """ - write annex to test case title Annex to #Name# - ----------------- - """ - line = "\n%s\n" % text - with open(rstAnnexName, "a") as f: - f.write(line) - f.write('-' * len(line) + '\n') +class RstReport(object): -def write_text(text, annex=False): + def __init__(self, crbName, target, nic, suite, perf=False): + """ + copy desc from #Name#_test_plan.rst to TestResult_#Name#.rst + """ + try: + path = [path2Result, crbName, target, nic] + # ensure the level folder exist + for node in range(0, len(path)): + if not os.path.exists('/'.join(path[:node + 1])): + for level in range(node, len(path)): + os.mkdir('/'.join(path[:level + 1])) + break - rstFile = rstAnnexName if annex else rstName + self.rstName = "%s/TestResult_%s.rst" % ('/'.join(path), suite) + rstReport = open(self.rstName, 'w') - with open(rstFile, "a") as f: - f.write(text) - - -def write_frame(text, annex=False): - write_text("\n::\n\n", annex) - parts = re.findall(r'\S+', text) - text = "" - length = 0 - - for part in parts: - if length + len(part) > 75: - text = text + "\n" + " " + part - length = len(part) + if perf is True: + self.rstAnnexName = "%s/TestResult_%s_Annex.rst" % ( + '/'.join(path), suite) + rstAnnexReport = open(self.rstAnnexName, 'w') + + f = open("%s/%s_test_plan.rst" % (path2Plan, suite), 'r') + for line in f: + if line[:13] == "Prerequisites": + break + rstReport.write(line) + if perf is True: + rstAnnexReport.write(line) + f.close() + + rstReport.close() + + except Exception as e: + raise VerifyFailure("RST Error: " + str(e)) + + def clear_all_rst(self, crbName, target): + path = [path2Result, crbName, target] + shutil.rmtree('/'.join(path), True) + + def write_title(self, text): + """ + write case title Test Case: #Name# + ----------------- + """ + line = "\n%s\n" % text + with open(self.rstName, "a") as f: + f.write(line) + f.write('-' * len(line) + '\n') + + def write_annex_title(self, text): + """ + write annex to test case title Annex to #Name# + ----------------- + """ + line = "\n%s\n" % text + with open(self.rstAnnexName, "a") as f: + f.write(line) + f.write('-' * len(line) + '\n') + + def write_text(self, text, annex=False): + rstFile = self.rstAnnexName if annex else self.rstName + + with open(rstFile, "a") as f: + f.write(text) + + def write_frame(self, text, annex=False): + self.write_text("\n::\n\n", annex) + parts = re.findall(r'\S+', text) + text = "" + length = 0 + + for part in parts: + if length + len(part) > 75: + text = text + "\n" + " " + part + length = len(part) + else: + length = length + len(part) + text = text + " " + part + self.write_text(text, annex) + self.write_text("\n\n", annex) + + def write_result(self, result): + with open(self.rstName, "a") as f: + f.write("\nResult: " + result + "\n") + + def include_image(self, image, width=90): + """ + Includes an image in the RST file. + The argument must include path, name and extension. + """ + with open(self.rstName, "a") as f: + f.write(".. image:: %s\n :width: %d%%\n\n" % (image, width)) + + def report(self, text, frame=False, annex=False): + """ + Save report text into rst file. + """ + if frame: + self.write_frame(text, annex) else: - length = length + len(part) - text = text + " " + part - write_text(text, annex) - write_text("\n\n", annex) - - -def write_result(result): - with open(rstName, "a") as f: - f.write("\nResult: " + result + "\n") - - -def include_image(image, width=90): - """ - Includes an image in the RST file. - The argument must include path, name and extension. - """ - with open(rstName, "a") as f: - f.write(".. image:: %s\n :width: %d%%\n\n" % (image, width)) + self.write_text(text, annex) -- 1.9.3