buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_amara.py
author wbernard
Wed, 16 Jun 2010 16:51:40 +0300
changeset 588 c7c26511138f
parent 587 85df38eb4012
child 628 7c4a911dc066
permissions -rw-r--r--
helium-10.0.0-bc45d50958fe
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_ant.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
""" amara.py module tests. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import amara
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
from xmlhelper import recursive_node_scan
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
def test_amara():
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    27
    """test amara"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    28
    xxx = amara.parse(r'<commentLog><branchInfo category="" error="kkk" file="tests/data/comments_test.txt" originator="sanummel" since="07-03-22">Add rofsfiles for usage in paged images</branchInfo></commentLog>')
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    29
    assert str(xxx.commentLog.branchInfo) == 'Add rofsfiles for usage in paged images'
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
    
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    31
    xxx = amara.parse(r'<commentLog><branchInfo>1</branchInfo><branchInfo>2</branchInfo></commentLog>')
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    32
    for yyy in xxx.commentLog.branchInfo:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    33
        assert str(yyy) == '1'
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        break
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
          
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    myxml = """<DpComponent DpType="File" name="dp.cfg.xml" fileType="Binary" fileSubType="1" fileIndex="1" owner="SwUpdate" extract="true" signed="true" optional="true" crc="true" useCases="Refurbish,BackupRestore" variantPackage="true" include="true" EnableCRCVerification="true" parameters="test"/>"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
    xcf = amara.parse(myxml)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    assert xcf.DpComponent['name'] == 'dp.cfg.xml'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    myxml2 = """<bomDelta><buildFrom>ido_raptor_mcl_abs_MCL.52.57</buildFrom><buildTo>mock</buildTo><content/></bomDelta>"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
    xcf2 = amara.parse(myxml2)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    assert xcf2.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    print xcf.DpComponent.xml_attributes
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    doc = amara.create_document(u'bom')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    s60_input_node = doc.xml_create_element(u'input')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode("s60"))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    print s60_input_node.xml()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    s60_input_source = s60_input_node.xml_create_element(u'source')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("grace"))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    print s60_input_source.xml()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
          
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    doc = amara.create_document(u'bom')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode("a")))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    doc = amara.create_document(u'bomDelta')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
    content_node = doc.xml_create_element(u'content')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    doc.bomDelta.xml_append(content_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    content_node.xml_append(content_node.xml_create_element(u'b', content=unicode('a')))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
    assert doc.bomDelta.xml(indent=False) == '<bomDelta><content><b>a</b></content></bomDelta>'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    recursive_node_scan(doc, 'a')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    amara.create_document()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    xcf3 = amara.parse(r'<VariantPackingList><Variant/></VariantPackingList>')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    assert hasattr(xcf3.VariantPackingList.Variant,"FileList") == False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    if not hasattr(xcf3.VariantPackingList.Variant,"FileList"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        xcf3.VariantPackingList.Variant.xml_append(xcf3.xml_create_element(u"FileList"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    xcf3.VariantPackingList.Variant.FileList.xml_append_fragment(doc.xml(omitXmlDeclaration=u"yes"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    xcf4 = amara.parse(r"<a><p name='1'/><p name='1'/></a>")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    found = False
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    76
    for p_path in xcf4.xml_xpath("//p"):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    77
        assert str(p_path.name) == '1'
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        found = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    assert found
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
    #xcf5 = amara.parse(open(r'C:\USERS\helium\helium-dev-forbuilds\helium\tests\data\bom\build_model_bom.xml'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
    #u'%s' % xcf5.bom.content.project.folder.task.synopsis