Skip to content

Commit

Permalink
Merge pull request #150 from SciCatProject/make-type-readonly
Browse files Browse the repository at this point in the history
Make type readonly
  • Loading branch information
jl-wynen authored Oct 2, 2023
2 parents 88b3318 + a87872b commit 9f0070e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
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

0 comments on commit 9f0070e

Please sign in to comment.