Skip to content

Commit

Permalink
KDP-1528 enable publish ci, add initial test file
Browse files Browse the repository at this point in the history
  • Loading branch information
rosinaderks committed Oct 6, 2023
1 parent 141ece6 commit 99a9425
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 138 deletions.
63 changes: 32 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- KDP-1528
tags:
- '*'
pull_request:
Expand Down Expand Up @@ -36,7 +37,7 @@ jobs:
pre-commit run --all-files
# - name: Run tests
# run: python -m pytest --cov edr-pydantic-classes --cov-report xml --cov-report term-missing
# run: python -m pytest --cov edr-pydantic --cov-report xml --cov-report term-missing
#
# - name: Upload Results
# if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
Expand All @@ -47,34 +48,34 @@ jobs:
# name: ${{ matrix.python-version }}
# fail_ci_if_error: false
#
# publish:
# needs: [tests]
# runs-on: ubuntu-latest
# if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.LATEST_PY_VERSION }}
#
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# python -m pip install flit
# python -m pip install .
#
# - name: Set tag version
# id: tag
# run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
#
# - name: Set module version
# id: module
# run: echo "version=$(python -c 'from importlib.metadata import version; print(version("edr-pydantic-classes"))')" >> $GITHUB_OUTPUT
publish:
needs: [tests]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PY_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flit
python -m pip install .
- name: Set tag version
id: tag
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Set module version
id: module
run: echo "version=$(python -c 'from importlib.metadata import version; print(version("edr-pydantic"))')" >> $GITHUB_OUTPUT

# - name: Build and publish
# if: steps.tag.outputs.tag == steps.module.outputs.version
# env:
# FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
# FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
# run: flit publish
- name: Build and publish
if: steps.tag.outputs.tag == steps.module.outputs.version
env:
FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: flit publish
67 changes: 33 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "edr-pydantic-classes"
name = "edr-pydantic"
description = "The Pydantic models for CoverageJSON"
readme = "README.md"
requires-python = ">=3.8"
Expand All @@ -8,45 +8,44 @@ authors = [
{name = "KNMI Data Platform Team", email = "[email protected]"},
]
keywords = ["EDR", "Pydantic"]
#classifiers = [
# "Intended Audience :: Information Technology",
# "Intended Audience :: Science/Research",
classifiers = [
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
# "License :: OSI Approved :: Apache Software License",
# "Programming Language :: Python :: 3.8",
# "Programming Language :: Python :: 3.9",
# "Programming Language :: Python :: 3.10",
# "Programming Language :: Python :: 3.11",
# "Topic :: Scientific/Engineering :: GIS",
# "Typing :: Typed",
#]
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: GIS",
"Typing :: Typed",
]
version = "0.1.0"
dependencies = ["pydantic>=2.3,<3", "covjson-pydantic~=0.2.0", "python-dateutil"]
dependencies = ["pydantic>=2.3,<3", "covjson-pydantic~=0.2.0"]

[project.optional-dependencies]
test = ["pytest", "pytest-cov"]
dev = ["pre-commit"]

[project.urls]
#Source = "https://github.com/knmi/covjson-pydantic"
Source = "https://github.com/rosinaderks/pypi-edr-github-test"
Source = "https://github.com/knmi/edr-pydantic"

[build-system]
requires = ["flit>=3.2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.module]
name = "edr-pydantic"

[tool.flit.sdist]
exclude = [
"test/",
".github/",
]

[tool.mypy]
plugins = [
"pydantic.mypy"
]

#[build-system]
#requires = ["flit>=3.2,<4"]
#build-backend = "flit_core.buildapi"
#
#[tool.flit.module]
#name = "edr-pydantic-classes"
#
#[tool.flit.sdist]
#exclude = [
# "test/",
# ".github/",
#]
#
#[tool.mypy]
#plugins = [
# "pydantic.mypy"
#]
#
#[tool.pydantic-mypy]
#warn_untyped_fields = true
[tool.pydantic-mypy]
warn_untyped_fields = true
73 changes: 0 additions & 73 deletions tests/test_edr.py
Original file line number Diff line number Diff line change
@@ -1,73 +0,0 @@
import json
from pathlib import Path

import pytest
from covjson_pydantic.coverage import Coverage
from covjson_pydantic.coverage import CoverageCollection
from covjson_pydantic.domain import Axes
from covjson_pydantic.domain import Domain
from covjson_pydantic.ndarray import NdArray
from covjson_pydantic.ndarray import TiledNdArray
from covjson_pydantic.parameter import Parameter
from covjson_pydantic.parameter import ParameterGroup
from covjson_pydantic.reference_system import ReferenceSystem
from pydantic import ValidationError


happy_cases = [
("spec-axes.json", Axes),
("coverage-json.json", Coverage),
("doc-example-coverage.json", Coverage),
("spec-vertical-profile-coverage.json", Coverage),
("doc-example-coverage-collection.json", CoverageCollection),
("grid-domain.json", Domain),
("point-series-domain-custom.json", Domain),
("spec-domain-grid.json", Domain),
("spec-domain-vertical-profile.json", Domain),
("spec-domain-point-series.json", Domain),
("spec-domain-point.json", Domain),
("spec-domain-multipoint-series.json", Domain),
("spec-domain-multipoint.json", Domain),
("ndarray-float.json", NdArray),
("spec-ndarray.json", NdArray),
("spec-tiled-ndarray.json", TiledNdArray),
("continuous-data-parameter.json", Parameter),
("categorical-data-parameter.json", Parameter),
("spec-parametergroup.json", ParameterGroup),
("spec-reference-system-identifierrs.json", ReferenceSystem),
]


@pytest.mark.parametrize("file_name, object_type", happy_cases)
def test_happy_cases(file_name, object_type):
file = Path(__file__).parent.resolve() / "test_data" / file_name
# Put JSON in default unindented format
with open(file, "r") as f:
data = json.load(f)
json_string = json.dumps(data, separators=(",", ":"))

# Round-trip
assert object_type.model_validate_json(json_string).model_dump_json(exclude_none=True) == json_string


error_cases = [
("grid-domain-no-y.json", Domain, r"A 'Grid' must have a 'y'-axis"),
(
"point-series-domain-more-z.json",
Domain,
r"If provided, the 'values' field of the 'z'-axis of a 'PointSeries' domain must contain a single value.",
),
("point-series-domain-no-t.json", Domain, r"A 'PointSeries' must have a 't'-axis."),
]


@pytest.mark.parametrize("file_name, object_type, error_message", error_cases)
def test_error_cases(file_name, object_type, error_message):
file = Path(__file__).parent.resolve() / "test_data" / file_name
# Put JSON in default unindented format
with open(file, "r") as f:
data = json.load(f)
json_string = json.dumps(data, separators=(",", ":"))

with pytest.raises(ValidationError, match=error_message):
object_type.model_validate_json(json_string)

0 comments on commit 99a9425

Please sign in to comment.