source: qesdi/geoplot/trunk/lib/geoplot/tests/test_utils.py @ 5403

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/tests/test_utils.py@5403
Revision 5403, 1.3 KB checked in by pnorton, 11 years ago (diff)

Moved QESDI tree from DCIP repository
 http://proj.badc.rl.ac.uk/svn/dcip/qesdi@3900.

Line 
1#/urs/bin/env python
2"""
3test_utils.py
4
5utility functions for testing modules
6"""
7
8import types
9
10def _floatCompare(f1,f2,thres=0.00001):
11    """
12    compairs two float numbers for equality using a threshold value
13    """
14    if f1 == f2: return True
15    size = (abs(f1) + abs(f2))/2
16    return abs((f1-f2)/size) < thres
17
18def _areNumericListsEqual(result,answer):
19    """
20    tests if two lists are equal (converts all values to float before comparison)
21    """
22    if (len(result) != len(answer)):
23        return False
24
25    for x in answer:
26        x = float(x)
27        found = False
28        for y in result:
29            y = float(y)
30            if _floatCompare(x,y):
31                found = True
32                break
33
34        if not found:
35            return False
36
37    return True
38
39def _comparePublicAttribues(A, B):
40
41    #check the attributes of the axis
42    for key in dir(A):
43        if key[0] == '_': #ignore private attributes
44            continue
45        attA = getattr(A,key)
46        if type(attA) == types.MethodType: #ignore methods
47            continue
48        #print key, type(getattr(axisA,key)), getattr(axisA,key)
49        if getattr(A, key) != getattr(B,key): #compair the public attributes
50            #print "attribute:", key, "doesn't match ", \
51            #       getattr(axisA, key), ",", getattr(axisB,key)
52            return False
53
54    return True
Note: See TracBrowser for help on using the repository browser.