[Fuego] [PATCH 2/3] ftc: gen-report: Make format for name of test report file

Hoang Van Tuyen tuyen.hoangvan at toshiba-tsdv.com
Tue Mar 13 10:16:02 UTC 2018


The format for name of test report file is
Test_report_${value_of_where_option}_${time}.${format_of_test_report}

Signed-off-by: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
---
  engine/scripts/ftc | 32 ++++++++++++++++++++++----------
  1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index 7fa0333..c1a2887 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -2071,14 +2071,14 @@ def add_page_number(canvas, doc):
      text = "Page %s" % page_num
      canvas.drawRightString(200*mm, 20*mm, text)

-def gen_pdf_report(header_data, report_data, report_dir):
+def gen_pdf_report(header_data, report_data, report_file):
      from reportlab.lib import colors
      from reportlab.lib.pagesizes import A4
      from reportlab.lib.styles import getSampleStyleSheet
      from reportlab.platypus import SimpleDocTemplate, Table, 
TableStyle, Paragraph

      # create a pdf file
-    doc = SimpleDocTemplate(report_dir + "report.pdf", pagesize=A4)
+    doc = SimpleDocTemplate(report_file, pagesize=A4)
      elements = []

      # generate header
@@ -2125,7 +2125,7 @@ def excel_column_name(n):
          name = chr(r + ord('A')) + name
      return name

-def gen_excel_report(header_data, report_data, report_dir):
+def gen_excel_report(header_data, report_data, report_file):
      from openpyxl import Workbook
      from openpyxl.style import Fill, Color

@@ -2164,14 +2164,13 @@ def gen_excel_report(header_data, report_data, 
report_dir):
workbook.remove_sheet(workbook.get_sheet_by_name("Sheet"))

      # save the report
-    workbook.save(report_dir + "report.xlsx")
+    workbook.save(report_file)

-def gen_csv_report(header_data, report_data, report_dir):
+def gen_csv_report(header_data, report_data, report_file):
      import csv

-    filename = report_dir + "report.csv"
      # generate header
-    with open(filename, "wb") as report:
+    with open(report_file, "wb") as report:
          writer = csv.writer(report)
          writer.writerows(header_data)

@@ -2238,6 +2237,19 @@ def do_gen_report(conf, options):
          # make we cannot create a directory.
          error_out("Invalid report directory '%s'" % report_dir)

+    # create name of test report file with format Test_report_testname_time
+    test_file_name = "Test_report_" + time.strftime("%Y-%m-%d_%H-%M-%S")
+    if "--where" in options:
+        test_file_name = "Test_report_" + 
options[options.index("--where")+1] + \
+                         "_" + time.strftime("%Y-%m-%d_%H-%M-%S")
+
+    # report_file includes the report_dir, test_file_name and fmt
+    # always include "/" to make sure the test_file_name into report_dir
+    if fmt == "excel":
+        report_file = report_dir + "/" + test_file_name + "." + "xlsx"
+    else:
+        report_file = report_dir + "/" + test_file_name + "." + fmt
+
      # get data for report
      header_data = get_report_header_data(run_list, run_map, header_fields)
      report_data = get_report_data(run_list, run_map, fields)
@@ -2247,13 +2259,13 @@ def do_gen_report(conf, options):
      if fmt=="html":
          report = gen_html_report(header_data, report_data)
      if fmt=="pdf":
-        gen_pdf_report(header_data, report_data, report_dir)
+        gen_pdf_report(header_data, report_data, report_file)
          sys.exit(0)
      if fmt=="excel":
-        gen_excel_report(header_data, report_data, report_dir)
+        gen_excel_report(header_data, report_data, report_file)
          sys.exit(0)
      if fmt=="csv":
-        gen_csv_report(header_data, report_data, report_dir)
+        gen_csv_report(header_data, report_data, report_file)
          sys.exit(0)

      print report
-- 
2.1.4

_______________________________________________
Fuego mailing list
Fuego at lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/fuego

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/fuego/attachments/20180313/86252acc/attachment.html>
-------------- next part --------------
From 8212da5dc47f7e99d949fc219c5a8da6cda4cddb Mon Sep 17 00:00:00 2001
From: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
Date: Tue, 13 Mar 2018 16:10:35 +0700
Subject: [PATCH 2/3] ftc: gen-report: Make format for name of test report file

The format for name of test report file is
Test_report_${value_of_where_option}_${time}.${format_of_test_report}

Signed-off-by: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
---
 engine/scripts/ftc | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index 7fa0333..c1a2887 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -2071,14 +2071,14 @@ def add_page_number(canvas, doc):
     text = "Page %s" % page_num
     canvas.drawRightString(200*mm, 20*mm, text)
 
-def gen_pdf_report(header_data, report_data, report_dir):
+def gen_pdf_report(header_data, report_data, report_file):
     from reportlab.lib import colors
     from reportlab.lib.pagesizes import A4
     from reportlab.lib.styles import getSampleStyleSheet
     from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
 
     # create a pdf file
-    doc = SimpleDocTemplate(report_dir + "report.pdf", pagesize=A4)
+    doc = SimpleDocTemplate(report_file, pagesize=A4)
     elements = []
 
     # generate header
@@ -2125,7 +2125,7 @@ def excel_column_name(n):
         name = chr(r + ord('A')) + name
     return name
 
-def gen_excel_report(header_data, report_data, report_dir):
+def gen_excel_report(header_data, report_data, report_file):
     from openpyxl import Workbook
     from openpyxl.style import Fill, Color
 
@@ -2164,14 +2164,13 @@ def gen_excel_report(header_data, report_data, report_dir):
         workbook.remove_sheet(workbook.get_sheet_by_name("Sheet"))
 
     # save the report
-    workbook.save(report_dir + "report.xlsx")
+    workbook.save(report_file)
 
-def gen_csv_report(header_data, report_data, report_dir):
+def gen_csv_report(header_data, report_data, report_file):
     import csv
 
-    filename = report_dir + "report.csv"
     # generate header
-    with open(filename, "wb") as report:
+    with open(report_file, "wb") as report:
         writer = csv.writer(report)
         writer.writerows(header_data)
 
@@ -2238,6 +2237,19 @@ def do_gen_report(conf, options):
         # make we cannot create a directory.
         error_out("Invalid report directory '%s'" % report_dir)
 
+    # create name of test report file with format Test_report_testname_time
+    test_file_name = "Test_report_" + time.strftime("%Y-%m-%d_%H-%M-%S")
+    if "--where" in options:
+        test_file_name = "Test_report_" + options[options.index("--where")+1] + \
+                         "_" + time.strftime("%Y-%m-%d_%H-%M-%S")
+
+    # report_file includes the report_dir, test_file_name and fmt
+    # always include "/" to make sure the test_file_name into report_dir
+    if fmt == "excel":
+        report_file = report_dir + "/" + test_file_name + "." + "xlsx"
+    else:
+        report_file = report_dir + "/" + test_file_name + "." + fmt
+
     # get data for report
     header_data = get_report_header_data(run_list, run_map, header_fields)
     report_data = get_report_data(run_list, run_map, fields)
@@ -2247,13 +2259,13 @@ def do_gen_report(conf, options):
     if fmt=="html":
         report = gen_html_report(header_data, report_data)
     if fmt=="pdf":
-        gen_pdf_report(header_data, report_data, report_dir)
+        gen_pdf_report(header_data, report_data, report_file)
         sys.exit(0)
     if fmt=="excel":
-        gen_excel_report(header_data, report_data, report_dir)
+        gen_excel_report(header_data, report_data, report_file)
         sys.exit(0)
     if fmt=="csv":
-        gen_csv_report(header_data, report_data, report_dir)
+        gen_csv_report(header_data, report_data, report_file)
         sys.exit(0)
 
     print report
-- 
2.1.4
-------------- next part --------------
-- 
This mail was scanned by BitDefender
For more information please visit http://www.bitdefender.com


More information about the Fuego mailing list