Skip to content

Commit

Permalink
fix: test against all our python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Jun 30, 2023
1 parent bf3379a commit 8222fd4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ jobs:
matrix:
# We can't just install without the cli extra, because black depends on click
with-click: [true, false]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install with development dependencies
run: pip install .[cli,dev]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ dev = [
"pytest~=7.3",
"pytest-console-scripts~=1.3",
"ruff==0.0.275",
"tomli~=2.0; python_version<'3.11'"
"tomli~=2.0; python_version<'3.11'",
"typing_extensions; python_version<'3.10'",
]
docs = [
"cartopy~=0.21",
Expand Down
88 changes: 48 additions & 40 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import sys
from pathlib import Path
from typing import Callable
from typing import Callable, Union

import pytest
import shapely.geometry
Expand All @@ -15,37 +16,44 @@
Polygon,
)

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

TEST_DATA_DIRECTORY = Path(__file__).parent / "data"
INPUT_DATA_DIRECTORY = TEST_DATA_DIRECTORY / "input"
OUTPUT_DATA_DIRECTORY = TEST_DATA_DIRECTORY / "output"

Reader = Callable[
Reader: TypeAlias = Callable[
[str],
Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| LinearRing
| GeometryCollection,
Union[
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon,
LinearRing,
GeometryCollection,
],
]


@pytest.fixture
def read_input() -> Reader:
def read_input(
name: str,
) -> (
Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| LinearRing
| GeometryCollection
):
) -> Union[
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon,
LinearRing,
GeometryCollection,
]:
return read_file((INPUT_DATA_DIRECTORY / name).with_suffix(".json"))

return read_input
Expand All @@ -63,33 +71,33 @@ def input_path(name: str) -> Path:
def read_output() -> Reader:
def read_output(
name: str,
) -> (
Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| LinearRing
| GeometryCollection
):
) -> Union[
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon,
LinearRing,
GeometryCollection,
]:
return read_file((OUTPUT_DATA_DIRECTORY / name).with_suffix(".json"))

return read_output


def read_file(
path: Path,
) -> (
Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| LinearRing
| GeometryCollection
):
) -> Union[
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon,
LinearRing,
GeometryCollection,
]:
with open(path) as f:
data = json.load(f)
shape = shapely.geometry.shape(data)
Expand Down

0 comments on commit 8222fd4

Please sign in to comment.