Merge "Add a new function into Common to compare two XML files 3 new test case to...
[integration/test.git] / test / csit / libraries / Common.py
1 """
2 Library for the robot based system test tool of the OpenDaylight project.
3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
4 Updated: 2013-11-14
5 """
6 import collections
7 import xml.etree.ElementTree as ET
8
9 '''
10 Common constants and functions for the robot framework.
11 '''
12
13 def collection_should_contain(collection, *members):
14     """
15     Fail if not every members is in the collection.
16     """
17     if not isinstance(collection, collections.Iterable):
18         return False
19     for m in members:
20         if m not in collection:
21             return False
22     else:
23         return True
24
25 def combine_strings(*strings):
26     """
27     Combines the given `strings` together and returns the result.
28     The given strings are not altered by this keyword.
29     """
30     result = ''
31     for s in strings:
32         if isinstance(s,str) or isinstance(s,unicode):
33             result += s
34     if result == '':
35         return None
36     else:
37         return result
38
39         
40 def compare_xml(xml1, xml2):
41     """
42     compare the two XML files to see if they contain the same data
43     but could be if different order.
44     It just split the xml in to lines and just check the line is in
45     the other file 
46     """
47     for line in xml1.rstrip().split('\n'):
48         if line not in xml2.rstrip().split('\n'):
49             return False
50
51     for line in xml2.rstrip().split('\n'):
52         if line not in xml1.rstrip().split('\n'):
53             return False
54
55     return True
56
57     
58
59
60 if __name__ == '__main__':
61     
62
63     pass