test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH 4/9] framework rst: add class to handle RST report
Date: Thu,  4 Aug 2016 13:38:17 +0800	[thread overview]
Message-ID: <1470289102-12677-5-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1470289102-12677-1-git-send-email-yong.liu@intel.com>

Each suite will generate its own rst report. So add new class to support
that.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

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

  parent reply	other threads:[~2016-08-04  5:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  5:38 [dts] [PATCH 0/9] optimize overall execution process Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 1/9] framework dts: optimize " Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 2/9] framework config: add concept for dut board Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 3/9] framework dut: remove dependency on dts module Marvin Liu
2016-08-04  5:38 ` Marvin Liu [this message]
2016-08-04  5:38 ` [dts] [PATCH 5/9] framework settings: support global setting load and save Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 6/9] framework test_result: add class to handle result Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 7/9] framework test_case: add test case handle logic Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 8/9] framework utils: move shared function from dts module Marvin Liu
2016-08-04  5:38 ` [dts] [PATCH 9/9] tests: remove dependencies of " Marvin Liu
2016-08-04  6:07 ` [dts] [PATCH 0/9] optimize overall execution process Liu, Yong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470289102-12677-5-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).