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 unittest, os, re, subprocess
|
|
18 |
|
3
|
19 |
# import __init__
|
0
|
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')
|
3
|
47 |
self.assertEquals(cmd.envs, "{'MYVAR':'123'}")
|
0
|
48 |
self.assertEquals(cmd.arguments, ['-c some_config.txt',
|
|
49 |
'-d some_dir',
|
|
50 |
'-x'])
|
|
51 |
self.assertEquals(cmd.pipes, {'stdin': subprocess.PIPE,
|
4
|
52 |
'stdout': 'program1.log',
|
|
53 |
'stderr': subprocess.PIPE})
|
0
|
54 |
|
|
55 |
cond = impl.reader.elements[1]
|
|
56 |
self.assertTrue(isinstance(cond, Condition))
|
|
57 |
self.assertEquals(cond.condition, 'False')
|
|
58 |
self.assertEquals(len(cond.commands), 1)
|
|
59 |
cmd = cond.commands[0]
|
|
60 |
self.assertTrue(isinstance(cmd, Command))
|
|
61 |
self.assertEquals(cmd.executable, r'c:\program2\abc.exe')
|
|
62 |
self.assertEquals(cmd.shell, True)
|
|
63 |
self.assertEquals(cmd.bufsize, 0)
|
|
64 |
self.assertEquals(cmd.arguments, ['-c some_config.txt'])
|
4
|
65 |
self.assertEquals(cmd.pipes, {'stdout': subprocess.PIPE,
|
|
66 |
'stderr': subprocess.PIPE})
|
0
|
67 |
|
|
68 |
self.assertEquals(impl.get_tags(), {})
|
|
69 |
|
|
70 |
def test_parse_file2(self):
|
|
71 |
impl = self._get_impl('file2.commandml')
|
3
|
72 |
self.assertEquals(len(impl.reader.elements), 5)
|
0
|
73 |
|
|
74 |
self.assertTrue(isinstance(impl.reader.elements[0], Condition))
|
|
75 |
self.assertTrue(isinstance(impl.reader.elements[1], Condition))
|
|
76 |
self.assertTrue(isinstance(impl.reader.elements[2], Command))
|
|
77 |
self.assertTrue(isinstance(impl.reader.elements[3], Command))
|
|
78 |
|
|
79 |
self.assertEquals(impl.get_tags(), {'target': ['footarget']})
|
|
80 |
|
|
81 |
if __name__ == '__main__':
|
|
82 |
unittest.main()
|