Skip to content

Commit

Permalink
Merge pull request #224 from dandi/gh-223
Browse files Browse the repository at this point in the history
Move `TempKlass`es outside of test functions
  • Loading branch information
yarikoptic authored Feb 7, 2024
2 parents c3a74cc + d96af2f commit d8213bb
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,14 @@ def test_properties_mismatch() -> None:
assert errors == []


def test_schemakey_roundtrip() -> None:
class TempKlass(DandiBaseModel):
contributor: Optional[List[Union[Organization, Person]]] = None
schemaKey: Literal["TempKlass"] = Field(
"TempKlass", validate_default=True, json_schema_extra={"readOnly": True}
)
class TempKlass1(DandiBaseModel):
contributor: Optional[List[Union[Organization, Person]]] = None
schemaKey: Literal["TempKlass1"] = Field(
"TempKlass1", validate_default=True, json_schema_extra={"readOnly": True}
)


def test_schemakey_roundtrip() -> None:
contributor = [
{
"name": "first",
Expand All @@ -598,33 +599,34 @@ class TempKlass(DandiBaseModel):
},
]
with pytest.raises(pydantic.ValidationError):
TempKlass(contributor=contributor)
TempKlass1(contributor=contributor)
contributor[0]["name"] = ", "
with pytest.raises(pydantic.ValidationError):
TempKlass(contributor=contributor)
TempKlass1(contributor=contributor)
contributor[0]["name"] = "last, first"
klassobj = TempKlass(contributor=contributor)
klassobj = TempKlass1(contributor=contributor)
assert klassobj.contributor is not None and all(
[isinstance(val, Person) for val in klassobj.contributor]
)


class TempKlass2(DandiBaseModel):
contributor: Person
schemaKey: Literal["TempKlass2"] = Field(
"TempKlass2", validate_default=True, json_schema_extra={"readOnly": True}
)


@pytest.mark.parametrize("name", ["Mitášová, Helena", "O'Brien, Claire"])
def test_name_regex(name: str) -> None:
class TempKlass(DandiBaseModel):
contributor: Person
schemaKey: Literal["TempKlass"] = Field(
"TempKlass", validate_default=True, json_schema_extra={"readOnly": True}
)

contributor = {
"name": name,
"roleName": [],
"schemaKey": "Person",
"affiliation": [],
"includeInCitation": True,
}
TempKlass(contributor=contributor)
TempKlass2(contributor=contributor)


def test_resource() -> None:
Expand Down

0 comments on commit d8213bb

Please sign in to comment.