587
|
1 |
#============================================================================
|
|
2 |
#Name : test_ant.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 |
""" amara.py module tests. """
|
|
21 |
|
|
22 |
|
|
23 |
import amara
|
|
24 |
from xmlhelper import recursive_node_scan
|
628
|
25 |
import urllib
|
|
26 |
import tempfile
|
|
27 |
import os
|
|
28 |
import sys
|
587
|
29 |
|
|
30 |
def test_amara():
|
588
|
31 |
"""test amara"""
|
|
32 |
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>')
|
|
33 |
assert str(xxx.commentLog.branchInfo) == 'Add rofsfiles for usage in paged images'
|
587
|
34 |
|
588
|
35 |
xxx = amara.parse(r'<commentLog><branchInfo>1</branchInfo><branchInfo>2</branchInfo></commentLog>')
|
|
36 |
for yyy in xxx.commentLog.branchInfo:
|
|
37 |
assert str(yyy) == '1'
|
587
|
38 |
break
|
|
39 |
|
|
40 |
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"/>"""
|
|
41 |
xcf = amara.parse(myxml)
|
|
42 |
assert xcf.DpComponent['name'] == 'dp.cfg.xml'
|
|
43 |
|
|
44 |
myxml2 = """<bomDelta><buildFrom>ido_raptor_mcl_abs_MCL.52.57</buildFrom><buildTo>mock</buildTo><content/></bomDelta>"""
|
|
45 |
xcf2 = amara.parse(myxml2)
|
|
46 |
assert xcf2.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57"
|
|
47 |
|
|
48 |
print xcf.DpComponent.xml_attributes
|
|
49 |
|
|
50 |
doc = amara.create_document(u'bom')
|
|
51 |
s60_input_node = doc.xml_create_element(u'input')
|
|
52 |
s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode("s60"))))
|
|
53 |
print s60_input_node.xml()
|
|
54 |
|
|
55 |
s60_input_source = s60_input_node.xml_create_element(u'source')
|
|
56 |
s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("grace"))))
|
|
57 |
print s60_input_source.xml()
|
|
58 |
|
|
59 |
doc = amara.create_document(u'bom')
|
|
60 |
doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode("a")))
|
|
61 |
|
|
62 |
doc = amara.create_document(u'bomDelta')
|
|
63 |
content_node = doc.xml_create_element(u'content')
|
|
64 |
doc.bomDelta.xml_append(content_node)
|
|
65 |
content_node.xml_append(content_node.xml_create_element(u'b', content=unicode('a')))
|
|
66 |
assert doc.bomDelta.xml(indent=False) == '<bomDelta><content><b>a</b></content></bomDelta>'
|
|
67 |
|
|
68 |
recursive_node_scan(doc, 'a')
|
|
69 |
|
|
70 |
amara.create_document()
|
|
71 |
|
|
72 |
xcf3 = amara.parse(r'<VariantPackingList><Variant/></VariantPackingList>')
|
|
73 |
assert hasattr(xcf3.VariantPackingList.Variant,"FileList") == False
|
|
74 |
if not hasattr(xcf3.VariantPackingList.Variant,"FileList"):
|
|
75 |
xcf3.VariantPackingList.Variant.xml_append(xcf3.xml_create_element(u"FileList"))
|
|
76 |
xcf3.VariantPackingList.Variant.FileList.xml_append_fragment(doc.xml(omitXmlDeclaration=u"yes"))
|
|
77 |
|
|
78 |
xcf4 = amara.parse(r"<a><p name='1'/><p name='1'/></a>")
|
|
79 |
found = False
|
588
|
80 |
for p_path in xcf4.xml_xpath("//p"):
|
|
81 |
assert str(p_path.name) == '1'
|
587
|
82 |
found = True
|
|
83 |
assert found
|
|
84 |
|
|
85 |
#xcf5 = amara.parse(open(r'C:\USERS\helium\helium-dev-forbuilds\helium\tests\data\bom\build_model_bom.xml'))
|
|
86 |
#u'%s' % xcf5.bom.content.project.folder.task.synopsis
|
628
|
87 |
|
|
88 |
doc = amara.create_document(u"commentLog")
|
|
89 |
if not doc:
|
|
90 |
pass
|
|
91 |
|
|
92 |
xml1 = """<commentLog><branchInfo category="" error="kkk" file="comments_test.txt" originator="sanummel" since="07-03-22">Add rofsfiles for usage in paged images</branchInfo></commentLog>"""
|
|
93 |
doc2 = amara.parse(xml1)
|
|
94 |
assert doc2.commentLog.branchInfo.category == ""
|
|
95 |
|
|
96 |
doc2.commentLog.xml_remove_child(doc2.commentLog.branchInfo)
|
|
97 |
|
|
98 |
myxml3 = """<a><b value="1"/></a>"""
|
|
99 |
xml3 = amara.parse(myxml3)
|
|
100 |
for p_temp in xml3.xml_xpath("//b"):
|
|
101 |
p_temp.value = u'2'
|
|
102 |
assert '2' in xml3.xml()
|
|
103 |
|
|
104 |
xml4 = """<a>\n\t<b name="b">a</b>\n</a>"""
|
|
105 |
|
|
106 |
print amara.parse(xml4).xml(indent="yes").replace('\n', 'n').replace('\t', 't')
|
|
107 |
assert xml4 in amara.parse(xml4).xml(indent="yes")
|
|
108 |
|
|
109 |
ppxml = """<SettingsData>
|
|
110 |
<ProductProfile Version="1.1">
|
|
111 |
<Feature>
|
|
112 |
<Index>35</Index>
|
|
113 |
<Value>1</Value>
|
|
114 |
</Feature>
|
|
115 |
</ProductProfile>
|
|
116 |
</SettingsData>"""
|
|
117 |
|
|
118 |
newppxml = amara.parse(ppxml)
|
|
119 |
oldppxml = amara.parse(ppxml)
|
|
120 |
|
|
121 |
oldppdata = {}
|
|
122 |
for oldfeature in oldppxml.SettingsData.ProductProfile.Feature:
|
|
123 |
oldppdata[str(oldfeature.Index)] = oldfeature.Value
|
|
124 |
for newfeature in newppxml.SettingsData.ProductProfile.Feature:
|
|
125 |
if not oldppdata.has_key(str(newfeature.Index)):
|
|
126 |
raise Exception(newfeature.Value)
|
|
127 |
elif oldppdata[str(newfeature.Index)] != str(newfeature.Value):
|
|
128 |
raise Exception(str(oldppdata[str(newfeature.Index)]) + ' ' + str(newfeature.Value))
|
|
129 |
|
|
130 |
def test_amara_xinclude():
|
|
131 |
(f_desc1, filename1) = tempfile.mkstemp()
|
|
132 |
f_file1 = os.fdopen(f_desc1, 'w')
|
|
133 |
f_file1.write(r'<b>qwerty</b>')
|
|
134 |
f_file1.close()
|
|
135 |
(f_desc, filename) = tempfile.mkstemp()
|
|
136 |
f_file = os.fdopen(f_desc, 'w')
|
|
137 |
|
|
138 |
#try:
|
|
139 |
# from Ft.Lib import Uri
|
|
140 |
# fileurl = Uri.OsPathToUri(filename1)
|
|
141 |
#except ImportError:
|
|
142 |
fileurl = filename1
|
|
143 |
|
|
144 |
f_file.write(r'<a xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include href="' + os.path.basename(fileurl) + r'"/></a>')
|
|
145 |
f_file.close()
|
|
146 |
|
|
147 |
#if 'java' in sys.platform:
|
|
148 |
doc3 = amara.parse(urllib.pathname2url(filename))
|
|
149 |
#else:
|
|
150 |
# doc3 = amara.parse(Uri.OsPathToUri(filename))
|
|
151 |
assert 'qwerty' in doc3.xml() |