-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_geos_err_handler.py
33 lines (24 loc) · 1.04 KB
/
test_geos_err_handler.py
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
import logging
import pytest
from shapely.geometry import LineString
from shapely.geos import ReadingError
from shapely.wkt import loads
def test_error_handler(tmpdir):
logger = logging.getLogger('shapely.geos')
logger.setLevel(logging.DEBUG)
logfile = str(tmpdir.join('test_error.log'))
fh = logging.FileHandler(logfile)
logger.addHandler(fh)
# This operation calls error_handler with a format string that
# has *no* conversion specifiers.
LineString([(0, 0), (2, 2)]).project(LineString([(1, 1), (1.5, 1.5)]))
# This calls error_handler with a format string of "%s" and one
# value.
with pytest.raises(ReadingError):
loads('POINT (LOLWUT)')
g = loads('MULTIPOLYGON (((10 20, 10 120, 60 70, 30 70, 30 40, 60 40, 60 70, 90 20, 10 20)))')
assert g.is_valid == False
log = open(logfile).read()
assert "third argument of GEOSProject_r must be Point*" in log
assert "Expected number but encountered word: 'LOLWUT'" in log
assert "Ring Self-intersection at or near point 60 70" in log