0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import sys, os, shutil, unittest
|
3
|
18 |
|
0
|
19 |
from testautomation.base_testcase import BaseTestCase
|
|
20 |
from testautomation import zip_dir
|
|
21 |
from scripttest_common import get_cmd
|
|
22 |
|
|
23 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
24 |
TEMP_DIR = os.path.normpath(os.path.join(ROOT_PATH, 'temp/report'))
|
|
25 |
TESTDATA_DIR = os.path.normpath(os.path.join(ROOT_PATH, 'testdata/report'))
|
|
26 |
TEST_PROJECT = os.path.normpath(os.path.join(TESTDATA_DIR, 'project'))
|
|
27 |
|
|
28 |
|
|
29 |
class TestReport(BaseTestCase):
|
|
30 |
|
|
31 |
def _test_get_help(self):
|
|
32 |
cmd = '%s -h' % get_cmd('report')
|
|
33 |
out = self.run_command(cmd)
|
3
|
34 |
lines = out.split(os.linesep)
|
0
|
35 |
self.assertTrue('Options:' in lines)
|
|
36 |
self.assertTrue(' Report options:' in lines)
|
|
37 |
|
|
38 |
def test_generate_data_files_and_create_reports(self):
|
|
39 |
TEST_DIR = 'test1/'
|
|
40 |
|
|
41 |
_, datafile_rofs3 = self.generate(TEST_DIR + 'out-rofs3', TEST_DIR + 'repdata/rofs3.dat', 'rofs3')
|
|
42 |
_, datafile_uda = self.generate(TEST_DIR + 'out-uda', TEST_DIR + 'repdata/uda.dat', 'uda')
|
|
43 |
|
|
44 |
REPORTS_DIR = os.path.join(TEMP_DIR, TEST_DIR + 'reports')
|
|
45 |
self.create_report([datafile_rofs3], os.path.join(REPORTS_DIR, 'rofs3.txt'))
|
|
46 |
self.create_report([datafile_uda], os.path.join(REPORTS_DIR, 'uda.txt'))
|
|
47 |
self.create_report([datafile_rofs3, datafile_uda], os.path.join(REPORTS_DIR, 'both.txt'))
|
|
48 |
|
|
49 |
EXPECTED_DIR = os.path.join(TESTDATA_DIR, 'expected')
|
|
50 |
self.assert_dir_contents_equal(EXPECTED_DIR, REPORTS_DIR, ['.svn'])
|
|
51 |
|
|
52 |
# Create by giving the directory as input and check
|
|
53 |
REPORT_FILE = os.path.join(TEMP_DIR, TEST_DIR, 'both_from_dir.txt')
|
|
54 |
EXPECTED_FILE = os.path.join(EXPECTED_DIR, 'both.txt')
|
|
55 |
self.create_report_from_dir(os.path.join(TEMP_DIR, TEST_DIR, 'repdata'), REPORT_FILE)
|
|
56 |
self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
|
|
57 |
|
|
58 |
def generate(self, output_dir, report_data_file, target_tag):
|
|
59 |
"""
|
|
60 |
Generate output into the given output directory and report data file.
|
|
61 |
@return: Tuple containing the absolute paths to the output directory
|
|
62 |
and report data file.
|
|
63 |
"""
|
|
64 |
OUTPUT_DIR = os.path.join(TEMP_DIR, output_dir)
|
|
65 |
REPORT_DATA_FILE = os.path.join(TEMP_DIR, report_data_file)
|
|
66 |
self.remove_if_exists(OUTPUT_DIR)
|
|
67 |
|
3
|
68 |
cmd = '%s -p "%s" -o "%s" --log-file="%s" --report-data-output "%s" --impl-tag target:%s' \
|
|
69 |
% (get_cmd('generate'), TEST_PROJECT, OUTPUT_DIR, os.path.join(OUTPUT_DIR,'cone.log'), REPORT_DATA_FILE, target_tag)
|
0
|
70 |
self.run_command(cmd)
|
|
71 |
self.assert_exists_and_contains_something(OUTPUT_DIR)
|
|
72 |
self.assert_exists_and_contains_something(REPORT_DATA_FILE)
|
|
73 |
|
|
74 |
return OUTPUT_DIR, REPORT_DATA_FILE
|
|
75 |
|
|
76 |
def create_report(self, report_data_files, report_file):
|
|
77 |
"""
|
|
78 |
Create a report based on a number of input data files.
|
|
79 |
@return: Absolute path to the created report.
|
|
80 |
"""
|
|
81 |
TEMPLATE_FILE = os.path.join(TESTDATA_DIR, 'template.txt')
|
|
82 |
REPORT_FILE = os.path.join(TEMP_DIR, report_file)
|
|
83 |
self.remove_if_exists(REPORT_FILE)
|
|
84 |
|
3
|
85 |
cmd = '%s --report "%s" --log-file="%s" --template "%s" ' % (get_cmd('report'),
|
|
86 |
REPORT_FILE,
|
|
87 |
os.path.join(TEMP_DIR,'cone_report.log'),
|
|
88 |
TEMPLATE_FILE)
|
0
|
89 |
cmd += ' '.join(['--input-data "%s"' % f for f in report_data_files])
|
|
90 |
self.run_command(cmd)
|
|
91 |
self.assert_exists_and_contains_something(REPORT_FILE)
|
|
92 |
return REPORT_FILE
|
|
93 |
|
|
94 |
def create_report_from_dir(self, report_data_dir, report_file):
|
|
95 |
"""
|
|
96 |
Create a report based on an input data directory.
|
|
97 |
@return: Absolute path to the created report.
|
|
98 |
"""
|
|
99 |
TEMPLATE_FILE = os.path.join(TESTDATA_DIR, 'template.txt')
|
|
100 |
REPORT_FILE = os.path.join(TEMP_DIR, report_file)
|
|
101 |
self.remove_if_exists(REPORT_FILE)
|
|
102 |
|
3
|
103 |
cmd = '%s --report "%s" --log-file="%s" --template "%s" --input-data-dir "%s"' \
|
|
104 |
% (get_cmd('report'), REPORT_FILE,
|
|
105 |
os.path.join(TEMP_DIR,'cone_report_from_dir.log'),
|
|
106 |
TEMPLATE_FILE,
|
|
107 |
report_data_dir)
|
0
|
108 |
self.run_command(cmd)
|
|
109 |
self.assert_exists_and_contains_something(REPORT_FILE)
|
|
110 |
return REPORT_FILE
|
|
111 |
|
3
|
112 |
|
0
|
113 |
if __name__ == '__main__':
|
3
|
114 |
unittest.main()
|