source: qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_layer_drawer_coastline.py @ 5735

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_layer_drawer_coastline.py@5735
Revision 5735, 3.0 KB checked in by pnorton, 10 years ago (diff)

Added the ability to change the coastline colour in the coastline layer drawer. Also fixed a minor problem with the colour bar that was causing problems when unicode is used rather than strings.

Line 
1'''
2Created on 15 Sep 2009
3
4@author: pnorton
5'''
6__test__=True
7
8import unittest
9import nose.tools as nt
10import logging
11import nose
12import random 
13
14import matplotlib.colors
15
16from geoplot.layer_drawer_coastline import LayerDrawerCoastlines
17
18
19log = logging.getLogger(__name__)
20
21class TestLayerDrawerCoastline(unittest.TestCase):
22
23    def setUp(self):
24        self.ldc = LayerDrawerCoastlines()
25   
26    def tearDown(self):
27        pass
28
29    def test_001_getMaptlotlibColour(self):
30       
31        #for all the html colour names should just return the string back
32        for c in matplotlib.colors.cnames.keys():
33            nt.assert_equal(c, self.ldc._getMatplotlibColour(c))
34           
35        #for all the single letter colours
36        for c in list('bgrcmykw'):
37            nt.assert_equal(c, self.ldc._getMatplotlibColour(c))
38       
39        hexChars = list('0123456789abcdef')
40       
41        #test a few random hex colours
42        for i in range(10):
43            hexString = "#" +"".join([random.choice(hexChars) for i in range(6)])
44            nt.assert_equal(hexString, self.ldc._getMatplotlibColour(hexString))
45       
46        #a few float values
47        for i in range(10):
48            x = random.random()
49            strX = "%.3f" % x
50            nt.assert_equal(strX, self.ldc._getMatplotlibColour(strX))
51            nt.assert_equal(str(x), self.ldc._getMatplotlibColour(x))
52       
53        #without the decimal point
54        nt.assert_equal('1', self.ldc._getMatplotlibColour('1'))
55        nt.assert_equal('0', self.ldc._getMatplotlibColour('0'))
56       
57        #string not in the html colours list
58        nt.assert_raises(ValueError, LayerDrawerCoastlines._getMatplotlibColour,
59                         self.ldc, 'notavalidhtmlcolour')
60       
61        #character not in the single leter colusr
62        nt.assert_raises(ValueError, LayerDrawerCoastlines._getMatplotlibColour,
63                         self.ldc, 'z')       
64       
65        #improperly formatted hex colour
66        nt.assert_raises(ValueError,  LayerDrawerCoastlines._getMatplotlibColour,
67                         self.ldc, '#nothex')
68               
69        #integer too big
70        nt.assert_raises(ValueError,  LayerDrawerCoastlines._getMatplotlibColour,
71                         self.ldc, '1.001')       
72   
73    def test_002_coastlineColourProperty(self):
74        #initial colour should be black
75        nt.assert_equal(self.ldc.coastlineColour, 'black')
76       
77        #attempting to set it to an ivalid colour won't change the colour
78        self.ldc.coastlineColour = 'notavalidcolouratall'
79       
80        nt.assert_equal(self.ldc.coastlineColour, 'black')
81       
82        #setting it to a valid colour will change it
83        self.ldc.coastlineColour = 'red'
84       
85        nt.assert_equal(self.ldc.coastlineColour, 'red')
86       
87       
88       
89
90def suite():
91    suite = unittest.TestSuite()
92    suite.addTest(unittest.makeSuite(TestLayerDrawerCoastline))
93    return suite
94
95if __name__ == "__main__":
96    nose.runmodule()
97   
Note: See TracBrowser for help on using the repository browser.