|
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 import sys, os, shutil, unittest |
|
19 import __init__ |
|
20 from testautomation.base_testcase import BaseTestCase |
|
21 from testautomation import zip_dir |
|
22 |
|
23 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
24 |
|
25 if sys.platform == "win32": |
|
26 CONE_SCRIPT = "cone.cmd" |
|
27 else: |
|
28 CONE_SCRIPT = "cone.sh" |
|
29 |
|
30 def get_cmd(action='generate'): |
|
31 """Return the command used to run the ConE sub-action""" |
|
32 if 'CONE_PATH' in os.environ: |
|
33 CONE_CMD = os.path.join(os.environ['CONE_PATH'], CONE_SCRIPT) |
|
34 if not os.path.exists(CONE_CMD): |
|
35 raise RuntimeError("'%s' does not exist!" % CONE_CMD) |
|
36 return '"%s" %s' % (CONE_CMD, action) |
|
37 else: |
|
38 SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..')) |
|
39 assert os.path.split(SOURCE_ROOT)[1] == 'source' |
|
40 cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action) |
|
41 return cmd |
|
42 |
|
43 class TestExampleGenerate(BaseTestCase): |
|
44 |
|
45 def _prepare_workdir(self, workdir): |
|
46 workdir = os.path.join(ROOT_PATH, workdir) |
|
47 self.recreate_dir(workdir) |
|
48 |
|
49 # Any needed extra preparation can be done here |
|
50 |
|
51 return workdir |
|
52 |
|
53 def test_generate_on_file_storage(self): |
|
54 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
|
55 self.assert_exists_and_contains_something(project_dir) |
|
56 self._run_test_generate('temp/gen1', project_dir) |
|
57 |
|
58 def test_generate_on_zip_storage(self): |
|
59 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
|
60 self.assert_exists_and_contains_something(project_dir) |
|
61 |
|
62 project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip") |
|
63 self.remove_if_exists(project_zip) |
|
64 zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN]) |
|
65 self.assert_exists_and_contains_something(project_zip) |
|
66 |
|
67 self._run_test_generate('temp/gen2', project_zip) |
|
68 |
|
69 def _run_test_generate(self, workdir, project): |
|
70 # Create a temp workdir and go there to run the test |
|
71 orig_workdir = os.getcwd() |
|
72 workdir = self._prepare_workdir(workdir) |
|
73 os.chdir(workdir) |
|
74 |
|
75 try: |
|
76 cmd = '%s -p "%s" --output output --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project) |
|
77 self.run_command(cmd) |
|
78 |
|
79 EXPECTED_DIR = os.path.join(ROOT_PATH, "testdata/generate/expected") |
|
80 self.assert_dir_contents_equal('output', EXPECTED_DIR, ['.svn']) |
|
81 finally: |
|
82 os.chdir(orig_workdir) |
|
83 |
|
84 if __name__ == '__main__': |
|
85 unittest.main() |