Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions counterexamples/divisions/division_boundary/bad-not-both.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions examples/divisions/division_area/both_land_territorial.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
id: example:division_area:both_land_territorial:country:us
type: Feature
geometry:
type: Polygon
coordinates: [
[
[-82.8732511, 24.4116731],
[-82.5948517, 24.5902399],
[-82.7300073, 24.8395704],
[-83.153058, 24.6776636],
[-82.8732511, 24.4116731]
]
]
properties:
theme: divisions
type: division_area
subtype: country
is_land: true
is_territorial: true
country: US
admin_level: 0
version: 0
class: land
division_id: example:division:country:us
names:
primary: United States
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: example:division_boundary:is_land:country:us
id: example:division_boundary:both_land_territorial:country:us
type: Feature
geometry:
type: LineString
Expand All @@ -9,9 +9,8 @@ properties:
type: division_boundary
version: 1
subtype: country
admin_level: 0
is_land: true
is_territorial: true
class: land
division_ids: ["example:division:country:left", "example:division:country:right"]
ext_expected_errors:
- "oneOf failed, subschemas 0, 1 matched"
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Not,
RadioGroupConstraint,
RequireAnyOfConstraint,
RequireAnyTrueConstraint,
RequireIfConstraint,
)

Expand Down Expand Up @@ -141,7 +142,10 @@ def _affected_field_names(constraint: ModelConstraint) -> frozenset[str]:
return frozenset(constraint.field_names) | _condition_field_names(
constraint.condition
)
if isinstance(constraint, (RequireAnyOfConstraint, RadioGroupConstraint)):
if isinstance(
constraint,
(RequireAnyOfConstraint, RadioGroupConstraint, RequireAnyTrueConstraint),
):
return frozenset(constraint.field_names)
return frozenset()

Expand All @@ -152,6 +156,10 @@ def _describe_one(constraint: ModelConstraint) -> str | None:
return None
if isinstance(constraint, RequireAnyOfConstraint):
return f"At least one of {_backtick_join(constraint.field_names)} must be set"
if isinstance(constraint, RequireAnyTrueConstraint):
return (
f"At least one of {_backtick_join(constraint.field_names)} must be `true`"
)
if isinstance(constraint, RadioGroupConstraint):
return f"Exactly one of {_backtick_join(constraint.field_names)} must be `true`"
if isinstance(constraint, MinFieldsSetConstraint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,28 +234,27 @@ def test_segment_common_base_is_base_model(self, segment_spec: UnionSpec) -> Non
assert "id" in segment_spec.common_base.model_fields


class TestPydanticTypePages:
"""End-to-end: pipeline produces pages for referenced Pydantic built-in types."""
@pytest.fixture(scope="module")
def pages() -> list:
"""Generate all pages from real discovered models."""
models = discover_models()
feature_specs: list[FeatureSpec] = []
for key, entry in models.items():
if is_model_class(entry):
feature_specs.append(extract_model(entry, entry_point=key.entry_point))
elif is_union_alias(entry):
feature_specs.append(
extract_union(
entry_point_class(key.entry_point),
entry,
entry_point=key.entry_point,
)
)
return generate_markdown_pages(feature_specs, "overture.schema")

_SCHEMA_ROOT = "overture.schema"

@pytest.fixture(scope="class")
def pages(self) -> list:
"""Generate all pages from real discovered models."""
models = discover_models()
feature_specs: list[FeatureSpec] = []
for key, entry in models.items():
if is_model_class(entry):
feature_specs.append(extract_model(entry, entry_point=key.entry_point))
elif is_union_alias(entry):
feature_specs.append(
extract_union(
entry_point_class(key.entry_point),
entry,
entry_point=key.entry_point,
)
)
return generate_markdown_pages(feature_specs, self._SCHEMA_ROOT)
class TestPydanticTypePages:
"""End-to-end: pipeline produces pages for referenced Pydantic built-in types."""

def test_http_url_page_exists(self, pages: list) -> None:
"""Pipeline produces a page for HttpUrl under pydantic/networks/."""
Expand Down
6 changes: 4 additions & 2 deletions packages/overture-schema-common/tests/scoping/test_scoped.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class Qux(BaseModel):
pass

@pytest.mark.parametrize(
"scope,required", itertools.product(Scope._top_level_scopes(), (False, True))
"scope,required",
list(itertools.product(Scope._top_level_scopes(), (False, True))),
)
def test_single_scope_top_level(self, scope: Scope, required: bool) -> None:
if required:
Expand All @@ -162,7 +163,8 @@ class SingleScoped(BaseModel):
assert field_info.is_required() == required

@pytest.mark.parametrize(
"scope,required", itertools.product(Scope._when_scopes(), (False, True))
"scope,required",
list(itertools.product(Scope._when_scopes(), (False, True))),
)
def test_single_scope_when(self, scope: Scope, required: bool) -> None:
if required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from overture.schema.system.doc import DocumentedEnum
from overture.schema.system.model_constraint import (
FieldEqCondition,
radio_group,
require_any_true,
require_if,
)
from overture.schema.system.primitive import (
Expand Down Expand Up @@ -53,7 +53,7 @@ class AreaClass(str, DocumentedEnum):
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.REGION))
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.MACROCOUNTY))
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.COUNTY))
@radio_group("is_land", "is_territorial")
@require_any_true("is_land", "is_territorial")
class DivisionArea(
OvertureFeature[Literal["divisions"], Literal["division_area"]], Named
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from overture.schema.system.model_constraint import (
FieldEqCondition,
forbid_if,
radio_group,
require_any_true,
require_if,
)
from overture.schema.system.primitive import (
Expand Down Expand Up @@ -57,7 +57,7 @@ class BoundaryClass(str, DocumentedEnum):
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.REGION))
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.MACROCOUNTY))
@require_if(["admin_level"], FieldEqCondition("subtype", DivisionSubtype.COUNTY))
@radio_group("is_land", "is_territorial")
@require_any_true("is_land", "is_territorial")
class DivisionBoundary(
OvertureFeature[Literal["divisions"], Literal["division_boundary"]]
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,29 +468,35 @@
}
}
],
"not": {
"required": [
"id",
"bbox",
"geometry"
]
},
"oneOf": [
"anyOf": [
{
"properties": {
"is_land": {
"const": true
}
}
},
"required": [
"is_land"
]
},
{
"properties": {
"is_territorial": {
"const": true
}
}
},
"required": [
"is_territorial"
]
}
],
"not": {
"required": [
"id",
"bbox",
"geometry"
]
},
"patternProperties": {
"^ext_.*$": {
"description": "Additional top-level properties are allowed if prefixed by `ext_`.\n\nThis feature is a on a deprecation path and will be removed once the schema is\nfully migrated to Pydantic."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,29 +396,35 @@
}
}
],
"not": {
"required": [
"id",
"bbox",
"geometry"
]
},
"oneOf": [
"anyOf": [
{
"properties": {
"is_land": {
"const": true
}
}
},
"required": [
"is_land"
]
},
{
"properties": {
"is_territorial": {
"const": true
}
}
},
"required": [
"is_territorial"
]
}
],
"not": {
"required": [
"id",
"bbox",
"geometry"
]
},
"patternProperties": {
"^ext_.*$": {
"description": "Additional top-level properties are allowed if prefixed by `ext_`.\n\nThis feature is a on a deprecation path and will be removed once the schema is\nfully migrated to Pydantic."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .no_extra_fields import NoExtraFieldsConstraint, no_extra_fields
from .radio_group import RadioGroupConstraint, radio_group
from .require_any_of import RequireAnyOfConstraint, require_any_of
from .require_any_true import RequireAnyTrueConstraint, require_any_true
from .require_if import RequireIfConstraint, require_if

__all__ = [
Expand All @@ -31,7 +32,9 @@
"radio_group",
"RadioGroupConstraint",
"require_any_of",
"require_any_true",
"require_if",
"RequireAnyOfConstraint",
"RequireAnyTrueConstraint",
"RequireIfConstraint",
]
Loading
Loading