| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
"""Test the coordinates class.""" |
| 18 |
|
| 19 |
from fastkml.geometry import Coordinates |
| 20 |
from tests.base import Lxml |
| 21 |
from tests.base import StdLibrary |
| 22 |
|
| 23 |
|
| 24 |
class TestCoordinates(StdLibrary): |
| 25 |
def test_coordinates(self) -> None: |
| 26 |
"""Test the init method.""" |
| 27 |
coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)) |
| 28 |
|
| 29 |
coordinates = Coordinates(coords=coords) |
| 30 |
|
| 31 |
assert coordinates.to_string(precision=6).strip() == ( |
| 32 |
'<kml:coordinates xmlns:kml="http://www.opengis.net/kml/2.2">' |
| 33 |
"0.000000,0.000000 0.000000,1.000000 1.000000,1.000000 " |
| 34 |
"1.000000,0.000000 0.000000,0.000000" |
| 35 |
"</kml:coordinates>" |
| 36 |
) |
| 37 |
|
| 38 |
def test_coordinates_from_string(self) -> None: |
| 39 |
"""Test the from_string method.""" |
| 40 |
coordinates = Coordinates.from_string( |
| 41 |
'<kml:coordinates xmlns:kml="http://www.opengis.net/kml/2.2">' |
| 42 |
"0.000000,0.000000 1.000000,0.000000 1.0,1.0 0.000000,0.000000" |
| 43 |
"</kml:coordinates>", |
| 44 |
) |
| 45 |
|
| 46 |
assert coordinates.coords == [(0, 0), (1, 0), (1, 1), (0, 0)] |
| 47 |
|
| 48 |
def test_coordinates_from_string_with_whitespace(self) -> None: |
| 49 |
"""Test the from_string method with whitespace.""" |
| 50 |
coordinates = Coordinates.from_string( |
| 51 |
'<kml:coordinates xmlns:kml="http://www.opengis.net/kml/2.2">\n' |
| 52 |
"-123.9404499372,49.169275246690,17 -123.940493701601,49.1694596207446,17 " |
| 53 |
"-123.940356261489,49.16947180231761,17 -123.940306243,49.169291706171,17 " |
| 54 |
"-123.940449937288,49.16927524669021,17 \n" |
| 55 |
"</kml:coordinates>", |
| 56 |
) |
| 57 |
|
| 58 |
assert coordinates.coords == [ |
| 59 |
(-123.9404499372, 49.16927524669, 17.0), |
| 60 |
(-123.940493701601, 49.1694596207446, 17.0), |
| 61 |
(-123.940356261489, 49.16947180231761, 17.0), |
| 62 |
(-123.940306243, 49.169291706171, 17.0), |
| 63 |
(-123.940449937288, 49.16927524669021, 17.0), |
| 64 |
] |
| 65 |
|
| 66 |
def test_coordinates_from_string_parse_error_relaxed(self) -> None: |
| 67 |
"""Test the from_string method with a parse error.""" |
| 68 |
coordinates = Coordinates.from_string( |
| 69 |
'<kml:coordinates xmlns:kml="http://www.opengis.net/kml/2.2">' |
| 70 |
"0.a,b.000000 1.0,1.0" |
| 71 |
"</kml:coordinates>", |
| 72 |
strict=False, |
| 73 |
) |
| 74 |
|
| 75 |
assert not coordinates.coords |
| 76 |
|
| 77 |
|
| 78 |
class TestCoordinatesLxml(Lxml, TestCoordinates): |
| 79 |
pass |