Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from warnings import warn
from deprecation import deprecated

from citrine._rest.resource import Resource
from citrine._serialization import properties
Expand Down Expand Up @@ -153,11 +153,9 @@ def __init__(self,
self.powers = powers if powers is not None else [1.0]

@property
@deprecated(deprecated_in="4.0.0", removed_in="5.0.0", details="Use 'powers' instead.")
def powers_as_float(self) -> list[float]:
"""Powers when computing generalized weighted means of element properties."""
warn("'powers_as_float' is deprecated as of v4.0.0 in favor of 'powers', and will be "
"removed in v5.0.0",
DeprecationWarning)
return self.powers

def __str__(self):
Expand Down
39 changes: 11 additions & 28 deletions src/citrine/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from logging import getLogger
from time import time, sleep
from uuid import UUID
from warnings import warn

from citrine._rest.resource import Resource
from citrine._serialization.properties import Set as PropertySet, String, Object
Expand Down Expand Up @@ -51,20 +50,13 @@ class TaskNode(Resource['TaskNode']):
""":str: if a task has failed, the failure reason will be in this parameter"""

@property
def status(self) -> JobStatus | str:
def status(self) -> JobStatus:
"""The last reported status of this particular task."""
if resolved := JobStatus.from_str(self._status, exception=False):
return resolved
else:
return self._status
return JobStatus.from_str(self._status, exception=False)

@status.setter
def status(self, value: JobStatus | str) -> None:
if JobStatus.from_str(value, exception=False) is None:
warn(
f"{value} is not a recognized JobStatus; this will become an error as of v4.0.0.",
DeprecationWarning
)
JobStatus.from_str(value, exception=True)
self._status = value


Expand All @@ -84,27 +76,18 @@ class JobStatusResponse(Resource['JobStatusResponse']):
""":dict[str, str] | None: job output properties and results"""

@property
def status(self) -> JobStatus | str:
def status(self) -> JobStatus:
"""The last reported status of this particular task."""
if resolved := JobStatus.from_str(self._status, exception=False):
return resolved
else:
return self._status
return JobStatus.from_str(self._status, exception=False)

@status.setter
def status(self, value: JobStatus | str) -> None:
if resolved := JobStatus.from_str(value, exception=False):
if resolved not in [JobStatus.RUNNING, JobStatus.SUCCESS, JobStatus.FAILURE]:
warn(
f"{value} is not a valid JobStatus for a JobStatusResponse; "
f"this will become an error as of v4.0.0.",
DeprecationWarning
)
else:
warn(
f"{value} is not a recognized JobStatus; this will become an error as of v4.0.0.",
DeprecationWarning
)
if resolved := JobStatus.from_str(value, exception=True):
valid = [JobStatus.RUNNING, JobStatus.SUCCESS, JobStatus.FAILURE]
if resolved not in valid:
raise ValueError(f"{value} is not a valid JobStatus for a JobStatusResponse; "
f"valid choices are {[x for x in valid]}")

self._status = value


Expand Down
39 changes: 0 additions & 39 deletions tests/jobs/test_deprecations.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/jobs/test_job_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from citrine.jobs.job import JobStatus, JobStatusResponse, TaskNode
import pytest

from tests.utils.factories import TaskNodeDataFactory, JobStatusResponseDataFactory

def test_status_response_status():
status_response = JobStatusResponse.build(JobStatusResponseDataFactory(failure=True))
assert status_response.status == JobStatus.FAILURE

with pytest.raises(ValueError):
status_response.status = 'Failed'
assert isinstance(status_response.status, JobStatus)

with pytest.raises(ValueError):
status_response.status = JobStatus.PENDING
assert status_response.status != JobStatus.PENDING

status_response.status = JobStatus.SUCCESS
assert status_response.status == JobStatus.SUCCESS

def test_task_node_status():
status_response = TaskNode.build(TaskNodeDataFactory(failure=True))
assert status_response.status == JobStatus.FAILURE

with pytest.raises(ValueError):
status_response.status = 'Failed'
assert isinstance(status_response.status, JobStatus)

status_response.status = JobStatus.SUCCESS
assert status_response.status == JobStatus.SUCCESS