|
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 unittest, os, re, subprocess |
|
18 |
|
19 import __init__ |
|
20 from cone.public import api, plugin |
|
21 from cone.storage import filestorage |
|
22 from testautomation.base_testcase import BaseTestCase |
|
23 from commandplugin.commandml import Command, Condition |
|
24 |
|
25 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
26 testdata = os.path.join(ROOT_PATH,'project') |
|
27 |
|
28 class TestParseCommandMl(BaseTestCase): |
|
29 def _get_impl(self, ref): |
|
30 fs = filestorage.FileStorage(testdata) |
|
31 p = api.Project(fs) |
|
32 config = p.get_configuration('product.confml') |
|
33 impl_set = plugin.get_impl_set(config, re.escape(ref) + '$') |
|
34 self.assertEquals(len(impl_set), 1) |
|
35 return iter(impl_set).next() |
|
36 |
|
37 def test_parse_file1(self): |
|
38 impl = self._get_impl('file1.commandml') |
|
39 self.assertEquals(len(impl.reader.elements), 2) |
|
40 |
|
41 cmd = impl.reader.elements[0] |
|
42 self.assertTrue(isinstance(cmd, Command)) |
|
43 self.assertEquals(cmd.executable, r'c:\program1\run.exe') |
|
44 self.assertEquals(cmd.shell, False) |
|
45 self.assertEquals(cmd.bufsize, 0) |
|
46 self.assertEquals(cmd.cwd, r'c:\program1') |
|
47 self.assertEquals(cmd.envs, {'MYVAR': '123'}) |
|
48 self.assertEquals(cmd.arguments, ['-c some_config.txt', |
|
49 '-d some_dir', |
|
50 '-x']) |
|
51 self.assertEquals(cmd.pipes, {'stdin': subprocess.PIPE, |
|
52 'stdout': 'program1.log'}) |
|
53 |
|
54 cond = impl.reader.elements[1] |
|
55 self.assertTrue(isinstance(cond, Condition)) |
|
56 self.assertEquals(cond.condition, 'False') |
|
57 self.assertEquals(len(cond.commands), 1) |
|
58 cmd = cond.commands[0] |
|
59 self.assertTrue(isinstance(cmd, Command)) |
|
60 self.assertEquals(cmd.executable, r'c:\program2\abc.exe') |
|
61 self.assertEquals(cmd.shell, True) |
|
62 self.assertEquals(cmd.bufsize, 0) |
|
63 self.assertEquals(cmd.arguments, ['-c some_config.txt']) |
|
64 self.assertEquals(cmd.pipes, {}) |
|
65 |
|
66 self.assertEquals(impl.get_tags(), {}) |
|
67 |
|
68 def test_parse_file2(self): |
|
69 impl = self._get_impl('file2.commandml') |
|
70 self.assertEquals(len(impl.reader.elements), 4) |
|
71 |
|
72 self.assertTrue(isinstance(impl.reader.elements[0], Condition)) |
|
73 self.assertTrue(isinstance(impl.reader.elements[1], Condition)) |
|
74 self.assertTrue(isinstance(impl.reader.elements[2], Command)) |
|
75 self.assertTrue(isinstance(impl.reader.elements[3], Command)) |
|
76 |
|
77 self.assertEquals(impl.get_tags(), {'target': ['footarget']}) |
|
78 |
|
79 if __name__ == '__main__': |
|
80 unittest.main() |