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