source: cows/trunk/cows/test/iface_test_lib.py @ 5399

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/test/iface_test_lib.py@5399
Revision 5399, 3.1 KB checked in by domlowe, 12 years ago (diff)

Changing PIL imports in cows

Line 
1# BSD Licence
2# Copyright (c) 2009, Science & Technology Facilities Council (STFC)
3# All rights reserved.
4#
5# See the LICENSE file in the source distribution of this software for
6# the full license text.
7
8"""
9Abstract base classes for testing the interfaces defined in cows.service.*_iface
10
11"""
12
13import unittest
14try:
15    from PIL import Image
16except ImportError:
17    import Image
18
19def assert_iterable(a):
20    try:
21        iter(a)
22    except:
23        raise AssertionError("Not Iterable")
24
25class TestILayer(unittest.TestCase):
26    """
27    Abstract base class for testing ILayer implementations.  Set self.layer
28    in subclasses.
29   
30    @cvar layer: An ILayer implementation to test.
31    @note: Set self.__test__ to True to activate subclasses.
32   
33    """
34   
35    __test__ = False
36    layer = NotImplementedError
37   
38    #!TODO: Put self.crss in wxs_iface. 
39    #    (spascoe) I think self.crss was originally part of the
40    #    ILayer when it was in wms_iface but appears to be missing from wxs_iface.
41    #    If getBBox is part of ILayer we logically need to know which
42    #    CRSs it supports.
43    def test_attributes(self):
44        assert self.layer.title != NotImplemented
45        assert self.layer.abstract != NotImplemented
46        if self.layer.featureInfoFormat != None:
47            assert_iterable(self.layer.featureInfoFormat)
48
49        assert_iterable(self.layer.crss)
50 
51    def test_getBBox(self):
52        for crs in self.layer.crss:
53            print 'Testing getBBox on CRS=%s' % crs
54            bbox = self.layer.getBBox(crs)
55            assert len(bbox) == 4
56            try:
57                [float(x) for x in bbox]
58            except:
59                raise AssertionError("BBox parameters not convertible to float")
60            llx, lly, urx, ury = bbox
61            assert llx < urx
62            assert lly < ury
63           
64class TestIwmsLayer(TestILayer):
65    def test_attributes(self):
66        width, height = self.legendSize
67        assert type(width) == int
68        assert type(height) == int
69       
70    def test_dimensions(self):
71        assert_iterable(self.layer.dimensions)
72        for dimName, dim in self.layer.dimensions.items():
73            assert dimName
74            assert dim.units != NotImplemented
75            assert_iterable(dim.extent)
76           
77    def test_getSlab(self):
78        for crs in self.layer.crss:
79            self.do_getSlab(crs)
80
81    #-------------------------------------------------------------------------
82
83    def do_getSlab(self, crs, renderOpts={}, extentIndex=0):
84        dimVals = {}
85        for dimName, dim in self.layer.dimensions.items():
86            dimVals[dimName] = dim[extentIndex]
87
88        slab = self.layer.getSlab(crs, dimVals, renderOpts)
89        self.assert_isSlab(slab)
90           
91    def assert_isSlab(self, slab):
92        attrs = ['layer', 'crs', 'dimValues', 'renderOpts', 'bbox']
93        for attr in attrs:
94            assert hasattr(slab, attr)
95       
96        img = slab.getImage(slab.bbox, 50, 50)
97        assert isinstance(img, Image.Image)
98        assert img.size == (50, 50)
99       
100    #!TODO: getLegendImage and getFeatureInfo.
101       
Note: See TracBrowser for help on using the repository browser.