20 """ amara.py module tests. """ |
20 """ amara.py module tests. """ |
21 |
21 |
22 |
22 |
23 import amara |
23 import amara |
24 from xmlhelper import recursive_node_scan |
24 from xmlhelper import recursive_node_scan |
|
25 import urllib |
|
26 import tempfile |
|
27 import os |
|
28 import sys |
25 |
29 |
26 def test_amara(): |
30 def test_amara(): |
27 """test amara""" |
31 """test amara""" |
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>') |
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>') |
29 assert str(xxx.commentLog.branchInfo) == 'Add rofsfiles for usage in paged images' |
33 assert str(xxx.commentLog.branchInfo) == 'Add rofsfiles for usage in paged images' |
78 found = True |
82 found = True |
79 assert found |
83 assert found |
80 |
84 |
81 #xcf5 = amara.parse(open(r'C:\USERS\helium\helium-dev-forbuilds\helium\tests\data\bom\build_model_bom.xml')) |
85 #xcf5 = amara.parse(open(r'C:\USERS\helium\helium-dev-forbuilds\helium\tests\data\bom\build_model_bom.xml')) |
82 #u'%s' % xcf5.bom.content.project.folder.task.synopsis |
86 #u'%s' % xcf5.bom.content.project.folder.task.synopsis |
|
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() |