Coverage for gws-app/gws/gis/crs/_test.py: 0%
43 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""Tests for the crs module."""
3import gws
4import gws.test.util as u
5import gws.gis.crs as crs
8def test_get_no_name():
9 assert not crs.get('')
12def test_get():
13 assert str(crs.get('EPSG:3857')) == '<crs:3857>'
16def test_parse():
17 assert crs.parse('EPSG:3857') == ('epsg', crs.get('3857'))
20def test_parse_srid():
21 assert crs.parse('3857') == ('srid', crs.get('3857'))
24def test_parse_no_format():
25 assert crs.parse('11wrongFormat') == ('', None)
28def test_require():
29 assert crs.require('3857') == crs.get('3857')
32def test_require_exception():
33 with u.raises(Exception):
34 crs.require('FOOBAR')
37def test_best_match():
38 lst = [crs.WEBMERCATOR, crs.WGS84]
39 assert crs.best_match(crs.WGS84, lst) == crs.get('4326')
42def test_best_match_not__list():
43 lst = [crs.WEBMERCATOR]
44 assert crs.best_match(crs.WGS84, lst) == crs.get('3857')
47def test_best_bounds():
48 b1 = gws.Bounds(crs=crs.WEBMERCATOR, extent=(0.0, 1.0, 1.0, 0.0))
49 b2 = gws.Bounds(crs=crs.WGS84, extent=(0.0, 1.0, 1.0, 0.0))
50 lst = [b1, b2]
51 assert crs.best_bounds(crs.WGS84, lst) == b2
54def test_best_axis():
55 assert crs.best_axis(crs.WGS84) == 'xy'
58def test_best_axis_inverted():
59 assert crs.best_axis(crs.WGS84, inverted_crs=[crs.WGS84]) == 'yx'
62def test_axis_for_format():
63 assert crs.WGS84.axis_for_format('EPSG') == 'yx'
66def test_transform_extent():
67 assert crs.WGS84.transform_extent(ext=(0.0, 1.0, 1.0, 0.0),
68 crs_to=crs.WEBMERCATOR) == (0.0, 0.0, 111319.49079327357, 111325.1428663851)
71def test_transformer():
72 assert str(crs.WGS84.transformer(crs.WEBMERCATOR)) == (
73 '<bound method Transformer.transform of <Concatenated Operation Transformer: '
74 'pipeline>\n'
75 'Description: axis order change (2D) + Popular Visualisation Pseudo-Mercator\n'
76 'Area of Use:\n'
77 '- name: World\n'
78 '- bounds: (-180.0, -90.0, 180.0, 90.0)>')
81def test_to_string():
82 assert crs.WEBMERCATOR.to_string() == 'EPSG:3857'
85def test_to_geojson():
86 assert crs.WEBMERCATOR.to_geojson() == {'properties': {'name': 'urn:ogc:def:crs:EPSG::3857'}, 'type': 'name'}