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
|
import pytest
from pyproj.crs import (
CRS,
CoordinateOperation,
CoordinateSystem,
Datum,
Ellipsoid,
PrimeMeridian,
)
def test_crs_to_json_dict():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_dict = aeqd_crs.to_json_dict()
assert json_dict["type"] == "ProjectedCRS"
def test_crs_to_json():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = aeqd_crs.to_json()
assert "ProjectedCRS" in json_data
assert "\n" not in json_data
def test_crs_to_json__pretty():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = aeqd_crs.to_json(pretty=True)
assert "ProjectedCRS" in json_data
assert json_data.startswith('{\n "')
def test_crs_to_json__pretty__indenation():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = aeqd_crs.to_json(pretty=True, indentation=4)
assert "ProjectedCRS" in json_data
assert json_data.startswith('{\n "')
def test_crs_from_json():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
assert CRS.from_json(aeqd_crs.to_json()) == aeqd_crs
def test_crs_from_json_dict():
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
assert CRS.from_json_dict(aeqd_crs.to_json_dict()) == aeqd_crs
@pytest.mark.parametrize(
"property_name, expected_type",
[
("coordinate_operation", "Conversion"),
("datum", "GeodeticReferenceFrame"),
("ellipsoid", "Ellipsoid"),
("prime_meridian", "PrimeMeridian"),
("coordinate_system", "CoordinateSystem"),
],
)
def test_properties_to_json(property_name, expected_type):
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = getattr(aeqd_crs, property_name).to_json()
assert expected_type in json_data
assert "\n" not in json_data
@pytest.mark.parametrize(
"property_name, expected_type",
[
("coordinate_operation", "Conversion"),
("datum", "GeodeticReferenceFrame"),
("ellipsoid", "Ellipsoid"),
("prime_meridian", "PrimeMeridian"),
("coordinate_system", "CoordinateSystem"),
],
)
def test_properties_to_json__pretty(property_name, expected_type):
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = getattr(aeqd_crs, property_name).to_json(pretty=True)
assert expected_type in json_data
assert json_data.startswith('{\n "')
@pytest.mark.parametrize(
"property_name, expected_type",
[
("coordinate_operation", "Conversion"),
("datum", "GeodeticReferenceFrame"),
("ellipsoid", "Ellipsoid"),
("prime_meridian", "PrimeMeridian"),
("coordinate_system", "CoordinateSystem"),
],
)
def test_properties_to_json__pretty__indentation(property_name, expected_type):
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
json_data = getattr(aeqd_crs, property_name).to_json(pretty=True, indentation=4)
assert expected_type in json_data
assert json_data.startswith('{\n "')
@pytest.mark.parametrize(
"property_name, expected_type",
[
("coordinate_operation", "Conversion"),
("datum", "GeodeticReferenceFrame"),
("ellipsoid", "Ellipsoid"),
("prime_meridian", "PrimeMeridian"),
],
)
def test_properties_to_json_dict(property_name, expected_type):
aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
assert getattr(aeqd_crs, property_name).to_json_dict()["type"] == expected_type
@pytest.mark.parametrize(
"property_name, init_class",
[
("coordinate_operation", CoordinateOperation),
("datum", Datum),
("ellipsoid", Ellipsoid),
("prime_meridian", PrimeMeridian),
],
)
def test_properties_from_json_dict(property_name, init_class):
prop = getattr(CRS.from_epsg(26915), property_name)
assert init_class.from_json_dict(prop.to_json_dict()) == prop
def test_coordinate_system_from_json_dict():
# separate test from other properties due to
# https://github.com/OSGeo/PROJ/issues/1818
aeqd_cs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5).coordinate_system
assert CoordinateSystem.from_json_dict(aeqd_cs.to_json_dict()) == aeqd_cs
def test_coordinate_system_from_json():
# separate test from other properties due to
# https://github.com/OSGeo/PROJ/issues/1818
aeqd_cs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5).coordinate_system
assert CoordinateSystem.from_json(aeqd_cs.to_json()) == aeqd_cs
|