Пример #1
0
    def test_cancelled_job_raises_on_cancel_request(self, connection):
        """Tests that `job.cancel()` raises an error for a completed job."""
        job = Job("abc", status=JobStatus.CANCELLED, connection=connection)

        with pytest.raises(InvalidJobOperationError,
                           match="A cancelled job cannot be cancelled"):
            job.cancel()
Пример #2
0
    def test_incomplete_job_raises_on_result_access(self, connection):
        """Tests that `job.result` raises an error for an incomplete job."""
        job = Job("abc", status=JobStatus.QUEUED, connection=connection)

        with pytest.raises(
                AttributeError,
                match="The result is undefined for jobs that are not completed",
        ):
            job.result
Пример #3
0
 def get_job(self, _id):
     """Returns a 'queued' job status until the number of requests exceeds a defined
     threshold, beyond which a 'complete' job status is returned.
     """
     self.request_count += 1
     status = (JobStatus.COMPLETED
               if self.request_count >= self.REQUESTS_BEFORE_COMPLETED else
               JobStatus.QUEUED)
     return Job(id_="123",
                status=status,
                connection=None,
                meta={"foo": "bar"})
def job_to_complete(connection, monkeypatch):
    """Mocks a remote job that is completed after a certain number of requests."""
    monkeypatch.setattr(
        Connection,
        "create_job",
        mock_return(Job(id_="123", status=JobStatus.OPEN, connection=connection)),
    )
    server = MockServer()
    monkeypatch.setattr(Connection, "get_job_status", server.get_job_status)
    monkeypatch.setattr(
        Connection,
        "get_job_result",
        mock_return(Result(np.array([[1, 2], [3, 4]]), is_stateful=False)),
    )