joonaspessi commented on code in PR #231:
URL: https://github.com/apache/sedona-db/pull/231#discussion_r2446771835
##########
python/sedonadb/tests/functions/test_functions.py:
##########
@@ -661,6 +661,66 @@ def test_st_isclosed(eng, geom, expected):
eng.assert_query_result(f"SELECT ST_IsClosed({geom_or_null(geom)})",
expected)
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+ ("geom", "expected"),
+ [
+ (None, None),
+ # Valid rings (closed + simple)
+ ("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)", True),
+ ("LINESTRING(0 0, 1 0, 1 1, 0 0)", True),
+ ("LINESTRING(0 0, 2 2, 1 2, 0 0)", True),
+ # Closed but self-intersecting - bowtie shape (not simple)
+ ("LINESTRING(0 0, 0 1, 1 0, 1 1, 0 0)", False),
+ # Not closed
+ ("LINESTRING(0 0, 1 1)", False),
+ ("LINESTRING(2 0, 2 2, 3 3)", False),
+ ("LINESTRING(0 0, 2 2)", False),
+ # Empty geometries
+ ("LINESTRING EMPTY", False),
+ ("POINT EMPTY", False),
+ ("POLYGON EMPTY", False),
+ ("MULTIPOLYGON EMPTY", False),
+ ("GEOMETRYCOLLECTION EMPTY", False),
+ ],
+)
+def test_st_isring(eng, geom, expected):
+ """Test ST_IsRing with LineString geometries.
+
+ ST_IsRing returns true if the geometry is a closed and simple LineString.
+ """
+ eng = eng.create_or_skip()
+ eng.assert_query_result(f"SELECT ST_IsRing({geom_or_null(geom)})",
expected)
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+ ("geom"),
+ [
+ "POINT(0 0)",
+ "MULTIPOINT((0 0), (1 1))",
+ "POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))",
+ "MULTILINESTRING((0 0, 0 1, 1 1, 1 0, 0 0))",
+ "GEOMETRYCOLLECTION(LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0))",
+ ],
+)
+def test_st_isring_non_linestring_error(eng, geom):
+ """Test that ST_IsRing throws errors for non-LineString non-empty
geometries.
+
+ Both SedonaDB and PostGIS throw errors when ST_IsRing is called on
+ non-LineString geometry types (PostGIS compatibility).
+ """
+ eng = eng.create_or_skip()
+ with pytest.raises(Exception) as exc_info:
+ eng.assert_query_result(f"SELECT
ST_IsRing(ST_GeomFromText('{geom}'))", None)
+
+ # Verify error message contains the expected text
+ error_msg = str(exc_info.value).lower()
+ assert (
+ "linear" in error_msg or "linestring" in error_msg
+ ), f"Expected error about linear feature, got: {exc_info.value}"
Review Comment:
Good idea! Updated to cleanly utilize pytest match pattern. Pre-commit
passes locally
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]