|
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 |
|
18 import __init__ |
|
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) |
|
34 lines = out.split('\r\n') |
|
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 |
|
68 cmd = '%s -p "%s" -o "%s" --report-data-output "%s" --impl-tag target:%s' \ |
|
69 % (get_cmd('generate'), TEST_PROJECT, OUTPUT_DIR, REPORT_DATA_FILE, target_tag) |
|
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 |
|
85 cmd = '%s --report "%s" --template "%s" ' % (get_cmd('report'), REPORT_FILE, TEMPLATE_FILE) |
|
86 cmd += ' '.join(['--input-data "%s"' % f for f in report_data_files]) |
|
87 self.run_command(cmd) |
|
88 self.assert_exists_and_contains_something(REPORT_FILE) |
|
89 return REPORT_FILE |
|
90 |
|
91 def create_report_from_dir(self, report_data_dir, report_file): |
|
92 """ |
|
93 Create a report based on an input data directory. |
|
94 @return: Absolute path to the created report. |
|
95 """ |
|
96 TEMPLATE_FILE = os.path.join(TESTDATA_DIR, 'template.txt') |
|
97 REPORT_FILE = os.path.join(TEMP_DIR, report_file) |
|
98 self.remove_if_exists(REPORT_FILE) |
|
99 |
|
100 cmd = '%s --report "%s" --template "%s" --input-data-dir "%s"' \ |
|
101 % (get_cmd('report'), REPORT_FILE, TEMPLATE_FILE, report_data_dir) |
|
102 self.run_command(cmd) |
|
103 self.assert_exists_and_contains_something(REPORT_FILE) |
|
104 return REPORT_FILE |
|
105 |
|
106 if __name__ == '__main__': |
|
107 unittest.main() |