114 |
self.assertEquals(proj.EPSGCode(), "42") |
self.assertEquals(proj.EPSGCode(), "42") |
115 |
|
|
116 |
|
|
|
class ProjFileTest(unittest.TestCase, support.FileTestMixin): |
|
117 |
|
|
118 |
"""Base class for the proj file tests""" |
class TestProjFileSimple: |
119 |
|
|
120 |
def filename(self): |
def test_init(self): |
121 |
"""Return the filename for the test""" |
"""Test ProjFile coinstructor""" |
122 |
return self.temp_file_name(self.id() + ".proj") |
proj_file = ProjFile("some_filename") |
123 |
|
self.assertEquals(proj_file.GetFilename(), "some_filename") |
124 |
|
self.assertEquals(len(proj_file.GetProjections()), 0) |
125 |
|
|
126 |
|
def test_set_filename(self): |
127 |
|
"""Test ProjFile.SetFilename()""" |
128 |
|
proj_file = ProjFile("some_filename") |
129 |
|
proj.SetFilename("other_name") |
130 |
|
self.assertEquals(proj_file.GetFilename(), "other_name") |
131 |
|
|
132 |
|
|
133 |
class TestProjFile(ProjFileTest, xmlsupport.ValidationTest): |
class TestProjFile(unittest.TestCase): |
134 |
|
|
135 |
"""Test cases for reading and writing projection files. |
"""Test cases for reading and writing projection files. |
136 |
""" |
""" |
137 |
|
|
138 |
def test(self): |
def setUp(self): |
139 |
"""Test ProjFile""" |
self.proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
140 |
|
self.proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
141 |
|
self.proj2 = Projection(["proj=lcc", "ellps=clrk66", |
142 |
|
"lat_1=0", "lat_2=20"]) |
143 |
|
|
144 |
|
def test_add_remove(self): |
145 |
|
"""Test ProjFile.Add() and ProjFile.Remove()""" |
146 |
|
proj_file = ProjFile("some_filename") |
147 |
|
proj_file.Add(self.proj0) |
148 |
|
proj_file.Add(self.proj1) |
149 |
|
self.assertEquals(proj_file.GetProjections(), [self.proj0, self.proj1]) |
150 |
|
proj_file.Remove(self.proj0) |
151 |
|
self.assertEquals(proj_file.GetProjections(), [self.proj1]) |
152 |
|
|
153 |
|
def test_remove_non_existing(self): |
154 |
|
"""Test ProjFile.Remove(<proj not in projfile>)""" |
155 |
|
proj_file = ProjFile("some_filename") |
156 |
|
self.assertRaises(ValueError, proj_file.Remove, self.proj0) |
157 |
|
|
158 |
|
def test_replace(self): |
159 |
|
"""Test ProjFile.Replace()""" |
160 |
|
proj_file = ProjFile("some_filename") |
161 |
|
proj_file.Add(self.proj0) |
162 |
|
proj_file.Add(self.proj1) |
163 |
|
|
164 |
proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
# Replace() |
165 |
proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
proj_file.Replace(self.proj0, self.proj2) |
166 |
proj2 = Projection(["proj=lcc", "ellps=clrk66", |
self.assertEquals(proj_file.GetProjections(), [self.proj2, self.proj1]) |
|
"lat_1=0", "lat_2=20"]) |
|
|
|
|
|
eq = self.assertEquals |
|
|
|
|
|
|
|
|
# |
|
|
# __init__() |
|
|
# GetFilename() |
|
|
# SetFilename() |
|
|
# |
|
|
for name in ["", "hello_world"]: |
|
|
projFile = ProjFile(name) |
|
|
eq(projFile.GetFilename(), name) |
|
|
|
|
|
projFile.SetFilename("XXX") |
|
|
projFile.SetFilename(name) |
|
|
eq(projFile.GetFilename(), name) |
|
|
|
|
|
# initial number of projections should be 0 |
|
|
eq(len(projFile.GetProjections()), 0) |
|
|
|
|
|
# |
|
|
# Add() |
|
|
# Remove() |
|
|
# |
|
|
projFile.Add(proj0) |
|
|
eq(len(projFile.GetProjections()), 1) |
|
|
projFile.Remove(proj0) |
|
|
eq(len(projFile.GetProjections()), 0) |
|
|
|
|
|
# try to remove something that doesn't exist |
|
|
self.assertRaises(ValueError, projFile.Remove, None) |
|
|
self.assertRaises(ValueError, projFile.Remove, proj0) |
|
|
|
|
|
projFile.Add(proj0) |
|
|
projFile.Add(proj1) |
|
|
projFile.Add(proj2) |
|
|
eq(len(projFile.GetProjections()), 3) |
|
|
|
|
|
# GetProjections() -- tests order |
|
|
projs = projFile.GetProjections() |
|
|
eq(projs[0], proj0) |
|
|
eq(projs[1], proj1) |
|
|
eq(projs[2], proj2) |
|
167 |
|
|
168 |
projFile.Remove(proj2) |
def test_replace_non_existing(self): |
169 |
projFile.Remove(proj1) |
"""Test ProjFile.Replace(<proj not in projfile>, <some proj>)""" |
170 |
|
proj_file = ProjFile("some_filename") |
171 |
|
proj_file.Add(self.proj0) |
172 |
|
proj_file.Add(self.proj1) |
173 |
|
self.assertRaises(ValueError, |
174 |
|
proj_file.Replace, self.proj2, self.proj0) |
175 |
|
|
176 |
# Replace() |
|
177 |
projFile.Replace(proj0, proj1) |
class ProjFileTest(unittest.TestCase, support.FileTestMixin, |
178 |
projs = projFile.GetProjections() |
xmlsupport.ValidationTest): |
179 |
eq(projs[0], proj1) |
|
180 |
|
"""Base class for the proj file tests that read or write files""" |
181 |
# replace a non-existent projection |
|
182 |
self.assertRaises(ValueError, projFile.Replace, None, proj2) |
def filename(self): |
183 |
self.assertRaises(ValueError, projFile.Replace, proj0, proj2) |
"""Return the filename for the test""" |
184 |
|
return self.temp_file_name(self.id() + ".proj") |
185 |
|
|
186 |
|
|
187 |
|
class ProjFileReadTests(ProjFileTest): |
188 |
|
|
189 |
|
"""Test read ProjFile objects from files""" |
190 |
|
|
191 |
def test_read_non_existing_file(self): |
def test_read_non_existing_file(self): |
192 |
"""Test read_proj_file with non-existing file""" |
"""Test read_proj_file with non-existing file""" |
226 |
self.assert_(len(projfile.GetProjections()) > 0) |
self.assert_(len(projfile.GetProjections()) > 0) |
227 |
|
|
228 |
|
|
229 |
class WriteProjFileTests(ProjFileTest, xmlsupport.ValidationTest): |
class WriteProjFileTests(ProjFileTest): |
230 |
|
|
231 |
"""Test cases for writing proj files""" |
"""Test cases for writing proj files""" |
232 |
|
|