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

chore: remove unused method & exception #50

Closed
wants to merge 5 commits into from
Closed
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
24 changes: 1 addition & 23 deletions tes/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import requests
import time

from attr import attrs, attrib
from attr.validators import instance_of, optional
Expand All @@ -9,7 +8,7 @@
from tes.models import (Task, ListTasksRequest, ListTasksResponse, ServiceInfo,
GetTaskRequest, CancelTaskRequest, CreateTaskResponse,
strconv)
from tes.utils import unmarshal, TimeoutError
from tes.utils import unmarshal


def append_suffixes_to_url(
Expand Down Expand Up @@ -173,27 +172,6 @@ def list_tasks(
response = send_request(paths=paths, kwargs_requests=kwargs)
return unmarshal(response.json(), ListTasksResponse)

def wait(self, task_id: str, timeout=None) -> Task:
def check_success(data: Task) -> bool:
return data.state not in ["QUEUED", "RUNNING", "INITIALIZING"]

max_time = time.time() + timeout if timeout else None

response: Optional[Task] = None
while True:
try:
response = self.get_task(task_id, "MINIMAL")
except Exception:
pass

if response is not None:
if check_success(response):
return response

if max_time is not None and time.time() >= max_time:
raise TimeoutError("last_response: {response.as_dict()}")
time.sleep(0.5)

def _request_params(
self, data: Optional[str] = None,
params: Optional[Dict] = None
Expand Down
28 changes: 0 additions & 28 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from tes.client import append_suffixes_to_url, HTTPClient, send_request
from tes.models import Task, Executor
from tes.utils import TimeoutError


class TestHTTPClient(unittest.TestCase):
Expand Down Expand Up @@ -176,33 +175,6 @@ def test_get_service_info(self):
with self.assertRaises(requests.HTTPError):
self.cli.get_service_info()

def test_wait(self):
with self.assertRaises(TimeoutError):
with requests_mock.Mocker() as m:
m.get(
"%s/ga4gh/tes/v1/tasks/%s" % (self.mock_url, self.mock_id),
status_code=200,
json={
"id": self.mock_id,
"state": "RUNNING",
}
)
self.cli.wait(self.mock_id, timeout=1)

with requests_mock.Mocker() as m:
m.get(
"%s/ga4gh/tes/v1/tasks/%s" % (self.mock_url, self.mock_id),
[
{"status_code": 200,
"json": {"id": self.mock_id, "state": "INITIALIZING"}},
{"status_code": 200,
"json": {"id": self.mock_id, "state": "RUNNING"}},
{"status_code": 200,
"json": {"id": self.mock_id, "state": "COMPLETE"}}
]
)
self.cli.wait(self.mock_id, timeout=2)


def test_append_suffixes_to_url():
urls = ["http://example.com", "http://example.com/"]
Expand Down