Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make type readonly #150

Merged
merged 3 commits into from
Oct 2, 2023
Merged
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
5 changes: 0 additions & 5 deletions src/scitacean/_dataset_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,6 @@ def type(self) -> DatasetType:
"""Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models."""
return self._type

@type.setter
def type(self, type: Union[DatasetType, Literal["raw", "derived"]]) -> None:
"""Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models."""
self._type = DatasetType(type)

@staticmethod
def _prepare_fields_from_download(
download_model: DownloadDataset,
Expand Down
4 changes: 2 additions & 2 deletions src/scitacean/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ def download_model_type(cls) -> Type[DownloadAttachment]:
class DownloadOrigDatablock(BaseModel):
dataFileList: Optional[List[DownloadDataFile]] = None
datasetId: Optional[PID] = None
ownerGroup: Optional[str] = None
size: Optional[NonNegativeInt] = None
id: Optional[str] = pydantic.Field(alias="_id", default=None)
accessGroups: Optional[List[str]] = None
chkAlg: Optional[str] = None
createdAt: Optional[datetime] = None
createdBy: Optional[str] = None
instrumentGroup: Optional[str] = None
ownerGroup: Optional[str] = None
updatedAt: Optional[datetime] = None
updatedBy: Optional[str] = None

Expand All @@ -344,11 +344,11 @@ def upload_model_type(cls) -> Type[UploadOrigDatablock]:
class UploadOrigDatablock(BaseModel):
dataFileList: List[UploadDataFile]
datasetId: PID
ownerGroup: str
size: NonNegativeInt
accessGroups: Optional[List[str]] = None
chkAlg: Optional[str] = None
instrumentGroup: Optional[str] = None
ownerGroup: Optional[str] = None

@classmethod
def download_model_type(cls) -> Type[DownloadOrigDatablock]:
Expand Down
8 changes: 7 additions & 1 deletion tests/dataset_fields_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# Fields whose types are not supported by hypothesis.
# E.g. because they contain `Any`.
_UNGENERATABLE_FIELDS = ("job_parameters", "meta")
# Fields that are readonly, but still required in the constructor.
_NOT_SETTABLE_FIELDS = ("type",)


def test_init_dataset_with_only_type():
Expand Down Expand Up @@ -107,7 +109,11 @@ def test_can_init_writable_fields(field, data):

@pytest.mark.parametrize(
"field",
(f for f in Dataset.fields(read_only=False) if f.name not in _UNGENERATABLE_FIELDS),
(
f
for f in Dataset.fields(read_only=False)
if f.name not in _UNGENERATABLE_FIELDS and f.name not in _NOT_SETTABLE_FIELDS
),
ids=lambda f: f.name,
)
@given(st.data())
Expand Down
5 changes: 0 additions & 5 deletions tools/model-generation/templates/dataset_fields.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ class DatasetBase:
"""Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models."""
return self._type

@type.setter
def type(self, type: Union[DatasetType, Literal["raw", "derived"]]) -> None:
"""Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models."""
self._type = DatasetType(type)

@staticmethod
def _prepare_fields_from_download(
download_model: DownloadDataset
Expand Down