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

Diff of /branches/WIP-pyshapelib-bramz/test/test_load.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 610 by jonathan, Fri Apr 4 13:56:59 2003 UTC revision 684 by jonathan, Tue Apr 15 21:55:12 2003 UTC
# Line 19  import unittest Line 19  import unittest
19  import support  import support
20  support.initthuban()  support.initthuban()
21    
22  from Thuban.Model.load import load_session  from Thuban.Model.load import load_session, parse_color
23  from Thuban.Model.session import Session  from Thuban.Model.session import Session
24  from Thuban.Model.map import Map  from Thuban.Model.map import Map
25  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
26  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
27  from Thuban.Model.color import Color  from Thuban.Model.color import Color
28    
29    from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, FIELDTYPE_STRING
30    
31    from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\
32        ClassGroupSingleton, ClassGroupDefault
33    
34  def filenames_equal(name1, name2):  def filenames_equal(name1, name2):
35      """Return true if the filenames name1 and name2 are equal.      """Return true if the filenames name1 and name2 are equal.
36    
# Line 101  class LoadSessionTest(unittest.TestCase, Line 106  class LoadSessionTest(unittest.TestCase,
106          eq(layer.GetClassification().GetDefaultFill(), Color.Transparent)          eq(layer.GetClassification().GetDefaultFill(), Color.Transparent)
107          eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000")          eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000")
108    
109            self.session.Destroy()
110            self.session = None
111    
112        def testClassification(self):
113            """Load a session with a map and classified layers."""
114    
115            eq = self.assertEquals
116            session = load_session("../Data/iceland_sample_test.thuban")
117            self.session = session
118    
119            map = self.session.Maps()[0] # only one map in the sample
120    
121            layers = map.Layers()
122            eq(len(layers), 3)
123    
124            expected = (("political", 0,
125                            [("default", (), "",
126                                ("#000000", 1, "#c0c0c0"))]),
127                        ("roads-line", 5,
128                            [("default", (), "",
129                                ("#000000", 1, "None")),
130                             ("range", (0.001, 0.3996), "short roads",
131                                ("#ffffff", 1, "#ffffff")),
132                             ("range", (0.3996, 0.7982), "less short",
133                                ("#ccf4cc", 1, "#ccf4cc")),
134                             ("range", (0.7982, 1.1968), "bit longer",
135                                ("#99ea99", 1, "#99ea99")),
136                             ("range", (1.1968, 1.5954), "where's the end?",
137                                ("#66e066", 1, "#66e066")),
138                             ("range", (1.5954, 1.994), "long roads",
139                                ("#33d633", 1, "#33d633"))]),
140                        ("something else", 6,
141                            [("default", (), "",
142                                ("#000000", 1, "None")),
143                             ("single", ("BUILDING"),  "",
144                                ("#0000ff", 1, "#0000ff")),
145                             ("single", ("FARM"), "",
146                                ("#00aaff", 1, "#00aaff")),
147                             ("single", ("HUT"), "",
148                                ("#00ffaa", 1, "#00ffaa")),
149                             ("single", ("LIGHTHOUSE"), "",
150                                ("#00ff00", 1, "#00ff00")),
151                             ("single", ("OTHER/UNKNOWN"), "",
152                                ("#aaff00", 1, "#aaff00")),
153                             ("single", ("RUINS"), "",
154                                ("#ffaa00", 1, "#ffaa00"))]))
155    
156            eq(len(layers), len(expected))
157    
158            TITLE = 0
159            NUM_GROUPS = 1
160            CLASSES = 2
161            GROUP_TYPE = 0
162            GROUP_DATA = 1
163            GROUP_LABEL = 2
164            GROUP_PROPS = 3
165    
166            for layer, data in zip(layers, expected):
167                eq(layer.Title(), data[TITLE])
168    
169                clazz = layer.GetClassification()
170                eq(clazz.GetNumGroups(), data[NUM_GROUPS])
171                eq(clazz.GetNumGroups() + 1, len(data[CLASSES]))
172    
173                i = 0
174                for group in clazz:
175                    
176                    props = ClassGroupProperties()
177                    props.SetLineColor(
178                        parse_color(data[CLASSES][i][GROUP_PROPS][0]))
179                    props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1])
180                    props.SetFill(
181                        parse_color(data[CLASSES][i][GROUP_PROPS][2]))
182    
183                    if data[CLASSES][i][GROUP_TYPE] == "default":
184                        g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL])
185                    elif data[CLASSES][i][GROUP_TYPE] == "range":
186                        g = ClassGroupRange(data[CLASSES][i][GROUP_DATA][0],
187                                            data[CLASSES][i][GROUP_DATA][1],
188                                            props, data[CLASSES][i][GROUP_LABEL])
189                    elif data[CLASSES][i][GROUP_TYPE] == "single":
190                        g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA],
191                                              props, data[CLASSES][i][GROUP_LABEL])
192    
193                    eq(group, g)
194    
195                    i += 1
196    
197  if __name__ == "__main__":  if __name__ == "__main__":
198      unittest.main()      unittest.main()
199    
200    
201    

Legend:
Removed from v.610  
changed lines
  Added in v.684

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26