mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 19:03:08 +02:00
- Add comprehensive tests for all packages (3572 tests, 100% branch coverage) - Split oversized test files to stay under 500-line limit - Add per-file ruff ignores for test-appropriate suppressions - Fix _cache_decks.py to properly convert JSON lists to tuples - Add session-scoped conftest fixture for logging handler cleanup (Python 3.14) - Update ruff pre-commit hook to v0.15.2 - Add codespell ignore words for test data - Add generated output files to .gitignore
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""Tests for _add_area_column and _add_length_column (non-empty GDFs)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import geopandas as gpd
|
|
from shapely.geometry import LineString, Polygon
|
|
|
|
from python_pkg.geo_data._common import _add_area_column, _add_length_column
|
|
|
|
|
|
class TestAddAreaColumnNonEmpty:
|
|
"""Tests for _add_area_column with non-empty GeoDataFrame."""
|
|
|
|
def test_adds_area_column(self) -> None:
|
|
gdf = gpd.GeoDataFrame(
|
|
{"name": ["A"]},
|
|
geometry=[Polygon([(20, 50), (21, 50), (21, 51), (20, 51)])],
|
|
crs="EPSG:4326",
|
|
)
|
|
result = _add_area_column(gdf)
|
|
assert "area_km2" in result.columns
|
|
assert result["area_km2"].iloc[0] > 0
|
|
|
|
|
|
class TestAddLengthColumnNonEmpty:
|
|
"""Tests for _add_length_column with non-empty GeoDataFrame."""
|
|
|
|
def test_adds_length_column(self) -> None:
|
|
gdf = gpd.GeoDataFrame(
|
|
{"name": ["A"]},
|
|
geometry=[LineString([(20, 50), (21, 51)])],
|
|
crs="EPSG:4326",
|
|
)
|
|
result = _add_length_column(gdf)
|
|
assert "length_km" in result.columns
|
|
assert result["length_km"].iloc[0] > 0
|
|
|
|
|
|
class TestAddAreaColumnEmpty:
|
|
"""Tests for _add_area_column with empty GeoDataFrame."""
|
|
|
|
def test_returns_empty_gdf(self) -> None:
|
|
gdf = gpd.GeoDataFrame({"name": [], "geometry": []})
|
|
result = _add_area_column(gdf)
|
|
assert len(result) == 0
|
|
|
|
|
|
class TestAddLengthColumnEmpty:
|
|
"""Tests for _add_length_column with empty GeoDataFrame."""
|
|
|
|
def test_returns_empty_gdf(self) -> None:
|
|
gdf = gpd.GeoDataFrame({"name": [], "geometry": []})
|
|
result = _add_length_column(gdf)
|
|
assert len(result) == 0
|