• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geopython / pywps / 20381518796

19 Dec 2025 08:18PM UTC coverage: 83.74% (-0.4%) from 84.104%
20381518796

Pull #699

github

web-flow
Merge c0aa7db99 into 04f734b97
Pull Request #699: Split extra libraries and add more granular control over tests

63 of 98 new or added lines in 6 files covered. (64.29%)

5 existing lines in 1 file now uncovered.

5418 of 6470 relevant lines covered (83.74%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.26
/tests/validator/test_complexvalidators.py
1
##################################################################
2
# Copyright 2018 Open Source Geospatial Foundation and others    #
3
# licensed under MIT, Please consult LICENSE.txt for details     #
4
##################################################################
5

6
"""Unit tests for complex validator
1✔
7
"""
8

9
from basic import TestBase
1✔
10
import pytest
1✔
11
from pywps.validator.mode import MODE
1✔
12
from pywps.validator.complexvalidator import (
1✔
13
    validategml,
14
    # validategpx,
15
    # validatexml,
16
    validatejson,
17
    validategeojson,
18
    validateshapefile,
19
    validategeotiff,
20
    validatenetcdf,
21
    validatedods,
22
)
23
from pywps.inout.formats import FORMATS
1✔
24
from pywps import ComplexInput
1✔
25
from pywps.inout.basic import SOURCE_TYPE
1✔
26
import tempfile
1✔
27
import os
1✔
28

29

30
netCDF4 = None
1✔
31
try:
1✔
32
    import netCDF4
1✔
33
except ImportError:
×
NEW
34
    pass
×
35

36
geotiff = None
1✔
37
try:
1✔
38
    import geotiff
1✔
NEW
39
except ImportError:
×
NEW
40
    pass
×
41

42
fiona = None
1✔
43
try:
1✔
44
    import fiona
1✔
NEW
45
except (ImportError, ModuleNotFoundError):
×
NEW
46
    pass
×
47

48

49
class ValidateTest(TestBase):
1✔
50
    """Complex validator test cases"""
51

52
    def get_input(self, name, schema, mime_type):
1✔
53

54
        class FakeFormat(object):
1✔
55
            mimetype = 'text/plain'
1✔
56
            schema = None
1✔
57
            units = None
1✔
58

59
            def validate(self, data):
1✔
60
                return True
×
61

62
        class FakeInput(object):
1✔
63
            tempdir = tempfile.mkdtemp(dir=self.tmpdir.name)
1✔
64
            file = os.path.join(
1✔
65
                os.path.abspath(os.path.dirname(__file__)),
66
                '..', 'data', name)
67
            format = FakeFormat()
1✔
68

69
        class data_format(object):
1✔
70
            file = os.path.join(
1✔
71
                os.path.abspath(os.path.dirname(__file__)),
72
                '..', 'data', str(schema))
73

74
        fake_input = FakeInput()
1✔
75
        fake_input.stream = open(fake_input.file)
1✔
76
        fake_input.data_format = data_format()
1✔
77
        if schema:
1✔
78
            fake_input.data_format.schema = 'file://' + fake_input.data_format.file
1✔
79
        fake_input.data_format.mime_type = mime_type
1✔
80

81
        return fake_input
1✔
82

83
    @pytest.mark.online
1✔
84
    @pytest.mark.requires_fiona
1✔
85
    @pytest.mark.skipif(fiona is None, reason="fiona libraries are required for this test")
1✔
86
    def test_gml_validator(self):
1✔
87
        """Test GML validator"""
88
        gml_input = self.get_input('gml/point.gml', 'point.xsd', FORMATS.GML.mime_type)
1✔
89
        self.assertTrue(validategml(gml_input, MODE.NONE), 'NONE validation')
1✔
90
        self.assertTrue(validategml(gml_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
91
        self.assertTrue(validategml(gml_input, MODE.STRICT), 'STRICT validation')
1✔
92
        # self.assertTrue(validategml(gml_input, MODE.VERYSTRICT), 'VERYSTRICT validation')
93
        gml_input.stream.close()
1✔
94

95
    @pytest.mark.online
1✔
96
    @pytest.mark.skipif(fiona is not None, reason="fiona libraries must not be installed for this test")
1✔
97
    def test_no_gml_validator(self):
1✔
98
        """Test GML validator"""
NEW
99
        gml_input = self.get_input('gml/point.gml', 'point.xsd', FORMATS.GML.mime_type)
×
NEW
100
        self.assertTrue(validategml(gml_input, MODE.NONE), 'NONE validation')
×
NEW
101
        self.assertTrue(validategml(gml_input, MODE.SIMPLE), 'SIMPLE validation')
×
NEW
102
        self.assertFalse(validategml(gml_input, MODE.STRICT), 'STRICT validation')
×
103
        # self.assertTrue(validategml(gml_input, MODE.VERYSTRICT), 'VERYSTRICT validation')
NEW
104
        gml_input.stream.close()
×
105

106
    @pytest.mark.online
1✔
107
    @pytest.mark.requires_fiona
1✔
108
    @pytest.mark.xfail(reason="gml verystrict validation fails")
1✔
109
    @pytest.mark.skipif(fiona is None, reason="fiona libraries are required for this test")
1✔
110
    def test_gml_validator_verystrict(self):
1✔
111
        """Test GML validator"""
112
        gml_input = self.get_input('gml/point.gml', 'point.xsd', FORMATS.GML.mime_type)
1✔
113
        self.assertTrue(validategml(gml_input, MODE.VERYSTRICT), 'VERYSTRICT validation')
1✔
114
        gml_input.stream.close()
×
115

116

117
    def test_json_validator(self):
1✔
118
        """Test GeoJSON validator"""
119
        json_input = self.get_input('json/point.geojson', None, FORMATS.JSON.mime_type)
1✔
120
        self.assertTrue(validatejson(json_input, MODE.NONE), 'NONE validation')
1✔
121
        self.assertTrue(validatejson(json_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
122
        self.assertTrue(validatejson(json_input, MODE.STRICT), 'STRICT validation')
1✔
123
        json_input.stream.close()
1✔
124

125
    @pytest.mark.requires_fiona
1✔
126
    @pytest.mark.skipif(fiona is None, reason="fiona libraries are required for this test")
1✔
127
    def test_geojson_validator(self):
1✔
128
        """Test GeoJSON validator"""
129
        geojson_input = self.get_input('json/point.geojson', 'json/schema/geojson.json',
1✔
130
                                  FORMATS.GEOJSON.mime_type)
131
        self.assertTrue(validategeojson(geojson_input, MODE.NONE), 'NONE validation')
1✔
132
        self.assertTrue(validategeojson(geojson_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
133
        self.assertTrue(validategeojson(geojson_input, MODE.STRICT), 'STRICT validation')
1✔
134
        self.assertTrue(validategeojson(geojson_input, MODE.VERYSTRICT), 'VERYSTRICT validation')
1✔
135
        geojson_input.stream.close()
1✔
136

137

138
    @pytest.mark.skipif(fiona is not None, reason="fiona libraries must not be installed for this test")
1✔
139
    def test_no_geojson_validator(self):
1✔
140
        """Test GeoJSON validator"""
NEW
141
        geojson_input = self.get_input('json/point.geojson', 'json/schema/geojson.json',
×
142
                                  FORMATS.GEOJSON.mime_type)
NEW
143
        self.assertTrue(validategeojson(geojson_input, MODE.NONE), 'NONE validation')
×
NEW
144
        self.assertTrue(validategeojson(geojson_input, MODE.SIMPLE), 'SIMPLE validation')
×
145

NEW
146
        self.assertFalse(validategeojson(geojson_input, MODE.STRICT), 'STRICT validation')
×
147

148
        # FIXME: MODE.VERYSTRICT should fail here
NEW
149
        self.assertTrue(validategeojson(geojson_input, MODE.VERYSTRICT), 'VERYSTRICT validation')
×
150

NEW
151
        geojson_input.stream.close()
×
152

153
    @pytest.mark.requires_fiona
1✔
154
    @pytest.mark.skipif(fiona is None, reason="fiona libraries are required for this test")
1✔
155
    def test_shapefile_validator(self):
1✔
156
        """Test ESRI Shapefile validator"""
157
        shapefile_input = self.get_input('shp/point.shp.zip', None,
1✔
158
                FORMATS.SHP.mime_type)
159
        self.assertTrue(validateshapefile(shapefile_input, MODE.NONE), 'NONE validation')
1✔
160
        self.assertTrue(validateshapefile(shapefile_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
161
        self.assertTrue(validateshapefile(shapefile_input, MODE.STRICT), 'STRICT validation')
1✔
162
        shapefile_input.stream.close()
1✔
163

164
    @pytest.mark.skipif(fiona is not None, reason="fiona libraries must not be installed for this test")
1✔
165
    def test_no_shapefile_validator(self):
1✔
166
        """Test ESRI Shapefile validator"""
NEW
167
        shapefile_input = self.get_input('shp/point.shp.zip', None,
×
168
                FORMATS.SHP.mime_type)
NEW
169
        self.assertTrue(validateshapefile(shapefile_input, MODE.NONE), 'NONE validation')
×
NEW
170
        self.assertTrue(validateshapefile(shapefile_input, MODE.SIMPLE), 'SIMPLE validation')
×
NEW
171
        self.assertFalse(validateshapefile(shapefile_input, MODE.STRICT), 'STRICT validation')
×
NEW
172
        shapefile_input.stream.close()
×
173

174
    @pytest.mark.skipif(geotiff is not None, reason="geotiff libraries must not be installed for this test")
1✔
175
    def test_no_geotiff_validator(self):
1✔
176
        """Test GeoTIFF validator"""
NEW
177
        geotiff_input = self.get_input('geotiff/dem.tiff', None,
×
178
                                  FORMATS.GEOTIFF.mime_type)
NEW
179
        self.assertTrue(validategeotiff(geotiff_input, MODE.NONE), 'NONE validation')
×
NEW
180
        self.assertTrue(validategeotiff(geotiff_input, MODE.SIMPLE), 'SIMPLE validation')
×
NEW
181
        self.assertFalse(validategeotiff(geotiff_input, MODE.STRICT), 'STRICT validation')
×
NEW
182
        geotiff_input.stream.close()
×
183

184
    @pytest.mark.requires_geotiff
1✔
185
    @pytest.mark.skipif(geotiff is None, reason="geotiff libraries are required for this test")
1✔
186
    def test_geotiff_validator(self):
1✔
187
        """Test GeoTIFF validator"""
188
        geotiff_input = self.get_input('geotiff/dem.tiff', None,
1✔
189
                                  FORMATS.GEOTIFF.mime_type)
190
        self.assertTrue(validategeotiff(geotiff_input, MODE.NONE), 'NONE validation')
1✔
191
        self.assertTrue(validategeotiff(geotiff_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
192
        self.assertTrue(validategeotiff(geotiff_input, MODE.STRICT), 'STRICT validation')
1✔
193
        geotiff_input.stream.close()
1✔
194

195
    @pytest.mark.requires_netcdf4
1✔
196
    @pytest.mark.skipif(netCDF4 is None, reason="NetCDF4 libraries are required for this test")
1✔
197
    def test_netcdf_validator(self):
1✔
198
        """Test netCDF validator"""
199
        netcdf_input = self.get_input('netcdf/time.nc', None, FORMATS.NETCDF.mime_type)
1✔
200
        self.assertTrue(validatenetcdf(netcdf_input, MODE.NONE), 'NONE validation')
1✔
201
        self.assertTrue(validatenetcdf(netcdf_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
202
        netcdf_input.stream.close()
1✔
203

204
        self.assertTrue(validatenetcdf(netcdf_input, MODE.STRICT), 'STRICT validation')
1✔
205
        netcdf_input.file = 'grub.nc'
1✔
206
        self.assertFalse(validatenetcdf(netcdf_input, MODE.STRICT))
1✔
207

208
    @pytest.mark.skipif(netCDF4 is not None, reason="NetCDF4 libraries must not be installed for this test")
1✔
209
    def test_no_netcdf_validator(self):
1✔
210
        """Test netCDF validator"""
UNCOV
211
        netcdf_input = self.get_input('netcdf/time.nc', None, FORMATS.NETCDF.mime_type)
×
UNCOV
212
        self.assertTrue(validatenetcdf(netcdf_input, MODE.NONE), 'NONE validation')
×
UNCOV
213
        self.assertTrue(validatenetcdf(netcdf_input, MODE.SIMPLE), 'SIMPLE validation')
×
UNCOV
214
        netcdf_input.stream.close()
×
215

NEW
216
        self.assertFalse(validatenetcdf(netcdf_input, MODE.STRICT), 'STRICT validation')
×
217

218
    @pytest.mark.online
1✔
219
    @pytest.mark.requires_netcdf4
1✔
220
    @pytest.mark.skipif(netCDF4 is None, reason="NetCDF4 libraries are required for this test")
1✔
221
    def test_dods_validator(self):
1✔
222
        opendap_input = ComplexInput('dods', 'opendap test', [FORMATS.DODS,])
1✔
223
        opendap_input.url = "http://test.opendap.org:80/opendap/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc"
1✔
224
        self.assertTrue(validatedods(opendap_input, MODE.NONE), 'NONE validation')
1✔
225
        self.assertTrue(validatedods(opendap_input, MODE.SIMPLE), 'SIMPLE validation')
1✔
226

227
        self.assertTrue(validatedods(opendap_input, MODE.STRICT), 'STRICT validation')
1✔
228
        opendap_input.url = 'Faulty url'
1✔
229
        self.assertFalse(validatedods(opendap_input, MODE.STRICT))
1✔
230

231
    @pytest.mark.online
1✔
232
    @pytest.mark.skipif(netCDF4 is not None, reason="NetCDF4 libraries must not be installed for this test")
1✔
233
    def test_dods_default(self):
1✔
UNCOV
234
        opendap_input = ComplexInput('dods', 'opendap test', [FORMATS.DODS,],
×
235
                                     default='http://test.opendap.org',
236
                                     default_type=SOURCE_TYPE.URL,
237
                                     mode=MODE.SIMPLE)
NEW
238
        opendap_input.url = "http://test.opendap.org:80/opendap/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc"
×
NEW
239
        self.assertTrue(validatedods(opendap_input, MODE.NONE), 'NONE validation')
×
NEW
240
        self.assertTrue(validatedods(opendap_input, MODE.SIMPLE), 'SIMPLE validation')
×
241

NEW
242
        with pytest.warns(UserWarning) as record:
×
NEW
243
            self.assertFalse(validatedods(opendap_input, MODE.STRICT), 'STRICT validation')
×
NEW
244
            assert "Complex validation requires netCDF4 support." in record[0].message.args[0]
×
245

246
    def test_fail_validator(self):
1✔
247
        fake_input = self.get_input('point.xsd', 'point.xsd', FORMATS.SHP.mime_type)
1✔
248
        self.assertFalse(validategml(fake_input, MODE.SIMPLE), 'SIMPLE validation invalid')
1✔
249
        fake_input.stream.close()
1✔
250

251

252
def load_tests(loader=None, tests=None, pattern=None):
1✔
253
    import unittest
×
254

255
    if not loader:
×
256
        loader = unittest.TestLoader()
×
257
    suite_list = [
×
258
        loader.loadTestsFromTestCase(ValidateTest)
259
    ]
260
    return unittest.TestSuite(suite_list)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc