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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_utils.py@5403
Revision 5403, 1.9 KB checked in by pnorton, 12 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"""
5
6# Import python modules
7
8# Import third-party software
9import nose
10import matplotlib
11
12import geoplot.utils
13
14class Test_ScaleRGBList(object):
15
16    def setUp(self):
17        pass
18
19    def tearDown(self):
20        pass
21
22    def testScalesRGBListOfInts(self):
23        l = [(63,255,0), (85,85,85), (120,1,14), (0,0,0)]
24        scaledList = geoplot.utils._scaleRGBList(l)
25        expectedResults4db = [(0.2471, 1.0000, 0.0000),
26                              (0.3333, 0.3333, 0.3333),
27                              (0.4706, 0.0039, 0.0549),
28                              (0.0000, 0.0000, 0.0000)]
29        for i in range(len(l)):
30            print scaledList[i], " - ", expectedResults4db[i]
31            assert (round(scaledList[i][0],4) == expectedResults4db[i][0]) # red
32            assert (round(scaledList[i][1],4) == expectedResults4db[i][1]) # green
33            assert (round(scaledList[i][2],4) == expectedResults4db[i][2]) # blue
34
35    def testRaisesExceptionWhenRGBValueLargetThan255(self):
36        l = [(63,255,0), (85,85,85), (120,320,14), (0,0,0)]
37        nose.tools.assert_raises(Exception, geoplot.utils._scaleRGBList, l)
38
39class TestGenerateDiscreteCmap(object):
40
41    def setUp(self):
42        self.l = [(63,255,0), (85,85,85), (120,1,14), (0,0,0)]
43        self.name = 'cmap_name'
44        self.cmap = geoplot.utils.generateDiscreteCmap(self.l, self.name)
45
46    def tearDown(self):
47        self.cmap = None
48        self.name = None
49        self.l = None
50
51    def testCreatesCmapAttributes(self):
52        assert(self.cmap.__class__ == matplotlib.colors.ListedColormap)
53        assert(self.cmap.name == self.name)
54        assert(self.cmap._isinit == False)
55        assert(self.cmap.N == len(self.l))
56
57    def testCreatedCmapColors(self):
58        scaledList = geoplot.utils._scaleRGBList(self.l)
59        assert(scaledList == self.cmap.colors)
60
61# Magic to run tests if executed as a script
62if __name__ == '__main__':
63
64    nose.runmodule()
Note: See TracBrowser for help on using the repository browser.