23 |
from Thuban import _ |
from Thuban import _ |
24 |
from Thuban.Model.proj import Projection, ProjFile, \ |
from Thuban.Model.proj import Projection, ProjFile, \ |
25 |
PROJ_UNITS_METERS, PROJ_UNITS_DEGREES |
PROJ_UNITS_METERS, PROJ_UNITS_DEGREES |
26 |
|
from Thuban.Model.messages import PROJECTION_ADDED, PROJECTION_REMOVED, \ |
27 |
|
PROJECTION_REPLACED |
28 |
import Thuban.Model.resource as resource |
import Thuban.Model.resource as resource |
29 |
|
|
30 |
from xmlsupport import sax_eventlist |
from xmlsupport import sax_eventlist |
131 |
self.assertEquals(proj_file.GetFilename(), "other_name") |
self.assertEquals(proj_file.GetFilename(), "other_name") |
132 |
|
|
133 |
|
|
134 |
class TestProjFile(unittest.TestCase): |
class TestProjFile(unittest.TestCase, support.SubscriberMixin): |
135 |
|
|
136 |
"""Test cases for reading and writing projection files. |
"""Test cases for reading and writing projection files. |
137 |
""" |
""" |
138 |
|
|
139 |
def setUp(self): |
def setUp(self): |
140 |
|
self.clear_messages() |
141 |
self.proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
self.proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
142 |
self.proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
self.proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
143 |
self.proj2 = Projection(["proj=lcc", "ellps=clrk66", |
self.proj2 = Projection(["proj=lcc", "ellps=clrk66", |
144 |
"lat_1=0", "lat_2=20"]) |
"lat_1=0", "lat_2=20"]) |
145 |
|
self.proj_file = ProjFile("some_filename") |
146 |
|
for msg in [PROJECTION_ADDED, PROJECTION_REMOVED, PROJECTION_REPLACED]: |
147 |
|
self.proj_file.Subscribe(msg, self.subscribe_with_params, msg) |
148 |
|
|
149 |
|
def tearDown(self): |
150 |
|
self.clear_messages() |
151 |
|
self.proj_file.Destroy() |
152 |
|
|
153 |
def test_add_remove(self): |
def test_add_remove(self): |
154 |
"""Test ProjFile.Add() and ProjFile.Remove()""" |
"""Test ProjFile.Add() and ProjFile.Remove()""" |
155 |
proj_file = ProjFile("some_filename") |
self.proj_file.Add(self.proj0) |
156 |
proj_file.Add(self.proj0) |
self.proj_file.Add(self.proj1) |
157 |
proj_file.Add(self.proj1) |
self.assertEquals(self.proj_file.GetProjections(), |
158 |
self.assertEquals(proj_file.GetProjections(), [self.proj0, self.proj1]) |
[self.proj0, self.proj1]) |
159 |
proj_file.Remove(self.proj0) |
self.check_messages([(self.proj0, PROJECTION_ADDED), |
160 |
self.assertEquals(proj_file.GetProjections(), [self.proj1]) |
(self.proj1, PROJECTION_ADDED)]) |
161 |
|
self.clear_messages() |
162 |
|
|
163 |
|
self.proj_file.Remove(self.proj0) |
164 |
|
self.assertEquals(self.proj_file.GetProjections(), [self.proj1]) |
165 |
|
self.check_messages([(self.proj0, PROJECTION_REMOVED)]) |
166 |
|
|
167 |
def test_remove_non_existing(self): |
def test_remove_non_existing(self): |
168 |
"""Test ProjFile.Remove(<proj not in projfile>)""" |
"""Test ProjFile.Remove(<proj not in projfile>)""" |
169 |
proj_file = ProjFile("some_filename") |
self.assertRaises(ValueError, self.proj_file.Remove, self.proj0) |
170 |
self.assertRaises(ValueError, proj_file.Remove, self.proj0) |
# Nothing happened, so no messages should have been sent |
171 |
|
self.check_messages([]) |
172 |
|
|
173 |
def test_replace(self): |
def test_replace(self): |
174 |
"""Test ProjFile.Replace()""" |
"""Test ProjFile.Replace()""" |
175 |
proj_file = ProjFile("some_filename") |
self.proj_file.Add(self.proj0) |
176 |
proj_file.Add(self.proj0) |
self.proj_file.Add(self.proj1) |
177 |
proj_file.Add(self.proj1) |
self.clear_messages() |
178 |
|
|
179 |
# Replace() |
# Replace() |
180 |
proj_file.Replace(self.proj0, self.proj2) |
self.proj_file.Replace(self.proj0, self.proj2) |
181 |
self.assertEquals(proj_file.GetProjections(), [self.proj2, self.proj1]) |
self.assertEquals(self.proj_file.GetProjections(), |
182 |
|
[self.proj2, self.proj1]) |
183 |
|
self.check_messages([(self.proj0, self.proj2, PROJECTION_REPLACED)]) |
184 |
|
|
185 |
def test_replace_non_existing(self): |
def test_replace_non_existing(self): |
186 |
"""Test ProjFile.Replace(<proj not in projfile>, <some proj>)""" |
"""Test ProjFile.Replace(<proj not in projfile>, <some proj>)""" |
187 |
proj_file = ProjFile("some_filename") |
self.proj_file.Add(self.proj0) |
188 |
proj_file.Add(self.proj0) |
self.proj_file.Add(self.proj1) |
189 |
proj_file.Add(self.proj1) |
self.clear_messages() |
190 |
self.assertRaises(ValueError, |
self.assertRaises(ValueError, |
191 |
proj_file.Replace, self.proj2, self.proj0) |
self.proj_file.Replace, self.proj2, self.proj0) |
192 |
|
# All projections should still be there |
193 |
|
self.assertEquals(self.proj_file.GetProjections(), |
194 |
|
[self.proj0, self.proj1]) |
195 |
|
# Nothing happened, so no messages should have been sent |
196 |
|
self.check_messages([]) |
197 |
|
|
198 |
|
|
199 |
class ProjFileTest(unittest.TestCase, support.FileTestMixin, |
class ProjFileTest(unittest.TestCase, support.FileTestMixin, |
432 |
|
|
433 |
|
|
434 |
if __name__ == "__main__": |
if __name__ == "__main__": |
435 |
unittest.main() |
support.run_tests() |