Ulrich Carmesin
3 years ago
2 changed files with 138 additions and 0 deletions
@ -0,0 +1,94 @@ |
|||||
|
import unittest |
||||
|
#import basic.program |
||||
|
import utils.xml_tool |
||||
|
import utils.xml_tool |
||||
|
|
||||
|
class MyTestCase(unittest.TestCase): |
||||
|
def xtest_xmlTool(self): |
||||
|
#job = basic.program.Job("unit") |
||||
|
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", |
||||
|
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", |
||||
|
"modus": "unit"} |
||||
|
beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}} |
||||
|
tree = {} |
||||
|
tree["root"] = args |
||||
|
xml = utils.xml_tool.dict2xml(tree) |
||||
|
print(xml) |
||||
|
xml = utils.xml_tool.dict2xml(beispiel_json) |
||||
|
print(xml) |
||||
|
self.assertEqual(1, 1) |
||||
|
f = utils.xml_tool.fcts() |
||||
|
|
||||
|
def xtest_addSingle(self): |
||||
|
tree = {} |
||||
|
# tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', 2, "abc") |
||||
|
tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc") |
||||
|
self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc") |
||||
|
self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") |
||||
|
|
||||
|
def xtest_addTwo(self): |
||||
|
# a-b-b |
||||
|
# c-a-a c-a-b |
||||
|
tree = {} |
||||
|
print("--------------------------------------------------------------------------------") |
||||
|
tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc") |
||||
|
print("--------------------------------------------------------------------------------") |
||||
|
tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="LAND"]/wert', 2, "xyz") |
||||
|
baum = {} |
||||
|
baum["root"] = tree |
||||
|
print("<------"+str(baum["root"])) |
||||
|
self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc") |
||||
|
self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") |
||||
|
self.assertEqual(tree["kratz"]["mm"][1]["wert"], "xyz") |
||||
|
self.assertEqual(tree["kratz"]["mm"][1]["@name"], "LAND") |
||||
|
|
||||
|
def xtest_addOnePaths(self): |
||||
|
tree = {} |
||||
|
print("--------------------------------------------------------------------------------") |
||||
|
tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") |
||||
|
baum = {} |
||||
|
baum["root"] = tree |
||||
|
print("<------"+str(baum["root"])) |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["wert"], "abc") |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") |
||||
|
|
||||
|
def xtest_addTwoPaths(self): |
||||
|
tree = {} |
||||
|
print("--------------------------------------------------------------------------------") |
||||
|
tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") |
||||
|
print("--------------------------------------------------------------------------------") |
||||
|
tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="LAND"]/wert', "xyz") |
||||
|
baum = {} |
||||
|
baum["root"] = tree |
||||
|
print("<------"+str(baum["root"])) |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["wert"], "abc") |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") |
||||
|
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") |
||||
|
|
||||
|
def test_tidy(self): |
||||
|
tree_dict = { "eins": "zwei", "drei": "vier" } |
||||
|
tree_dict3 = { "eins": { "zwei": { "drei": "vier" } }} |
||||
|
tree_list = { "eins": [ {"zwei": 2, "drei": 3, "vier": 4 } ] } |
||||
|
tree_attr = { "eins": [ {"zwei": 2, "drei": 3, "vier": { "@name": "attr"} } ] } |
||||
|
tree_attrx = { "eins": [ {"zwei": 2, "drei": 3, "vier": { "@name": "attr", "fuenf": 5} } ] } |
||||
|
c = utils.xml_tool.fcts() |
||||
|
xml = c.tidy(tree_dict, 0) |
||||
|
print("-------------------------------------") |
||||
|
print(xml) |
||||
|
xml = c.tidy(tree_dict3, 0) |
||||
|
print("-------------------------------------") |
||||
|
print(xml) |
||||
|
xml = c.tidy(tree_list, 0) |
||||
|
print("-------------------------------------") |
||||
|
print(xml) |
||||
|
xml = c.tidy(tree_attr, 0) |
||||
|
print("-------------------------------------") |
||||
|
print(xml) |
||||
|
xml = c.tidy(tree_attrx, 0) |
||||
|
print("-------------------------------------") |
||||
|
print(xml) |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
unittest.main() |
||||
|
|
Loading…
Reference in new issue