pasqal-cloud 0.2.4__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {pasqal-cloud-0.2.4/pasqal_cloud.egg-info → pasqal-cloud-0.2.5}/PKG-INFO +1 -1
  2. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/__init__.py +41 -3
  3. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/_version.py +1 -1
  4. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/batch.py +19 -14
  5. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/client.py +24 -12
  6. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/errors.py +5 -4
  7. pasqal-cloud-0.2.5/pasqal_cloud/job.py +46 -0
  8. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5/pasqal_cloud.egg-info}/PKG-INFO +1 -1
  9. pasqal-cloud-0.2.5/tests/conftest.py +110 -0
  10. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_batch.py +53 -2
  11. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_client.py +7 -8
  12. pasqal-cloud-0.2.5/tests/test_cloud_sdk_import.py +30 -0
  13. pasqal-cloud-0.2.4/pasqal_cloud/job.py +0 -36
  14. pasqal-cloud-0.2.4/tests/conftest.py +0 -52
  15. pasqal-cloud-0.2.4/tests/test_cloud_sdk_import.py +0 -25
  16. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/LICENSE +0 -0
  17. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/MANIFEST.in +0 -0
  18. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/README.md +0 -0
  19. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/authentication.py +0 -0
  20. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/__init__.py +0 -0
  21. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/configuration/__init__.py +0 -0
  22. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/configuration/base_config.py +0 -0
  23. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/configuration/emu_free.py +0 -0
  24. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/configuration/emu_tn.py +0 -0
  25. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/device/emulator_types.py +0 -0
  26. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/endpoints.py +0 -0
  27. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/py.typed +0 -0
  28. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/utils/__init__.py +0 -0
  29. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/utils/jsend.py +0 -0
  30. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud/utils/strenum.py +0 -0
  31. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud.egg-info/SOURCES.txt +0 -0
  32. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud.egg-info/dependency_links.txt +0 -0
  33. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud.egg-info/requires.txt +5 -5
  34. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pasqal_cloud.egg-info/top_level.txt +0 -0
  35. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/pyproject.toml +0 -0
  36. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/sdk/__init__.py +0 -0
  37. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/sdk/device/__init__.py +0 -0
  38. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/sdk/device/configuration/__init__.py +0 -0
  39. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/sdk/setup.py +0 -0
  40. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/sdk/utils/__init__.py +0 -0
  41. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/setup.cfg +0 -0
  42. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/setup.py +0 -0
  43. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/__init__.py +0 -0
  44. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_config.py +0 -0
  45. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_device_specs.py +0 -0
  46. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_doubles/__init__.py +0 -0
  47. {pasqal-cloud-0.2.4 → pasqal-cloud-0.2.5}/tests/test_doubles/authentication.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pasqal-cloud
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Software development kit for Pasqal cloud platform.
5
5
  Home-page: https://github.com/pasqal-io/pasqal-cloud
6
6
  Maintainer: Pasqal Cloud Services
@@ -114,7 +114,7 @@ class SDK:
114
114
  )
115
115
  batch = Batch(**batch_rsp, _client=self._client)
116
116
  for job_rsp in jobs_rsp:
117
- batch.jobs[job_rsp["id"]] = Job(**job_rsp)
117
+ batch.jobs[job_rsp["id"]] = Job(**job_rsp, _client=self._client)
118
118
 
119
119
  self.batches[batch.id] = batch
120
120
  return batch
@@ -123,7 +123,7 @@ class SDK:
123
123
  """Retrieve a batch's data and all its jobs.
124
124
 
125
125
  Args:
126
- id: Id of the batch.
126
+ id: ID of the batch.
127
127
  fetch_results: whether to download job results
128
128
 
129
129
  Returns:
@@ -133,10 +133,48 @@ class SDK:
133
133
  batch_rsp, jobs_rsp = self._client._get_batch(id, fetch_results=fetch_results)
134
134
  batch = Batch(**batch_rsp, _client=self._client)
135
135
  for job_rsp in jobs_rsp:
136
- batch.jobs[job_rsp["id"]] = Job(**job_rsp)
136
+ batch.jobs[job_rsp["id"]] = Job(**job_rsp, _client=self._client)
137
137
  self.batches[batch.id] = batch
138
138
  return batch
139
139
 
140
+ def cancel_batch(self, id: str) -> Batch:
141
+ """Cancel the given batch on the PCS
142
+
143
+ Args:
144
+ id: ID of the batch.
145
+ """
146
+ batch_rsp = self._client._cancel_batch(id)
147
+ batch = Batch(**batch_rsp, _client=self._client)
148
+ return batch
149
+
150
+ def get_job(self, id: str, wait: bool = False) -> Job:
151
+ """Retrieve a job's data.
152
+
153
+ Args:
154
+ id: ID of the job.
155
+ wait: Whether to wait for the job to be done
156
+
157
+ Returns:
158
+ Job: the job stored in the PCS database.
159
+ """
160
+ job_rsp = self._client._get_job(id)
161
+ if wait:
162
+ while job_rsp["status"] in ["PENDING", "RUNNING"]:
163
+ time.sleep(RESULT_POLLING_INTERVAL)
164
+ job_rsp = self._client._get_job(id)
165
+ job = Job(**job_rsp, _client=self._client)
166
+ return job
167
+
168
+ def cancel_job(self, id: str) -> Job:
169
+ """Cancel the given job on the PCS
170
+
171
+ Args:
172
+ id: ID of the job.
173
+ """
174
+ job_rsp = self._client._cancel_job(id)
175
+ job = Job(**job_rsp, _client=self._client)
176
+ return job
177
+
140
178
  def get_device_specs_dict(self) -> Dict[str, str]:
141
179
  """Retrieve the list of available device specifications.
142
180
 
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "0.2.4"
15
+ __version__ = "0.2.5"
@@ -16,28 +16,28 @@ class Batch:
16
16
 
17
17
  A batch groups up several jobs with the same sequence. When a batch is assigned to
18
18
  a QPU, all its jobs are ran sequentially and no other batch can be assigned to the
19
- device until all its jobs are done and it is declared complete.
19
+ device until all its jobs are done and declared complete.
20
20
 
21
21
  Attributes:
22
22
  - complete: Whether the batch has been declared as complete.
23
23
  - created_at: Timestamp of the creation of the batch.
24
- - updated_at: Timestamps of the last update of the batch.
24
+ - updated_at: Timestamp of the last update of the batch.
25
25
  - device_type: Type of device to run the batch on.
26
- - group_id: Id of the owner group of the batch.
26
+ - group_id: ID of the owner group of the batch.
27
27
  - id: Unique identifier for the batch.
28
28
  - user_id: Unique identifier of the user that created the batch.
29
29
  - priority: Level of priority of the batch.
30
- - status: Status of the batch.
30
+ - status: Status of the batch. Possible values are: PENDING, RUNNING, DONE, CANCELED, TIMED_OUT, ERROR, PAUSED.
31
31
  - webhook: Webhook where the job results are automatically sent to.
32
+ - _client: A Client instance to connect to PCS.
32
33
  - sequence_builder: Pulser sequence of the batch.
33
34
  - start_datetime: Timestamp of the time the batch was sent to the QPU.
34
- - end_datetime: Timestamp of when the batch process was finished.
35
+ - end_datetime: Timestamp of when the batch process was finished.
35
36
  - device_status: Status of the device where the batch is running.
36
37
  - jobs: Dictionary of all the jobs added to the batch.
37
- - jobs_count: number of jobs added to the batch.
38
- - jobs_count_per_status: number of jobs per status.
38
+ - jobs_count: Number of jobs added to the batch.
39
+ - jobs_count_per_status: Number of jobs per status.
39
40
  - configuration: Further configuration for certain emulators.
40
-
41
41
  """
42
42
 
43
43
  complete: bool
@@ -81,7 +81,7 @@ class Batch:
81
81
  """Add and send a new job for this batch.
82
82
 
83
83
  Args:
84
- runs: number of times the job is ran on the QPU.
84
+ runs: number of times the job is run on the QPU.
85
85
  variables (optional): values for variables if sequence is parametrized.
86
86
  wait: Whether to wait for the job to be done.
87
87
 
@@ -92,7 +92,7 @@ class Batch:
92
92
  if variables:
93
93
  job_data["variables"] = variables
94
94
  job_rsp = self._client._send_job(job_data)
95
- job = Job(**job_rsp)
95
+ job = Job(**job_rsp, _client=self._client)
96
96
  self.jobs[job.id] = job
97
97
  if wait:
98
98
  while job.status in ["PENDING", "RUNNING"]:
@@ -107,16 +107,15 @@ class Batch:
107
107
  """Declare to PCS that the batch is complete.
108
108
 
109
109
  Args:
110
- wait: Whether to wait for the batch to be done
111
- fetch_results: Whether to download the results. Implies
112
- waiting for the batch.
110
+ wait: Whether to wait for the batch to be done.
111
+ fetch_results: Whether to download the results. Implies waiting for the batch.
113
112
 
114
113
  A batch that is complete awaits no extra jobs. All jobs previously added
115
114
  will be executed before the batch is terminated. When all its jobs are done,
116
115
  the complete batch is unassigned to its running device.
117
116
  """
118
- self.complete = True
119
117
  batch_rsp = self._client._complete_batch(self.id)
118
+ self.complete = True
120
119
  if wait or fetch_results:
121
120
  while batch_rsp["status"] in ["PENDING", "RUNNING"]:
122
121
  time.sleep(RESULT_POLLING_INTERVAL)
@@ -130,3 +129,9 @@ class Batch:
130
129
  for job_rsp in jobs_rsp:
131
130
  self.jobs[job_rsp["id"]] = Job(**job_rsp)
132
131
  return batch_rsp
132
+
133
+ def cancel(self) -> Dict[str, Any]:
134
+ """Cancel the current batch on the PCS."""
135
+ batch_rsp = self._client._cancel_batch(self.id)
136
+ self.status = batch_rsp.get("status", "CANCELED")
137
+ return batch_rsp
@@ -126,18 +126,6 @@ class Client:
126
126
  jobs_data = batch_data.pop("jobs", [])
127
127
  return batch_data, jobs_data
128
128
 
129
- def _complete_batch(self, batch_id: str) -> Dict[str, Any]:
130
- response: Dict[str, Any] = self._request(
131
- "PUT", f"{self.endpoints.core}/api/v1/batches/{batch_id}/complete"
132
- )["data"]
133
- return response
134
-
135
- def _send_job(self, job_data: Dict[str, Any]) -> Dict[str, Any]:
136
- response: Dict[str, Any] = self._request(
137
- "POST", f"{self.endpoints.core}/api/v1/jobs", job_data
138
- )["data"]
139
- return response
140
-
141
129
  def _get_batch(
142
130
  self, id: str, fetch_results: bool = False
143
131
  ) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
@@ -153,12 +141,36 @@ class Client:
153
141
  job_data["result"] = results.get(str(job_data["id"]), None)
154
142
  return batch_data, jobs_data
155
143
 
144
+ def _complete_batch(self, batch_id: str) -> Dict[str, Any]:
145
+ response: Dict[str, Any] = self._request(
146
+ "PUT", f"{self.endpoints.core}/api/v1/batches/{batch_id}/complete"
147
+ )["data"]
148
+ return response
149
+
150
+ def _cancel_batch(self, batch_id: str) -> Dict[str, Any]:
151
+ batch: Dict[str, Any] = self._request(
152
+ "PUT", f"{self.endpoints.core}/api/v1/batches/{batch_id}/cancel"
153
+ )["data"]
154
+ return batch
155
+
156
+ def _send_job(self, job_data: Dict[str, Any]) -> Dict[str, Any]:
157
+ response: Dict[str, Any] = self._request(
158
+ "POST", f"{self.endpoints.core}/api/v1/jobs", job_data
159
+ )["data"]
160
+ return response
161
+
156
162
  def _get_job(self, job_id: str) -> Dict[str, Any]:
157
163
  job: Dict[str, Any] = self._request(
158
164
  "GET", f"{self.endpoints.core}/api/v1/jobs/{job_id}"
159
165
  )["data"]
160
166
  return job
161
167
 
168
+ def _cancel_job(self, job_id: str) -> Dict[str, Any]:
169
+ job: Dict[str, Any] = self._request(
170
+ "PUT", f"{self.endpoints.core}/api/v1/jobs/{job_id}/cancel"
171
+ )["data"]
172
+ return job
173
+
162
174
  def get_device_specs_dict(self) -> Dict[str, str]:
163
175
  device_specs: Dict[str, str] = self._request(
164
176
  "GET", f"{self.endpoints.core}/api/v1/devices/specs"
@@ -26,12 +26,13 @@ class HTTPError(Exception):
26
26
 
27
27
  def __init__(self, data: JSendPayload, *args: object) -> None:
28
28
  super().__init__(*args)
29
- self.code = data["code"]
29
+ self.code = data.get("code", 0)
30
+
30
31
  # If no error description, display default response message instead
31
- if data.get("data"):
32
- self.description = data["data"].get("description", data["message"])
32
+ if data.get("data", ""):
33
+ self.description = data["data"].get("description", data.get("message"))
33
34
  else:
34
- self.description = data["message"]
35
+ self.description = data.get("message", "")
35
36
  self.details = data
36
37
 
37
38
  def __str__(self) -> str:
@@ -0,0 +1,46 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any, Dict, List, Optional
3
+
4
+ from pasqal_cloud.client import Client
5
+
6
+
7
+ @dataclass
8
+ class Job:
9
+ """Class for job data.
10
+
11
+ Attributes:
12
+ - runs: Number of times the job should be run.
13
+ - created_at: Timestamp of the creation of the job.
14
+ - updated_at: Timestamp of the last update of the job.
15
+ - start_timestamp: The timestamp of when the job began processing.
16
+ - end_timestamp: The timestamp of when the job finished processing.
17
+ - batch_id: ID of the batch which the job belongs to.
18
+ - errors: Error messages that occurred while processing job.
19
+ - id: Unique identifier for the job.
20
+ - group_id: ID of the group which the users scheduling the job belong to.
21
+ - status: Status of the job. Possible values are: PENDING, RUNNING, DONE, CANCELED, TIMED_OUT, ERROR, PAUSED.
22
+ - _client: A Client instance to connect to PCS.
23
+ - result: Result of the job.
24
+ - variables: Dictionary of variables of the job.
25
+ None if the associated batch is non-parametrized.
26
+ """
27
+
28
+ runs: int
29
+ batch_id: str
30
+ id: str
31
+ group_id: str
32
+ status: str
33
+ _client : Client
34
+ created_at: str
35
+ updated_at: str
36
+ errors: List[str]
37
+ start_timestamp: Optional[str] = None
38
+ end_timestamp: Optional[str] = None
39
+ result: Optional[Dict[str, Any]] = None
40
+ variables: Optional[Dict[str, Any]] = None
41
+
42
+ def cancel(self) -> Dict[str, Any]:
43
+ """Cancel the current job on the PCS."""
44
+ job_rsp = self._client._cancel_job(self.id)
45
+ self.status = job_rsp.get("status", "CANCELED")
46
+ return job_rsp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pasqal-cloud
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Software development kit for Pasqal cloud platform.
5
5
  Home-page: https://github.com/pasqal-io/pasqal-cloud
6
6
  Maintainer: Pasqal Cloud Services
@@ -0,0 +1,110 @@
1
+ import json
2
+ import os
3
+ from unittest.mock import patch
4
+
5
+ import pytest
6
+ import requests_mock
7
+
8
+ from pasqal_cloud import Client, Batch, Job
9
+ from pasqal_cloud.endpoints import Endpoints
10
+ from tests.test_doubles.authentication import FakeAuth0AuthenticationSuccess
11
+
12
+ TEST_API_FIXTURES_PATH = "tests/fixtures/api"
13
+ JSON_FILE = "_.{}.json"
14
+
15
+
16
+ def mock_core_response(request):
17
+ path = request.url.split("/api/v1/")[1].split("?")[0]
18
+
19
+ data = None
20
+ if request.method == "POST":
21
+ data = request.json()
22
+
23
+ json_path = os.path.join(
24
+ TEST_API_FIXTURES_PATH, path, JSON_FILE.format(request.method)
25
+ )
26
+ with open(json_path) as json_file:
27
+ result = json.load(json_file)
28
+ if path == "batches" and data:
29
+ if data.get("emulator"):
30
+ result["data"]["device_type"] = data["emulator"]
31
+ else:
32
+ result["data"]["device_type"] = "FRESNEL"
33
+ result["data"]["configuration"] = None
34
+ return result
35
+
36
+
37
+ def mock_response(request, context):
38
+ """This acts as a Router to Mock the requests we make with custom behaviors."""
39
+ if request.url.startswith(Endpoints.core):
40
+ return mock_core_response(request)
41
+
42
+
43
+ @pytest.fixture(scope="session")
44
+ @requests_mock.Mocker(kw="mock")
45
+ def request_mock(mock=None):
46
+ # Configure requests to use the local JSON files a response
47
+ mock.register_uri(requests_mock.ANY, requests_mock.ANY, json=mock_response)
48
+ return mock
49
+
50
+
51
+ @pytest.fixture(scope="function")
52
+ def start_mock_request(request_mock):
53
+ request_mock.start()
54
+ yield request_mock
55
+ request_mock.stop()
56
+
57
+
58
+ @pytest.fixture
59
+ @patch("pasqal_cloud.client.Auth0TokenProvider", FakeAuth0AuthenticationSuccess)
60
+ def pasqal_client_mock():
61
+ client = Client(
62
+ group_id="00000000-0000-0000-0000-000000000002",
63
+ username="00000000-0000-0000-0000-000000000001",
64
+ password="password",
65
+ )
66
+ return client
67
+
68
+
69
+ @pytest.fixture
70
+ def batch(pasqal_client_mock):
71
+ batch_data = {
72
+ "complete": False,
73
+ "created_at": "2022-12-31T23:59:59.999Z",
74
+ "updated_at": "2023-01-01T00:00:00.000Z",
75
+ "device_type": "qpu",
76
+ "group_id": "00000000-0000-0000-0000-000000000002",
77
+ "id": "00000000-0000-0000-0000-000000000001",
78
+ "user_id": 1,
79
+ "priority": 0,
80
+ "status": "PENDING",
81
+ "webhook": "https://example.com/webhook",
82
+ "_client": pasqal_client_mock,
83
+ "sequence_builder": "pulser",
84
+ "start_datetime": "2023-01-01T00:00:00.000Z",
85
+ "end_datetime": None,
86
+ "device_status": "available",
87
+ "jobs": {}
88
+ }
89
+ return Batch(**batch_data)
90
+
91
+
92
+ @pytest.fixture
93
+ def job(pasqal_client_mock):
94
+ job_data = {
95
+ "runs": 50,
96
+ "batch_id": "00000000-0000-0000-0000-000000000001",
97
+ "id": "00000000-0000-0000-0000-000000022010",
98
+ "group_id": "00000000-0000-0000-0000-000000000001",
99
+ "status": "PENDING",
100
+ "_client": pasqal_client_mock,
101
+ "created_at": "2022-12-31T23:59:59.999Z",
102
+ "updated_at": "2023-01-01T00:00:00.000Z",
103
+ "errors": [],
104
+ "variables": {
105
+ "param1": 1,
106
+ "param2": 2,
107
+ "param3": 3
108
+ }
109
+ }
110
+ return Job(**job_data)
@@ -4,13 +4,13 @@ from uuid import uuid4
4
4
  import pytest
5
5
  from tests.test_doubles.authentication import FakeAuth0AuthenticationSuccess
6
6
 
7
- from pasqal_cloud import SDK
7
+ from pasqal_cloud import SDK, Batch, Job
8
8
  from pasqal_cloud.device import BaseConfig, EmuFreeConfig, EmulatorType, EmuTNConfig
9
9
 
10
10
 
11
11
  class TestBatch:
12
12
  @pytest.fixture(autouse=True)
13
- @patch("sdk.client.Auth0TokenProvider", FakeAuth0AuthenticationSuccess)
13
+ @patch("pasqal_cloud.client.Auth0TokenProvider", FakeAuth0AuthenticationSuccess)
14
14
  def init_sdk(self, start_mock_request):
15
15
  self.sdk = SDK(
16
16
  username="me@test.com", password="password", group_id=str(uuid4())
@@ -72,6 +72,57 @@ class TestBatch:
72
72
  assert job.result == self.job_result
73
73
  assert request_mock.last_request.method == "GET"
74
74
 
75
+ def test_get_batch(self, batch):
76
+ batch_requested = self.sdk.get_batch(batch.id)
77
+ assert (
78
+ batch_requested.id == self.batch_id
79
+ )
80
+
81
+ def test_cancel_batch_self(self, request_mock, batch):
82
+ batch.cancel()
83
+ assert batch.status == 'CANCELED'
84
+ assert request_mock.last_request.method == "PUT"
85
+ assert (
86
+ request_mock.last_request.url
87
+ == f"{self.sdk._client.endpoints.core}/api/v1/batches/{self.batch_id}/cancel"
88
+ )
89
+
90
+ def test_cancel_batch_sdk(self, request_mock):
91
+ client_rsp = self.sdk.cancel_batch(self.batch_id)
92
+ assert type(client_rsp) == Batch
93
+ assert client_rsp.status == 'CANCELED'
94
+ assert request_mock.last_request.method == "PUT"
95
+ assert (
96
+ request_mock.last_request.url
97
+ == f"{self.sdk._client.endpoints.core}/api/v1/batches/{self.batch_id}/cancel"
98
+ )
99
+
100
+ def test_get_job(self, job):
101
+ job_requested = self.sdk.get_job(job.id)
102
+ print(self.sdk)
103
+ assert (
104
+ job_requested.id == job.id
105
+ )
106
+
107
+ def test_cancel_job_self(self, request_mock, job):
108
+ job.cancel()
109
+ assert job.status == 'CANCELED'
110
+ assert request_mock.last_request.method == "PUT"
111
+ assert (
112
+ request_mock.last_request.url
113
+ == f"{self.sdk._client.endpoints.core}/api/v1/jobs/{self.job_id}/cancel"
114
+ )
115
+
116
+ def test_cancel_job_sdk(self, request_mock):
117
+ client_rsp = self.sdk.cancel_job(self.job_id)
118
+ assert type(client_rsp) == Job
119
+ assert client_rsp.status == 'CANCELED'
120
+ assert request_mock.last_request.method == "PUT"
121
+ assert (
122
+ request_mock.last_request.url
123
+ == f"{self.sdk._client.endpoints.core}/api/v1/jobs/{self.job_id}/cancel"
124
+ )
125
+
75
126
  @pytest.mark.skip(reason="Not enabled during Iroise MVP")
76
127
  def test_batch_add_job(self, request_mock):
77
128
  batch = self.sdk.create_batch(
@@ -11,14 +11,14 @@ from tests.test_doubles.authentication import (
11
11
  )
12
12
 
13
13
 
14
- @patch("sdk.client.Auth0TokenProvider", FakeAuth0AuthenticationSuccess)
14
+ @patch("pasqal_cloud.client.Auth0TokenProvider", FakeAuth0AuthenticationSuccess)
15
15
  class TestAuthSuccess:
16
16
  group_id = "random_group_id"
17
17
  username = "random_username"
18
18
  password = "random_password"
19
19
  new_core_endpoint = "random_endpoint"
20
20
 
21
- @patch("sdk.client.getpass")
21
+ @patch("pasqal_cloud.client.getpass")
22
22
  def test_module_getpass_success(self, getpass):
23
23
  getpass.return_value = self.password
24
24
  SDK(group_id=self.group_id, username=self.username)
@@ -32,7 +32,7 @@ class TestAuthSuccess:
32
32
  group_id=self.group_id,
33
33
  token_provider=FakeAuth0AuthenticationSuccess("username", "password", None),
34
34
  )
35
-
35
+
36
36
  def test_custom_token_provider(self):
37
37
  """Test that the custom provider suggested in the readme is working"""
38
38
  class CustomTokenProvider(TokenProvider):
@@ -40,7 +40,6 @@ class TestAuthSuccess:
40
40
  return "your-token" # Replace this value with your token
41
41
  SDK(token_provider=CustomTokenProvider(), group_id="group_id")
42
42
 
43
-
44
43
  def test_correct_endpoints(self):
45
44
  sdk = SDK(
46
45
  group_id=self.group_id,
@@ -60,7 +59,7 @@ class TestAuthSuccess:
60
59
  )
61
60
 
62
61
 
63
- @patch("sdk.client.Auth0TokenProvider", FakeAuth0AuthenticationFailure)
62
+ @patch("pasqal_cloud.client.Auth0TokenProvider", FakeAuth0AuthenticationFailure)
64
63
  class TestAuthFailure:
65
64
  group_id = "random_group_id"
66
65
  username = "random_username"
@@ -68,7 +67,7 @@ class TestAuthFailure:
68
67
  password = "random_password"
69
68
  no_password = ""
70
69
 
71
- @patch("sdk.client.getpass")
70
+ @patch("pasqal_cloud.client.getpass")
72
71
  def test_module_getpass_bad_password(self, getpass):
73
72
  getpass.return_value = self.password
74
73
 
@@ -97,7 +96,7 @@ class TestAuthInvalidClient:
97
96
  password=self.password,
98
97
  )
99
98
 
100
- @patch("sdk.client.getpass")
99
+ @patch("pasqal_cloud.client.getpass")
101
100
  def test_module_no_password(self, getpass):
102
101
  getpass.return_value = ""
103
102
  with pytest.raises(ValueError):
@@ -107,7 +106,7 @@ class TestAuthInvalidClient:
107
106
  password=self.no_password,
108
107
  )
109
108
 
110
- @patch("sdk.client.getpass")
109
+ @patch("pasqal_cloud.client.getpass")
111
110
  def test_module_getpass_no_password(self, getpass):
112
111
  getpass.return_value = self.no_password
113
112
 
@@ -0,0 +1,30 @@
1
+ import inspect
2
+ import warnings
3
+
4
+ import pytest
5
+
6
+ """
7
+ Tests written to verify if the backward compatibility is working between the new name of the package `pasqal-cloud`
8
+ and its main folder renamed to `pasqal_cloud` and the previous package name that was `pasqal-cloud`
9
+ with the former folder called `sdk`.
10
+ """
11
+
12
+
13
+ def test_verify_import_sdk_is_module():
14
+ with pytest.warns(DeprecationWarning):
15
+ import sdk
16
+ assert inspect.ismodule(sdk)
17
+
18
+
19
+ def test_verify_import_classes_from_sdk():
20
+ with pytest.warns(DeprecationWarning):
21
+ from sdk import SDK
22
+ from sdk import Batch
23
+ from sdk import Job
24
+ from sdk import Endpoints
25
+ from sdk import EmulatorType
26
+ from sdk.device.configuration import BaseConfig
27
+ from sdk.device.configuration import EmuFreeConfig
28
+ from sdk.device.configuration import EmuTNConfig
29
+ from sdk.utils import JSendPayload
30
+ from sdk.utils import StrEnum
@@ -1,36 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Any, Dict, List, Optional
3
-
4
-
5
- @dataclass
6
- class Job:
7
- """Class for job data.
8
-
9
- Attributes:
10
- - runs: Number of time the job should be ran.
11
- - created_at: Timestamp of the creation of the batch.
12
- - updated_at: Timestamps of the last update of the batch.
13
- - start_timestamp(optional): The timestamp of when the job began processing.
14
- - end_timestamp(optional): The timestamp of when the job finished processing.
15
- - batch_id: ID of the batch which the job belongs to.
16
- - errors: Error messages that occured while processing job.
17
- - id: Unique identifier for the batch
18
- - group_id: ID of the group which the users scheduling the job belong to.
19
- - status: Status of the job
20
- - result(optional): Result of the job.
21
- - variables (optional): dictionnary of variables of the job.
22
- None if the associated batch is non-parametrized
23
- """
24
-
25
- runs: int
26
- batch_id: str
27
- id: str
28
- group_id: str
29
- status: str
30
- created_at: str
31
- updated_at: str
32
- errors: List[str]
33
- start_timestamp: Optional[str] = None
34
- end_timestamp: Optional[str] = None
35
- result: Optional[Dict[str, Any]] = None
36
- variables: Optional[Dict[str, Any]] = None
@@ -1,52 +0,0 @@
1
- import json
2
- import os
3
-
4
- import pytest
5
- import requests_mock
6
-
7
- from pasqal_cloud.endpoints import Endpoints
8
-
9
- TEST_API_FIXTURES_PATH = "tests/fixtures/api"
10
- JSON_FILE = "_.{}.json"
11
-
12
-
13
- def mock_core_response(request):
14
- path = request.url.split("/api/v1/")[1].split("?")[0]
15
-
16
- data = None
17
- if request.method == "POST":
18
- data = request.json()
19
-
20
- json_path = os.path.join(
21
- TEST_API_FIXTURES_PATH, path, JSON_FILE.format(request.method)
22
- )
23
- with open(json_path) as json_file:
24
- result = json.load(json_file)
25
- if data:
26
- if data.get("emulator"):
27
- result["data"]["device_type"] = data["emulator"]
28
- else:
29
- result["data"]["device_type"] = "FRESNEL"
30
- result["data"]["configuration"] = None
31
- return result
32
-
33
-
34
- def mock_response(request, context):
35
- """This acts as a Router to Mock the requests we make with custom behaviors."""
36
- if request.url.startswith(Endpoints.core):
37
- return mock_core_response(request)
38
-
39
-
40
- @pytest.fixture(scope="session")
41
- @requests_mock.Mocker(kw="mock")
42
- def request_mock(mock=None):
43
- # Configure requests to use the local JSON files a response
44
- mock.register_uri(requests_mock.ANY, requests_mock.ANY, json=mock_response)
45
- return mock
46
-
47
-
48
- @pytest.fixture(scope="function")
49
- def start_mock_request(request_mock):
50
- request_mock.start()
51
- yield request_mock
52
- request_mock.stop()
@@ -1,25 +0,0 @@
1
- import inspect
2
-
3
- """
4
- Tests written to verify if the backward compatibility is working between the new name of the package `pasqal-cloud`
5
- and its main folder renamed to `pasqal_cloud` and the previous package name that was `pasqal-cloud`
6
- with the former folder called `sdk`.
7
- """
8
-
9
-
10
- def test_verify_import_sdk_is_module():
11
- import sdk
12
- assert inspect.ismodule(sdk)
13
-
14
-
15
- def test_verify_import_classes_from_sdk():
16
- from sdk import SDK
17
- from sdk import Batch
18
- from sdk import Job
19
- from sdk import Endpoints
20
- from sdk import EmulatorType
21
- from sdk.device.configuration import BaseConfig
22
- from sdk.device.configuration import EmuFreeConfig
23
- from sdk.device.configuration import EmuTNConfig
24
- from sdk.utils import JSendPayload
25
- from sdk.utils import StrEnum
File without changes
File without changes
File without changes
@@ -6,11 +6,11 @@ pyjwt[crypto]<3.0.0,>=2.5.0
6
6
  typing-extensions==4.4.0
7
7
 
8
8
  [dev]
9
- flake8==3.9.0
10
- types-requests==2.25.1
11
- requests-mock==1.9.3
12
- flake8-import-order==0.18.1
13
9
  mypy==0.982
14
- black==20.8b1
15
10
  pytest-cov==2.11.1
16
11
  pytest==6.2.5
12
+ flake8==3.9.0
13
+ flake8-import-order==0.18.1
14
+ requests-mock==1.9.3
15
+ black==20.8b1
16
+ types-requests==2.25.1
File without changes
File without changes
File without changes