File: test_testing.py

package info (click to toggle)
python-shapely 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,564 kB
  • sloc: python: 18,650; ansic: 6,615; makefile: 88; sh: 62
file content (97 lines) | stat: -rw-r--r-- 2,846 bytes parent folder | download | duplicates (3)
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
import numpy as np
import pytest

import shapely
from shapely.testing import assert_geometries_equal
from shapely.tests.common import (
    all_types,
    empty,
    empty_line_string,
    empty_line_string_z,
    empty_point,
    empty_point_z,
    empty_polygon,
    line_string,
    line_string_nan,
    line_string_z,
    point,
)

EMPTY_GEOMS = (
    empty_point,
    empty_point_z,
    empty_line_string,
    empty_line_string_z,
    empty_polygon,
    empty,
)

line_string_reversed = shapely.linestrings([(0, 0), (1, 0), (1, 1)][::-1])


def make_array(left, right, use_array):
    if use_array in ("left", "both"):
        left = np.array([left] * 3, dtype=object)
    if use_array in ("right", "both"):
        right = np.array([right] * 3, dtype=object)
    return left, right


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
@pytest.mark.parametrize("geom", all_types + EMPTY_GEOMS)
def test_assert_geometries_equal(geom, use_array):
    assert_geometries_equal(*make_array(geom, geom, use_array))


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
@pytest.mark.parametrize(
    "geom1,geom2",
    [
        (point, line_string),
        (line_string, line_string_z),
        (empty_point, empty_polygon),
        (empty_point, empty_point_z),
        (empty_line_string, empty_line_string_z),
    ],
)
def test_assert_geometries_not_equal(geom1, geom2, use_array):
    with pytest.raises(AssertionError):
        assert_geometries_equal(*make_array(geom1, geom2, use_array))


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
def test_assert_none_equal(use_array):
    assert_geometries_equal(*make_array(None, None, use_array))


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
def test_assert_none_not_equal(use_array):
    with pytest.raises(AssertionError):
        assert_geometries_equal(*make_array(None, None, use_array), equal_none=False)


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
def test_assert_nan_equal(use_array):
    assert_geometries_equal(*make_array(line_string_nan, line_string_nan, use_array))


@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"])
def test_assert_nan_not_equal(use_array):
    with pytest.raises(AssertionError):
        assert_geometries_equal(
            *make_array(line_string_nan, line_string_nan, use_array), equal_nan=False
        )


def test_normalize_true():
    assert_geometries_equal(line_string_reversed, line_string, normalize=True)


def test_normalize_default():
    with pytest.raises(AssertionError):
        assert_geometries_equal(line_string_reversed, line_string)


def test_normalize_false():
    with pytest.raises(AssertionError):
        assert_geometries_equal(line_string_reversed, line_string, normalize=False)