def pytest_report_header(config): headers = [] # gdal version number gdal_release_name = fiona.get_gdal_release_name() headers.append('GDAL: {} ({})'.format(gdal_release_name, fiona.get_gdal_version_num())) supported_drivers = ", ".join(sorted(list(fiona.drvsupport.supported_drivers.keys()))) # supported drivers headers.append("Supported drivers: {}".format(supported_drivers)) return '\n'.join(headers)
import fiona import six GDAL_MAJOR_VER = fiona.get_gdal_version_num() // 1000000 def test_read_bool_subtype(tmpdir): test_data = """{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"bool": true, "not_bool": 1, "float": 42.5}, "geometry": null}]}""" path = tmpdir.join("test_read_bool_subtype.geojson") with open(str(path), "w") as f: f.write(test_data) with fiona.open(str(path), "r") as src: feature = next(iter(src)) if GDAL_MAJOR_VER >= 2: assert type(feature["properties"]["bool"]) is bool else: assert type(feature["properties"]["bool"]) is int assert isinstance(feature["properties"]["not_bool"], six.integer_types) assert type(feature["properties"]["float"]) is float def test_write_bool_subtype(tmpdir): path = tmpdir.join("test_write_bool_subtype.geojson") schema = { "geometry": "Point", "properties": { "bool": "bool", "not_bool": "int",
"""Tests for Fiona's OGR driver interface.""" import logging import sys import pytest import os import fiona logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) GDAL_MAJOR_VER = fiona.get_gdal_version_num() // 1000000 def test_options(tmpdir): """Test that setting CPL_DEBUG=ON works""" logfile = str(tmpdir.mkdir('tests').join('test_options.log')) logger = logging.getLogger() logger.setLevel(logging.DEBUG) fh = logging.FileHandler(logfile) fh.setLevel(logging.DEBUG) logger.addHandler(fh) with fiona.drivers(CPL_DEBUG=True): path = os.path.join("tests", "data", "coutwildrnp.shp") c = fiona.open(path) c.close() with open(logfile, "r") as f: log = f.read() if GDAL_MAJOR_VER >= 2:
'coordinates': (((-112, 38), (-112, 40), (-106, 40), (-106, 38), (-112, 38)), ) } results = list(self.c.filter(mask=mask)) self.assertEqual(len(results), 26) def test_zipped_bytes_collection(bytes_coutwildrnp_zip): """Open a zipped stream of bytes as a collection""" with fiona.BytesCollection(bytes_coutwildrnp_zip) as col: assert col.name == 'coutwildrnp' assert len(col) == 67 @pytest.mark.skipif( fiona.get_gdal_version_num() >= fiona.calc_gdal_version_num(2, 3, 0), reason="Changed behavior with gdal 2.3, possibly related to RFC 70:" "Guessing output format from output file name extension for utilities") def test_grenada_bytes_geojson(bytes_grenada_geojson): """Read grenada.geojson as BytesCollection. grenada.geojson is an example of geojson that GDAL's GeoJSON driver will fail to read successfully unless the file's extension reflects its json'ness. """ # We expect an exception if the GeoJSON driver isn't specified. with pytest.raises(fiona.errors.FionaValueError): with fiona.BytesCollection(bytes_grenada_geojson) as col: pass # If told what driver to use, we should be good.
def test_filter_mask(self): mask = { 'type': 'Polygon', 'coordinates': ( ((-112, 38), (-112, 40), (-106, 40), (-106, 38), (-112, 38)),)} results = list(self.c.filter(mask=mask)) self.assertEqual(len(results), 26) def test_zipped_bytes_collection(bytes_coutwildrnp_zip): """Open a zipped stream of bytes as a collection""" with fiona.BytesCollection(bytes_coutwildrnp_zip) as col: assert col.name == 'coutwildrnp' assert len(col) == 67 @pytest.mark.skipif(fiona.get_gdal_version_num() >= fiona.calc_gdal_version_num(2, 3, 0), reason="Changed behavior with gdal 2.3, possibly related to RFC 70:" "Guessing output format from output file name extension for utilities") def test_grenada_bytes_geojson(bytes_grenada_geojson): """Read grenada.geojson as BytesCollection. grenada.geojson is an example of geojson that GDAL's GeoJSON driver will fail to read successfully unless the file's extension reflects its json'ness. """ # We expect an exception if the GeoJSON driver isn't specified. with pytest.raises(fiona.errors.FionaValueError): with fiona.BytesCollection(bytes_grenada_geojson) as col: pass # If told what driver to use, we should be good.