Skip to content

Commit

Permalink
Revert to the OpenApiGenNoneType for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
illusional committed Sep 18, 2023
1 parent 3735b98 commit 0ff8bef
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion metamist/parser/generic_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def __init__(
def to_sm(self) -> AssayUpsert:
"""Convert to SM upsert model"""
return AssayUpsert(
type=self.assay_type,
id=self.internal_id,
type=self.assay_type,
external_ids=self.external_ids,
# sample_id=self.s,
meta=self.meta,
Expand Down
2 changes: 1 addition & 1 deletion models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# annotate any external objects that must be instantiated with this
# type to force openapi generator to allow for Nones (it will actually allow Any)
OpenApiGenNoneType = bytes
OpenApiGenNoneType = bytes | None


class SMBase(BaseModel):
Expand Down
24 changes: 12 additions & 12 deletions models/models/assay.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from typing import Any

from models.base import SMBase
from models.base import OpenApiGenNoneType, SMBase
from models.utils.sample_id_format import sample_id_format, sample_id_transform_to_raw


Expand Down Expand Up @@ -88,11 +88,11 @@ def to_internal(self):
class AssayUpsert(SMBase):
"""Assay upsert model for external use"""

id: int | None = None
type: str | None = None
external_ids: dict[str, str] | None = None
sample_id: str | None = None
meta: dict[str, Any] | None = None
id: int | OpenApiGenNoneType = None
type: str | OpenApiGenNoneType = None
external_ids: dict[str, str] | OpenApiGenNoneType = None
sample_id: str | OpenApiGenNoneType = None
meta: dict[str, Any] | OpenApiGenNoneType = None

def to_internal(self):
"""Convert to internal model"""
Expand All @@ -101,12 +101,12 @@ def to_internal(self):
_sample_id = None
if self.sample_id:
# but may be provided directly when inserting directly
_sample_id = sample_id_transform_to_raw(self.sample_id)
_sample_id = sample_id_transform_to_raw(self.sample_id) # type: ignore

return AssayUpsertInternal(
id=self.id,
type=self.type,
external_ids=self.external_ids,
sample_id=_sample_id,
meta=self.meta,
id=self.id, # type: ignore
type=self.type, # type: ignore
external_ids=self.external_ids, # type: ignore
sample_id=_sample_id, # type: ignore
meta=self.meta, # type: ignore
)
26 changes: 13 additions & 13 deletions models/models/participant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from db.python.utils import ProjectId
from models.base import SMBase
from models.base import OpenApiGenNoneType, SMBase
from models.models.family import FamilySimple, FamilySimpleInternal
from models.models.sample import (
NestedSample,
Expand Down Expand Up @@ -123,24 +123,24 @@ class NestedParticipant(SMBase):
class ParticipantUpsert(SMBase):
"""External upsert model for participant"""

id: int | None = None
external_id: str | None = None
reported_sex: int | None = None
reported_gender: str | None = None
karyotype: str | None = None
meta: dict | None = None
id: int | OpenApiGenNoneType = None
external_id: str | OpenApiGenNoneType = None
reported_sex: int | OpenApiGenNoneType = None
reported_gender: str | OpenApiGenNoneType = None
karyotype: str | OpenApiGenNoneType = None
meta: dict | OpenApiGenNoneType = None

samples: list[SampleUpsert] | None = None

def to_internal(self):
"""Convert to internal model, doesn't really do much"""
p = ParticipantUpsertInternal(
id=self.id,
external_id=self.external_id,
reported_sex=self.reported_sex,
reported_gender=self.reported_gender,
karyotype=self.karyotype,
meta=self.meta,
id=self.id, # type: ignore
external_id=self.external_id, # type: ignore
reported_sex=self.reported_sex, # type: ignore
reported_gender=self.reported_gender, # type: ignore
karyotype=self.karyotype, # type: ignore
meta=self.meta, # type: ignore
)

if self.samples:
Expand Down
28 changes: 14 additions & 14 deletions models/models/sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from models.base import SMBase
from models.base import OpenApiGenNoneType, SMBase
from models.models.assay import Assay, AssayInternal, AssayUpsert, AssayUpsertInternal
from models.models.sequencing_group import (
NestedSequencingGroup,
Expand Down Expand Up @@ -159,13 +159,13 @@ class NestedSample(SMBase):
class SampleUpsert(SMBase):
"""Upsert model for a Sample"""

id: str | None = None
external_id: str | None = None
meta: dict | None = None
project: int | None = None
type: str | None = None
participant_id: int | None = None
active: bool | None = None
id: str | OpenApiGenNoneType = None
external_id: str | OpenApiGenNoneType = None
meta: dict | OpenApiGenNoneType = None
project: int | OpenApiGenNoneType = None
type: str | OpenApiGenNoneType = None
participant_id: int | OpenApiGenNoneType = None
active: bool | OpenApiGenNoneType = None

sequencing_groups: list[SequencingGroupUpsert] | None = None
non_sequencing_assays: list[AssayUpsert] | None = None
Expand All @@ -178,12 +178,12 @@ def to_internal(self) -> SampleUpsertInternal:

sample_upsert = SampleUpsertInternal(
id=_id,
external_id=self.external_id,
meta=self.meta,
project=self.project,
type=self.type,
participant_id=self.participant_id,
active=self.active,
external_id=self.external_id, # type: ignore
meta=self.meta, # type: ignore
project=self.project, # type: ignore
type=self.type, # type: ignore
participant_id=self.participant_id, # type: ignore
active=self.active, # type: ignore
)

if self.sequencing_groups:
Expand Down
30 changes: 15 additions & 15 deletions models/models/sequencing_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from models.base import SMBase
from models.base import OpenApiGenNoneType, SMBase
from models.models.assay import Assay, AssayInternal, AssayUpsert, AssayUpsertInternal
from models.utils.sample_id_format import sample_id_format, sample_id_transform_to_raw
from models.utils.sequencing_group_id_format import (
Expand Down Expand Up @@ -163,15 +163,15 @@ class SequencingGroupUpsert(SMBase):
Upsert model for sequence group
"""

id: int | str | None = None
type: str | None = None
technology: str | None = None
platform: str | None = None
meta: dict[str, str] | None = None
sample_id: str | None = None
external_ids: dict[str, str] | None = None
id: int | str | OpenApiGenNoneType = None
type: str | OpenApiGenNoneType = None
technology: str | OpenApiGenNoneType = None
platform: str | OpenApiGenNoneType = None
meta: dict[str, str] | OpenApiGenNoneType = None
sample_id: str | OpenApiGenNoneType = None
external_ids: dict[str, str] | OpenApiGenNoneType = None

assays: list[AssayUpsert] | None = None
assays: list[AssayUpsert] | OpenApiGenNoneType = None

def to_internal(self) -> SequencingGroupUpsertInternal:
"""
Expand All @@ -187,15 +187,15 @@ def to_internal(self) -> SequencingGroupUpsertInternal:

sg_internal = SequencingGroupUpsertInternal(
id=_id,
type=self.type,
technology=self.technology,
platform=self.platform.lower() if self.platform else None,
meta=self.meta,
type=self.type, # type: ignore
technology=self.technology, # type: ignore
platform=self.platform.lower() if self.platform else None, # type: ignore
meta=self.meta, # type: ignore
sample_id=_sample_id,
external_ids=self.external_ids or {},
external_ids=self.external_ids or {}, # type: ignore
)

if self.assays is not None:
sg_internal.assays = [a.to_internal() for a in self.assays]
sg_internal.assays = [a.to_internal() for a in self.assays] # type: ignore

return sg_internal

0 comments on commit 0ff8bef

Please sign in to comment.