Merge test folder of test branch
[iotivity.git] / test / test_manager / result_reporter.py
1 #!/usr/bin/python3
2 '''
3 /******************************************************************
4 *
5 * Copyright 2018 Samsung Electronics All Rights Reserved.
6 *
7 *
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ******************************************************************/
22 '''
23
24 import time
25 import os
26 from time import strftime
27 import shutil
28
29 import sys
30
31 from configuration import *
32
33 from ite.tc.xmlanalyzer import TCXMLAnalyzer
34 from ite.tc.container import TestSpecContainer
35 from ite.reporter.tc_reporter import TestSpecReporter
36 from ite.reporter.result_reporter import TestResultReporter
37
38 XLSX_FILE_NAME = "TestResult.xlsx"
39
40 print("### Start to Make Test Result Report")
41
42 folder_prefix = ""
43
44 run_dir = TEST_RESULT_RUN_DIR
45 if len(sys.argv) > 1:
46     run_dir = sys.argv[1]
47
48 if len(sys.argv) > 2:
49     folder_prefix = sys.argv[2].upper() + "_"
50
51 timestring = strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))
52 if os.path.exists(run_dir):
53     result_dir = os.path.join(TEST_RESULT_DIR, folder_prefix + "TestResult_" + timestring)
54     shutil.move(run_dir, result_dir)
55 else:
56     print("### Can't find Result Source Dir: " + run_dir)
57     raise SystemExit(1)
58
59 testspec_path = os.path.join(result_dir, TEST_SPEC_XML_FOR_RESULT)
60 testspec_data = None
61
62 if not os.path.exists(testspec_path):
63     if os.path.exists(API_TC_SRC_DIR):
64         container = TestSpecContainer()
65         container.extract_api_testspec(API_TC_SRC_DIR, '')
66         reporter = TestSpecReporter()
67         reporter.generate_testspec_report(container.data)
68         reporter.report('XML', testspec_path)
69
70 if os.path.exists(testspec_path):
71     container = TCXMLAnalyzer()
72     container.read_spec_xml(testspec_path)
73     testspec_data = container.data
74 else:
75     print ('Unable to generate report. Problem with Testspec file')
76     exit(-1)
77
78 report_name = "TestResult_" + timestring + ".xlsx"
79 reporter = TestResultReporter()
80 reporter.generate_testresult_report(result_dir, testspec_data)
81 reporter.report_to_xlsx(os.path.join(result_dir, report_name))
82
83 def clear_create_folder(name):
84     new_dir = os.path.join(result_dir, name)
85     if os.path.exists(new_dir):
86         shutil.rmtree(new_dir)
87     os.makedirs(new_dir)
88
89     return new_dir
90
91 reporter.report_fail_result_to_txt(clear_create_folder("Failed"))
92 reporter.report_pass_result_to_txt(clear_create_folder("Pass"))
93
94 print("Making Test Result Report is Done!!")