0
|
1 |
# *-* coding: utf-8 *-*
|
|
2 |
#
|
|
3 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
# All rights reserved.
|
|
5 |
# This component and the accompanying materials are made available
|
|
6 |
# under the terms of "Eclipse Public License v1.0"
|
|
7 |
# which accompanies this distribution, and is available
|
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
#
|
|
10 |
# Initial Contributors:
|
|
11 |
# Nokia Corporation - initial contribution.
|
|
12 |
#
|
|
13 |
# Contributors:
|
|
14 |
#
|
|
15 |
# Description:
|
|
16 |
#
|
|
17 |
##
|
|
18 |
# @author Teemu Rytkonen
|
|
19 |
|
|
20 |
import sys, os, shutil, unittest
|
|
21 |
import __init__
|
|
22 |
from testautomation.base_testcase import BaseTestCase
|
|
23 |
from testautomation import zip_dir
|
|
24 |
from scripttest_common import get_cmd
|
|
25 |
|
|
26 |
|
|
27 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
28 |
testproject = os.path.join(ROOT_PATH,'test_project.cpf')
|
|
29 |
rootconf = 'root3.confml'
|
|
30 |
|
|
31 |
class TestGenerate(BaseTestCase):
|
|
32 |
|
|
33 |
def test_get_help(self):
|
|
34 |
cmd = '%s -h' % get_cmd('generate')
|
|
35 |
out = self.run_command(cmd)
|
|
36 |
lines = out.split('\r\n')
|
|
37 |
self.assertTrue('Options:' in lines)
|
|
38 |
self.assertTrue(' Generate options:' in lines)
|
|
39 |
|
|
40 |
def test_generate(self):
|
|
41 |
self.set_modification_reference_time(testproject)
|
|
42 |
OUTPUT_DIR = os.path.join(ROOT_PATH, 'temp/gen1/output')
|
|
43 |
self.remove_if_exists(OUTPUT_DIR)
|
|
44 |
cmd = '%s -p "%s" -c "%s" -o "%s"' % (get_cmd('generate'),testproject,rootconf,OUTPUT_DIR)
|
|
45 |
out = self.run_command(cmd)
|
|
46 |
self.assert_exists_and_contains_something(OUTPUT_DIR)
|
|
47 |
|
|
48 |
self.assert_not_modified(testproject)
|
|
49 |
|
|
50 |
def test_generate_with_report(self):
|
|
51 |
self.set_modification_reference_time(testproject)
|
|
52 |
OUTPUT_DIR = os.path.join(ROOT_PATH, 'temp/gen2/output')
|
|
53 |
REPORT_FILE = os.path.join(ROOT_PATH, 'temp/gen2/report.html')
|
|
54 |
self.remove_if_exists([OUTPUT_DIR, REPORT_FILE])
|
|
55 |
cmd = '%s -p "%s" -c "%s" -o "%s" -r "%s"' % (get_cmd('generate'),testproject,rootconf, OUTPUT_DIR, REPORT_FILE)
|
|
56 |
out = self.run_command(cmd)
|
|
57 |
self.assert_exists_and_contains_something(OUTPUT_DIR)
|
|
58 |
self.assert_exists_and_contains_something(REPORT_FILE)
|
|
59 |
|
|
60 |
self.assert_not_modified(testproject)
|
|
61 |
|
|
62 |
def test_generate_with_report_using_custom_template(self):
|
|
63 |
self._run_test_generate_with_report_using_custom_template(
|
|
64 |
output_dir = 'temp/gen3/output',
|
|
65 |
report_file = 'temp/gen3/report.csv',
|
|
66 |
template_path = 'template.csv')
|
|
67 |
|
|
68 |
def test_generate_with_report_using_custom_template_in_relative_dir(self):
|
|
69 |
self._run_test_generate_with_report_using_custom_template(
|
|
70 |
output_dir = 'temp/gen4/output',
|
|
71 |
report_file = 'temp/gen4/report.csv',
|
|
72 |
template_path = 'test_template/template2.csv')
|
|
73 |
|
|
74 |
def test_generate_with_report_using_custom_template_in_relative_dir2(self):
|
|
75 |
self._run_test_generate_with_report_using_custom_template(
|
|
76 |
output_dir = 'temp/gen5/output',
|
|
77 |
report_file = 'temp/gen5/report.csv',
|
|
78 |
template_path = '../tests/test_template/template2.csv')
|
|
79 |
|
|
80 |
def test_generate_with_report_using_custom_template_in_absolute_dir(self):
|
|
81 |
self._run_test_generate_with_report_using_custom_template(
|
|
82 |
output_dir = 'temp/gen6/output',
|
|
83 |
report_file = 'temp/gen6/report.csv',
|
|
84 |
template_path = os.path.join(ROOT_PATH,'test_template/template2.csv'))
|
|
85 |
|
|
86 |
def _run_test_generate_with_report_using_custom_template(self,
|
|
87 |
output_dir, report_file, template_path, project=testproject):
|
|
88 |
|
|
89 |
# Since we are testing also relative paths here, we need
|
|
90 |
# to run the test in the same directory as the script
|
|
91 |
orig_workdir = os.getcwd()
|
|
92 |
os.chdir(ROOT_PATH)
|
|
93 |
try:
|
|
94 |
self.set_modification_reference_time(project)
|
|
95 |
self.remove_if_exists([output_dir, report_file])
|
|
96 |
cmd = '%s -p "%s" -c "%s" -o "%s" -r "%s" -t "%s"' % (get_cmd('generate'),project,rootconf, output_dir, report_file, template_path)
|
|
97 |
out = self.run_command(cmd)
|
|
98 |
self.assert_exists_and_contains_something(output_dir)
|
|
99 |
self.assert_exists_and_contains_something(report_file)
|
|
100 |
self.assert_not_modified(project)
|
|
101 |
finally:
|
|
102 |
os.chdir(orig_workdir)
|
|
103 |
|
|
104 |
def test_generate_with_report_and_invalid_refs_in_data(self):
|
|
105 |
self._run_test_generate_with_report_using_custom_template(
|
|
106 |
project = os.path.join(ROOT_PATH, 'testdata/generate/test_project_invalid_data_refs.zip'),
|
|
107 |
output_dir = 'temp/gen7/output',
|
|
108 |
report_file = 'temp/gen7/report.csv',
|
|
109 |
template_path = os.path.join(ROOT_PATH,'test_template/template2.csv'))
|
|
110 |
|
|
111 |
class TestGenerateAllImplsOnLastLayer(BaseTestCase):
|
|
112 |
|
|
113 |
def _prepare_workdir(self, workdir):
|
|
114 |
workdir = os.path.join(ROOT_PATH, workdir)
|
|
115 |
self.recreate_dir(workdir)
|
|
116 |
|
|
117 |
# Any needed extra preparation can be done here
|
|
118 |
|
|
119 |
return workdir
|
|
120 |
|
|
121 |
def test_generate_all_impls_on_last_layer_on_file_storage(self):
|
|
122 |
project_dir = os.path.join(ROOT_PATH, "generation_test_project")
|
|
123 |
self.assert_exists_and_contains_something(project_dir)
|
|
124 |
self._run_test_generate_all_impls_on_last_layer('temp/gen_ll1', project_dir)
|
|
125 |
|
|
126 |
def test_generate_all_impls_on_last_layer_on_zip_storage(self):
|
|
127 |
project_dir = os.path.join(ROOT_PATH, "generation_test_project")
|
|
128 |
self.assert_exists_and_contains_something(project_dir)
|
|
129 |
|
|
130 |
project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip")
|
|
131 |
self.remove_if_exists(project_zip)
|
|
132 |
zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN])
|
|
133 |
self.assert_exists_and_contains_something(project_zip)
|
|
134 |
|
|
135 |
self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip)
|
|
136 |
|
|
137 |
def test_generate_all_impls_on_last_layer_on_file_storage_with_report(self):
|
|
138 |
project_dir = os.path.join(ROOT_PATH, "generation_test_project")
|
|
139 |
self.assert_exists_and_contains_something(project_dir)
|
|
140 |
|
|
141 |
# Create a temp workdir and go there to run the test
|
|
142 |
orig_workdir = os.getcwd()
|
|
143 |
workdir = self._prepare_workdir('temp/gen_ll3')
|
|
144 |
os.chdir(workdir)
|
|
145 |
|
|
146 |
try:
|
|
147 |
cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg --report report.html' % (get_cmd('generate'), project_dir)
|
|
148 |
self.run_command(cmd)
|
|
149 |
finally:
|
|
150 |
os.chdir(orig_workdir)
|
|
151 |
|
|
152 |
ACTUAL_REPORT = os.path.join(ROOT_PATH, 'temp/gen_ll3/report.html')
|
|
153 |
EXPECTED_REPORT = os.path.join(ROOT_PATH, "testdata/generate/expected_report.html")
|
|
154 |
|
|
155 |
ignores = [
|
|
156 |
r'<tr>\s*<td>Report generated</td>\s*<td>.*</td>\s*</tr>',
|
|
157 |
r'<tr>\s*<td>Generation duration</td>\s*<td>.*</td>\s*</tr>',
|
|
158 |
r'<a href=".*">',
|
|
159 |
r'<tr>\s*<td align="left">Project</td>\s*<td align="left">.*</td>\s*</tr>',
|
|
160 |
r'<tr>\s*<td align="left">Working directory</td>\s*<td align="left">.*</td>\s*</tr>',
|
|
161 |
]
|
|
162 |
|
|
163 |
self.assert_file_contents_equal(ACTUAL_REPORT, EXPECTED_REPORT, ignores)
|
|
164 |
|
|
165 |
def _run_test_generate_all_impls_on_last_layer(self, workdir, project):
|
|
166 |
# Create a temp workdir and go there to run the test
|
|
167 |
orig_workdir = os.getcwd()
|
|
168 |
workdir = self._prepare_workdir(workdir)
|
|
169 |
os.chdir(workdir)
|
|
170 |
|
|
171 |
try:
|
|
172 |
cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg' % (get_cmd('generate'), project)
|
|
173 |
print self.run_command(cmd)
|
|
174 |
|
|
175 |
EXPECTED_DIR = os.path.join(ROOT_PATH, "testdata/generate/expected")
|
|
176 |
self.assert_dir_contents_equal('output', EXPECTED_DIR, ['.svn'])
|
|
177 |
|
|
178 |
# Check that output has also been generated to the overridden output root directory
|
|
179 |
self.assert_exists_and_contains_something('overridden_output/output_rootdir_test.txt')
|
|
180 |
self.assert_exists_and_contains_something('overridden_output/test_subdir/output_rootdir_test.txt')
|
|
181 |
finally:
|
|
182 |
os.chdir(orig_workdir)
|
|
183 |
|
|
184 |
class TestGenerationImplFilteringByTags(BaseTestCase):
|
|
185 |
|
|
186 |
def test_no_tag_filtering(self):
|
|
187 |
self._run_tag_filtering_test(
|
|
188 |
name = 'no_filter',
|
|
189 |
filter = '',
|
|
190 |
expected = ['none', 't1', 't2', 't3', 't1_t2', 't2_t3', 't1_t3', 't1_t2_t3'])
|
|
191 |
|
|
192 |
def test_filter_by_t1(self):
|
|
193 |
self._run_tag_filtering_test(
|
|
194 |
name = 't1',
|
|
195 |
filter = '--impl-tag target:t1',
|
|
196 |
expected = ['t1', 't1_t2', 't1_t3', 't1_t2_t3'])
|
|
197 |
|
|
198 |
def test_filter_by_t2(self):
|
|
199 |
self._run_tag_filtering_test(
|
|
200 |
name = 't2',
|
|
201 |
filter = '--impl-tag target:t2',
|
|
202 |
expected = ['t2', 't1_t2', 't2_t3', 't1_t2_t3'])
|
|
203 |
|
|
204 |
def test_filter_by_t3(self):
|
|
205 |
self._run_tag_filtering_test(
|
|
206 |
name = 't3',
|
|
207 |
filter = '--impl-tag target:t3',
|
|
208 |
expected = ['t3', 't1_t3', 't2_t3', 't1_t2_t3'])
|
|
209 |
|
|
210 |
def test_filter_by_t1_or_t2(self):
|
|
211 |
self._run_tag_filtering_test(
|
|
212 |
name = 't1_or_t2',
|
|
213 |
filter = '--impl-tag target:t1 --impl-tag target:t2',
|
|
214 |
expected = ['t1', 't2', 't1_t2', 't2_t3', 't1_t3', 't1_t2_t3'])
|
|
215 |
|
|
216 |
def test_filter_by_t2_or_t3(self):
|
|
217 |
self._run_tag_filtering_test(
|
|
218 |
name = 't2_or_t3',
|
|
219 |
filter = '--impl-tag target:t2 --impl-tag target:t3',
|
|
220 |
expected = ['t2', 't3', 't1_t2', 't2_t3', 't1_t3', 't1_t2_t3'])
|
|
221 |
|
|
222 |
def test_filter_by_t1_or_t3(self):
|
|
223 |
self._run_tag_filtering_test(
|
|
224 |
name = 't1_or_t3',
|
|
225 |
filter = '--impl-tag target:t1 --impl-tag target:t3',
|
|
226 |
expected = ['t1', 't3', 't1_t2', 't2_t3', 't1_t3', 't1_t2_t3'])
|
|
227 |
|
|
228 |
def test_filter_by_t1_or_t2_or_t3(self):
|
|
229 |
self._run_tag_filtering_test(
|
|
230 |
name = 't1_or_t2_or_t3',
|
|
231 |
filter = '--impl-tag target:t1 --impl-tag target:t2 --impl-tag target:t3',
|
|
232 |
expected = ['t1', 't2', 't3', 't1_t2', 't2_t3', 't1_t3', 't1_t2_t3'])
|
|
233 |
|
|
234 |
def test_filter_by_t1_and_t2(self):
|
|
235 |
self._run_tag_filtering_test(
|
|
236 |
name = 't1_and_t2',
|
|
237 |
filter = '--impl-tag target:t1 --impl-tag target:t2 --impl-tag-policy=AND',
|
|
238 |
expected = ['t1_t2', 't1_t2_t3'])
|
|
239 |
|
|
240 |
def test_filter_by_t2_and_t3(self):
|
|
241 |
self._run_tag_filtering_test(
|
|
242 |
name = 't2_and_t3',
|
|
243 |
filter = '--impl-tag target:t2 --impl-tag target:t3 --impl-tag-policy=AND',
|
|
244 |
expected = ['t2_t3', 't1_t2_t3'])
|
|
245 |
|
|
246 |
def test_filter_by_t1_and_t3(self):
|
|
247 |
self._run_tag_filtering_test(
|
|
248 |
name = 't1_and_t3',
|
|
249 |
filter = '--impl-tag target:t1 --impl-tag target:t3 --impl-tag-policy=AND',
|
|
250 |
expected = ['t1_t3', 't1_t2_t3'])
|
|
251 |
|
|
252 |
def test_filter_by_t1_and_t2_and_t3(self):
|
|
253 |
self._run_tag_filtering_test(
|
|
254 |
name = 't1_and_t2_and_t3',
|
|
255 |
filter = '--impl-tag target:t1 --impl-tag target:t2 --impl-tag target:t3 --impl-tag-policy=AND',
|
|
256 |
expected = ['t1_t2_t3'])
|
|
257 |
|
|
258 |
def _run_tag_filtering_test(self, name, filter, expected):
|
|
259 |
PROJECT = os.path.join(ROOT_PATH, 'tag_filtering_test_project')
|
|
260 |
|
|
261 |
OUTPUT_ROOT = os.path.join(ROOT_PATH, 'temp/gen_tf/', name)
|
|
262 |
OUTPUT = os.path.join(OUTPUT_ROOT, 'out')
|
|
263 |
LOG = os.path.join(OUTPUT_ROOT, 'cone.log')
|
|
264 |
self.remove_if_exists(OUTPUT)
|
|
265 |
|
|
266 |
cmd = '%s -p "%s" --output "%s" --log-file="%s" %s' % (get_cmd('generate'), PROJECT, OUTPUT, LOG, filter)
|
|
267 |
self.run_command(cmd)
|
|
268 |
|
|
269 |
self.assert_exists_and_contains_something(OUTPUT)
|
|
270 |
|
|
271 |
expected_files = sorted([x + '.txt' for x in expected])
|
|
272 |
actual_files = sorted(os.listdir(OUTPUT))
|
|
273 |
|
|
274 |
self.assertEquals(expected_files, actual_files)
|
|
275 |
|
|
276 |
if __name__ == '__main__':
|
|
277 |
unittest.main()
|