Skip to content

Commit e3e94e6

Browse files
committed
Add new testing clients. Change Submission.status to be Status enum.
1 parent 38d87a8 commit e3e94e6

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

src/judge0/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from enum import IntEnum
33

44

5+
# TODO: Consider moving enumerations and other possible future types to separate
6+
# module (_types.py).
57
class Language(IntEnum):
68
PYTHON = 0
79
CPP = 1

src/judge0/submission.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def set_attributes(self, attributes):
125125

126126
if attr in ENCODED_FIELDS:
127127
setattr(self, attr, decode(value) if value else None)
128+
elif attr == "status":
129+
self.status = Status(value["id"])
128130
else:
129131
setattr(self, attr, value)
130132

@@ -151,5 +153,4 @@ def is_done(self) -> bool:
151153
if self.status is None:
152154
return False
153155
else:
154-
# TODO: When status is changed to `Status`, refactor this as well.
155-
return self.status["id"] not in (Status.IN_QUEUE, Status.PROCESSING)
156+
return self.status not in (Status.IN_QUEUE, Status.PROCESSING)

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88
load_dotenv()
99

1010

11+
@pytest.fixture(scope="session")
12+
def judge0_ce_client():
13+
api_key = os.getenv("JUDGE0_TEST_API_KEY")
14+
api_key_header = os.getenv("JUDGE0_TEST_API_KEY_HEADER")
15+
endpoint = os.getenv("JUDGE0_TEST_CE_ENDPOINT")
16+
client = clients.Client(
17+
endpoint=endpoint,
18+
auth_headers={api_key_header: api_key},
19+
)
20+
return client
21+
22+
23+
@pytest.fixture(scope="session")
24+
def judge0_extra_ce_client():
25+
api_key = os.getenv("JUDGE0_TEST_API_KEY")
26+
api_key_header = os.getenv("JUDGE0_TEST_API_KEY_HEADER")
27+
endpoint = os.getenv("JUDGE0_TEST_EXTRA_CE_ENDPOINT")
28+
client = clients.Client(
29+
endpoint=endpoint,
30+
auth_headers={api_key_header: api_key},
31+
)
32+
return client
33+
34+
1135
@pytest.fixture(scope="session")
1236
def atd_ce_client():
1337
api_key = os.getenv("JUDGE0_ATD_API_KEY")

tests/test_submission.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
from judge0 import Status, Submission, wait
4+
5+
6+
def test_status_before_and_after_submission(request):
7+
client = request.getfixturevalue("judge0_ce_client")
8+
submission = Submission('print("Hello World!")')
9+
10+
assert submission.status is None
11+
12+
client.create_submission(submission)
13+
client.get_submission(submission)
14+
15+
assert submission.status.__class__ == Status
16+
assert submission.status >= Status.IN_QUEUE
17+
18+
19+
def test_is_done(request):
20+
client = request.getfixturevalue("judge0_ce_client")
21+
submission = Submission('print("Hello World!")')
22+
23+
assert submission.status is None
24+
25+
client.create_submission(submission)
26+
wait(client, submission)
27+
28+
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