Skip to content

Commit 204bcd6

Browse files
committed
Add get_client public function.
1 parent c7957f6 commit 204bcd6

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/judge0/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from .api import async_execute, execute, run, sync_execute, wait
3+
from .api import async_execute, execute, get_client, run, sync_execute, wait
44
from .base_types import Flavor, Language, LanguageAlias, Status, TestCase
55
from .clients import (
66
ATD,
@@ -41,6 +41,7 @@
4141
"TestCase",
4242
"async_execute",
4343
"execute",
44+
"get_client",
4445
"run",
4546
"sync_execute",
4647
"wait",

src/judge0/api.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
from .submission import Submission, Submissions
88

99

10+
def get_client(flavor: Flavor = Flavor.CE) -> Client:
11+
from . import _get_implicit_client
12+
13+
if isinstance(flavor, Flavor):
14+
return _get_implicit_client(flavor=flavor)
15+
else:
16+
raise ValueError(
17+
"Expected argument flavor to be of of type enum Flavor, "
18+
f"got {type(flavor)}."
19+
)
20+
21+
1022
def resolve_client(
1123
client: Optional[Union[Client, Flavor]] = None,
1224
submissions: Optional[Union[Submission, Submissions]] = None,
@@ -15,11 +27,8 @@ def resolve_client(
1527
if isinstance(client, Client):
1628
return client
1729

18-
from . import _get_implicit_client
19-
20-
# User explicitly choose the flavor of the client.
2130
if isinstance(client, Flavor):
22-
return _get_implicit_client(flavor=client)
31+
return get_client(flavor=client)
2332

2433
if client is None and isinstance(submissions, list) and len(submissions) == 0:
2534
raise ValueError("Client cannot be determined from empty submissions.")
@@ -33,7 +42,7 @@ def resolve_client(
3342
languages = [submission.language for submission in submissions]
3443

3544
for flavor in Flavor:
36-
client = _get_implicit_client(flavor)
45+
client = get_client(flavor)
3746
if client is not None and all(
3847
(client.is_language_supported(lang) for lang in languages)
3948
):

tests/test_submission.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
31
from judge0 import Status, Submission, wait
42

53

@@ -23,6 +21,6 @@ def test_is_done(request):
2321
assert submission.status is None
2422

2523
client.create_submission(submission)
26-
wait(client, submission)
24+
wait(client=client, submissions=submission)
2725

2826
assert submission.is_done()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy