/usr/lib/python3/dist-packages/pydap/tests/test_wsgi_functions.py is in python3-pydap 3.2.2+ds1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | """Test the server-side functions that come with Pydap."""
import copy
from webtest import TestApp as App
from pydap.handlers.lib import BaseHandler
from pydap.tests.datasets import SimpleSequence, SimpleGrid
from pydap.wsgi.ssf import ServerSideFunctions
from pydap.exceptions import ConstraintExpressionError, ServerError
import unittest
class TestDensity(unittest.TestCase):
"""Test the density function."""
def setUp(self):
"""Create simple WSGI app."""
self.app = App(ServerSideFunctions(BaseHandler(SimpleSequence)))
def test_wrong_type(self):
"""Test passing the wrong type."""
app = App(ServerSideFunctions(BaseHandler(SimpleGrid)))
with self.assertRaises(ConstraintExpressionError):
app.get('/.dds?density(SimpleGrid,SimpleGrid,SimpleGrid)')
def test_plain(self):
"""Test a direct request."""
res = self.app.get('/.asc')
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'"1", 100, -10, 0, -1, 21, 35, 0\n'
'"2", 200, 10, 500, 1, 15, 35, 100\n'
'\n')
def test_projection(self):
"""Test using density as a projection."""
res = self.app.get(
'/.asc?density(cast.salinity,cast.temperature,cast.pressure)')
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Float64 rho;\n'
' } result;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'result.rho\n'
'1024.37\n'
'1026.29\n'
'\n')
def test_selection(self):
"""Test using density as a selection."""
res = self.app.get(
"/.asc?cast.temperature&"
"density(cast.salinity,cast.temperature,cast.pressure)>1025")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Int32 temperature;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.temperature\n'
'15\n'
'\n')
class TestBounds(unittest.TestCase):
"""Test the ``bounds`` function, used by GrADS."""
def setUp(self):
"""Create a simple WSGI app."""
self.app = App(ServerSideFunctions(BaseHandler(SimpleSequence)))
def test_wrong_type(self):
"""Test passing a wrong type to the function."""
app = App(ServerSideFunctions(BaseHandler(SimpleGrid)))
with self.assertRaises(ConstraintExpressionError):
app.get('/.dds?SimpleGrid'
'&bounds(0,360,-90,90,500,500,00Z01JAN1970,00Z01JAN1970)')
def test_default(self):
"""Test the default bounding box."""
res = self.app.get('/.asc?cast&bounds(0,360,-90,90,0,500,'
'00Z01JAN1970,00Z01JAN1970)')
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'\n')
def test_selection_only(self):
"""Test using the function alone in the selection."""
res = self.app.get('/.asc?bounds(0,360,-90,90,0,500,'
'00Z01JAN1970,00Z01JAN1970)')
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'\n')
def test_subset(self):
"""Test a requesting a subset of the data."""
res = self.app.get('/.asc?bounds(0,360,-90,90,0,500,'
'00Z01JAN1970,00Z31JAN1970)')
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'"2", 200, 10, 500, 1, 15, 35, 100\n'
'\n')
def test_subset_with_selection(self):
"""Test combining selections."""
res = self.app.get("/.asc?"
"bounds(0,360,-90,90,0,500,"
"00Z01JAN1969,00Z31JAN1970)&cast.lat<0")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'"1", 100, -10, 0, -1, 21, 35, 0\n'
'\n')
def test_projection(self):
"""Test bounds used as a projection."""
res = self.app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,"
"00Z01JAN1970,00Z31JAN1970)")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.pressure\n'
'100\n'
'\n')
def test_point(self):
"""Test a request for a point."""
res = self.app.get("/.asc?bounds(100,100,-10,-10,0,0,"
"00Z31DEC1969,00Z31DEC1969)")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' String id;\n'
' Int32 lon;\n'
' Int32 lat;\n'
' Int32 depth;\n'
' Int32 time;\n'
' Int32 temperature;\n'
' Int32 salinity;\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.id, cast.lon, cast.lat, cast.depth, cast.time, '
'cast.temperature, cast.salinity, cast.pressure\n'
'"1", 100, -10, 0, -1, 21, 35, 0\n'
'\n')
def test_grads_step(self):
"""Test different GrADS time steps."""
modified = copy.copy(SimpleSequence)
modified.cast.time.attributes['grads_step'] = '1mn'
app = App(ServerSideFunctions(BaseHandler(modified)))
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,12Z01JAN1970,12Z01JAN1970)")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.pressure\n'
'\n')
modified.cast.time.attributes['grads_step'] = '1hr'
app = App(ServerSideFunctions(BaseHandler(modified)))
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,12Z01JAN1970,12Z01JAN1970)")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.pressure\n'
'\n')
modified.cast.time.attributes['grads_step'] = '1dy'
app = App(ServerSideFunctions(BaseHandler(modified)))
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,12Z01JAN1970,12Z01JAN1970)")
self.assertEqual(res.text,
'Dataset {\n'
' Sequence {\n'
' Int32 pressure;\n'
' } cast;\n'
'} SimpleSequence;\n'
'---------------------------------------------\n'
'cast.pressure\n'
'100\n'
'\n')
modified.cast.time.attributes['grads_step'] = '1mo'
app = App(ServerSideFunctions(BaseHandler(modified)))
with self.assertRaises(NotImplementedError):
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,"
"12Z01JAN1970,12Z01JAN1970)")
modified.cast.time.attributes['grads_step'] = '1yr'
app = App(ServerSideFunctions(BaseHandler(modified)))
with self.assertRaises(NotImplementedError):
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,"
"12Z01JAN1970,12Z01JAN1970)")
modified.cast.time.attributes['grads_step'] = '1xx'
app = App(ServerSideFunctions(BaseHandler(modified)))
with self.assertRaises(ServerError):
res = app.get("/.asc?cast.pressure&"
"bounds(0,360,-90,90,0,500,"
"12Z01JAN1970,12Z01JAN1970)")
class TestMean(unittest.TestCase):
"""Test the ``mean`` function."""
def setUp(self):
"""Create a simple WSGI app."""
self.app = App(ServerSideFunctions(BaseHandler(SimpleGrid)))
def test_wrong_type(self):
"""Test passing a wrong type to mean function."""
app = App(ServerSideFunctions(BaseHandler(SimpleSequence)))
with self.assertRaises(ConstraintExpressionError):
app.get('/.dds?mean(sequence)')
def test_base_type(self):
"""Test mean of base types."""
res = self.app.get("/.asc?mean(x)")
self.assertEqual(res.text,
'Dataset {\n'
' Float64 x;\n'
'} SimpleGrid;\n'
'---------------------------------------------\n'
'x\n'
'1\n')
def test_grid_type(self):
"""Test mean of grid objects."""
res = self.app.get("/.asc?mean(SimpleGrid)")
self.assertEqual(res.text,
'Dataset {\n'
' Grid {\n'
' Array:\n'
' Float64 SimpleGrid[y = 3];\n'
' Maps:\n'
' Int32 y[y = 2];\n'
' } SimpleGrid;\n'
'} SimpleGrid;\n'
'---------------------------------------------\n'
'SimpleGrid.SimpleGrid\n'
'[0] 1.5\n'
'[1] 2.5\n'
'[2] 3.5\n'
'\n'
'SimpleGrid.y\n'
'[0] 0\n'
'[1] 1\n'
'\n'
'\n')
def test_nested(self):
"""Test nested function calls."""
res = self.app.get("/.asc?mean(mean(SimpleGrid))")
self.assertEqual(res.text,
'Dataset {\n'
' Grid {\n'
' Array:\n'
' Float64 SimpleGrid;\n'
' Maps:\n'
' } SimpleGrid;\n'
'} SimpleGrid;\n'
'---------------------------------------------\n'
'SimpleGrid.SimpleGrid\n'
'2.5\n'
'\n')
|