587
|
1 |
#============================================================================
|
|
2 |
#Name : test_atsconfigparser.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
|
19 |
|
|
20 |
""" Testing the ATS configuration file """
|
|
21 |
|
|
22 |
import os
|
|
23 |
import logging
|
|
24 |
import tempfile
|
|
25 |
import unittest
|
|
26 |
|
|
27 |
import ats3.atsconfigparser
|
|
28 |
|
|
29 |
_logger = logging.getLogger('test.atsconfigparser')
|
|
30 |
logging.basicConfig(level=logging.INFO)
|
|
31 |
|
|
32 |
class AtsConfigParserTest(unittest.TestCase):
|
|
33 |
"""class used to test ATS config parser"""
|
|
34 |
def test_converttestxml(self):
|
|
35 |
"""setup test data, call the convert to XML method (part being tested)
|
|
36 |
then check it is correct"""
|
|
37 |
spectext = """<ATSConfigData>
|
|
38 |
<config name="common" abstract="true">
|
|
39 |
|
|
40 |
<!-- Properties to add/modify -->
|
|
41 |
<config type="properties">
|
|
42 |
<set name="HARNESS" value="STIFx" />
|
|
43 |
<set name="HARNESS2" value="STIF2"/>
|
|
44 |
<set name="HARNESS3" value="STIF2"/>
|
|
45 |
<set name="2" value="3" />
|
|
46 |
</config>
|
|
47 |
|
|
48 |
<!-- Attributes to modify -->
|
|
49 |
<config type="attributes">
|
|
50 |
<set name="xyz" value="2" />
|
|
51 |
<set name="significant" value="true" />
|
|
52 |
</config>
|
|
53 |
|
|
54 |
<!-- Settings to add/modify -->
|
|
55 |
<config type="settings">
|
|
56 |
<set name="HARNESS" value="STIF" />
|
|
57 |
<set name="2" value="3" />
|
|
58 |
</config>
|
|
59 |
|
|
60 |
</config>
|
|
61 |
</ATSConfigData>
|
|
62 |
"""
|
|
63 |
|
|
64 |
testxmldata = """<test>
|
|
65 |
<name>helium_clock</name>
|
|
66 |
<target>
|
|
67 |
<device alias="DEFAULT_STIF" rank="none">
|
|
68 |
<property name="HARNESS" value="STIF"/>
|
|
69 |
<property name="HARNESS2" value="STIF"/>
|
|
70 |
<property name="HARNESS3" value="STIF"/>
|
|
71 |
</device>
|
|
72 |
<device alias="DEFAULT_EUIT" rank="none">
|
|
73 |
<property name="HARNESS" value="STIF"/>
|
|
74 |
<property name="HARNESS2" value="STIF3"/>
|
|
75 |
</device>
|
|
76 |
</target>
|
|
77 |
<plan passrate="100" harness="STIF" enabled="true" name="helium_clock Plan" significant="false">
|
|
78 |
<session passrate="100" harness="STIF" enabled="true" name="session" significant="false">
|
|
79 |
<set passrate="100" harness="STIF" enabled="true" name="set0" significant="false">
|
|
80 |
<target>
|
|
81 |
<device alias="DEFAULT_STIF" rank="master"/>
|
|
82 |
</target>
|
|
83 |
</set>
|
|
84 |
</session>
|
|
85 |
</plan>
|
|
86 |
</test>
|
|
87 |
"""
|
|
88 |
|
|
89 |
(file_descriptor, filename) = tempfile.mkstemp()
|
|
90 |
file_handle = os.fdopen(file_descriptor, 'w')
|
|
91 |
file_handle.write(spectext)
|
|
92 |
file_handle.close()
|
|
93 |
|
|
94 |
output = ats3.atsconfigparser.converttestxml(filename, testxmldata)
|
|
95 |
os.remove(filename)
|
|
96 |
_logger.info(output)
|
|
97 |
self.assert_( '<property name="2" value="3"/>' in output)
|
|
98 |
self.assert_( '<property name="HARNESS" value="STIFx"/>' in output)
|
|
99 |
self.assert_( '<property name="HARNESS" value="STIF"/>' not in output)
|
|
100 |
self.assert_( '<property name="HARNESS2" value="STIF2"/>' in output)
|
|
101 |
self.assert_( '<property name="HARNESS2" value="STIF3"/>' not in output)
|
|
102 |
self.assert_( '<property name="HARNESS3" value="STIF2"/>' in output)
|