/[thuban]/branches/WIP-pyshapelib-bramz/test/test_classification.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/test/test_classification.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 395 - (show annotations)
Mon Feb 10 15:28:02 2003 UTC (22 years ago) by jonathan
Original Path: trunk/thuban/test/test_classification.py
File MIME type: text/x-python
File size: 2974 byte(s)
fix tests to work with new code changes.

1 # Copyright (c) 2002 by Intevation GmbH
2 # Authors:
3 # Jonathan Coles <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 """
9 Test the Classification class
10 """
11
12 __version__ = "$Revision$"
13 # $Source$
14 # $Id$
15
16 import unittest
17
18 import support
19 support.initthuban()
20
21 from Thuban.Model.classification import Classification
22 from Thuban.Model.layer import Layer
23
24
25 class TestClassification(unittest.TestCase):
26
27 def test_classification(self):
28 """Test Classification"""
29
30 layer = Layer("asdf", "../Data/iceland/political.shp")
31
32 #
33 # init with no params
34 #
35 c = Classification(layer)
36 self.assertEqual(c.field, None)
37 self.assertNotEqual(c.DefaultData, None)
38
39 #
40 # SetField
41 #
42 c = Classification(layer)
43 c.SetField("Test")
44 self.assertEqual(c.field, "Test")
45 c.SetField(None)
46 self.assertEqual(c.field, None)
47
48 #
49 # init with field
50 #
51 c = Classification(layer, "Test")
52 self.assertEqual(c.field, "Test")
53
54 #
55 # AddRange
56 #
57 c0 = Classification(layer, "c0")
58 default0 = c0.GetDefaultData()
59 self.assertRaises(ValueError, c0.AddRange, 0, 0, None)
60 self.assertRaises(ValueError, c0.AddRange, 10, 0, None)
61 c0.AddRange(-10, 0, "1")
62 c0.AddRange(0, 10, "2")
63
64 #
65 # AddPoint
66 #
67 c1 = Classification(layer, "c1")
68 default1 = c1.GetDefaultData()
69 c1.AddPoint(0, "1")
70 c1.AddPoint("0", "2")
71 self.assertRaises(TypeError, c1.AddPoint, {'monty':'python'}, "3")
72
73 #
74 # GetProperties
75 #
76
77 self.assertEqual(c0.GetProperties(-10), "1")
78 self.assertEqual(c0.GetProperties(-11), default0)
79 self.assertEqual(c0.GetProperties(0), "2") # min <= x < max
80 self.assertEqual(c0.GetProperties(10), default0)
81 self.assertEqual(c0.GetProperties(11), default0)
82
83 self.assertEqual(c1.GetProperties(0), "1")
84 self.assertEqual(c1.GetProperties("0"), "2")
85 self.assertEqual(c1.GetProperties(-1), default1)
86 self.assertEqual(c1.GetProperties(1), default1)
87 self.assertRaises(TypeError, c1.GetProperties, {'monty':'python'})
88
89 #
90 # toggle field
91 #
92
93 c0.SetField(None)
94 self.assertEqual(c0.GetProperties(10), default0)
95 self.assertEqual(c0.GetProperties(11), default0)
96
97 c1.SetField(None)
98 self.assertEqual(c1.GetProperties(0), default1)
99 self.assertEqual(c1.GetProperties("0"), default1)
100
101 c0.SetField("c0")
102 self.assertEqual(c0.GetProperties(10), default0)
103 self.assertEqual(c0.GetProperties(11), default0)
104
105 c1.SetField("c1")
106 self.assertEqual(c1.GetProperties(0), "1")
107 self.assertEqual(c1.GetProperties("0"), "2")
108
109 if __name__ == "__main__":
110 unittest.main()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26