Skip to content

Handle grouped test cases #49

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

Merged
merged 4 commits into from
Apr 9, 2025
Merged
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
33 changes: 20 additions & 13 deletions submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def is_python2(files):
return False
if python2.search(line.split('#')[0]):
return True
except UnicodeDecodeError:
pass
except IOError:
return False
return False
Expand Down Expand Up @@ -198,6 +200,8 @@ def guess_mainfile(language, files):
return filename
if language == 'Pascal' and re.match(r'^\s*[Pp]rogram\b', conts):
return filename
except UnicodeDecodeError:
pass
except IOError:
pass
return files[0]
Expand Down Expand Up @@ -321,12 +325,12 @@ def get_submission_status(submission_url, cookies):

_RED_COLOR = 31
_GREEN_COLOR = 32
_YELLOW_COLOR = 33
def color(s, c):
return f'\x1b[{c}m{s}\x1b[0m'


def show_judgement(submission_url, cfg):
print()
login_reply = login_from_config(cfg)
while True:
status = get_submission_status(submission_url, login_reply.cookies)
Expand All @@ -336,7 +340,6 @@ def show_judgement(submission_url, cfg):

status_text = _STATUS_MAP.get(status_id, f'Unknown status {status_id}')


if status_id < _RUNNING_STATUS:
print(f'\r{status_text}...', end='')
else:
Expand All @@ -359,15 +362,16 @@ def show_judgement(submission_url, cfg):
if testcases_total == 0:
print('???', end='')
else:
s = '.' * (testcases_done - 1)
if status_id == _RUNNING_STATUS:
s += '?'
elif status_id == _ACCEPTED_STATUS:
s += '.'
else:
s += 'x'
progress = ''
for i in re.findall(r'<i class="([\w\- ]*)" title', status['row_html']):
if 'is-empty' in i: break
if 'accepted' in i: progress += color('.', _GREEN_COLOR)
if 'rejected' in i: progress += color('x', _RED_COLOR)

print(f'[{s: <{testcases_total}}] {testcases_done} / {testcases_total}', end='')
# NB: We need to do the following math since len(color('.', _SOME_COLOR)) == 10
if status_id == _RUNNING_STATUS:
progress = progress[:10*(testcases_done - 1)] + color('?', _YELLOW_COLOR)
print(f'[{progress}{" " * (9*testcases_done + testcases_total - len(progress))}] {testcases_done} / {testcases_total}', end='')

sys.stdout.flush()

Expand All @@ -377,8 +381,12 @@ def show_judgement(submission_url, cfg):
success = status_id == _ACCEPTED_STATUS
try:
root = fragment_fromstring(status['row_html'], create_parent=True)
cpu_time = root.find('.//*[@data-type="cpu"]').text
status_text += " (" + cpu_time + ")"
cpu_time = root.xpath('.//*[@data-type="cpu"]')[0].text_content()
try:
score = re.findall(r'\(([\d\.]+)\)', root.xpath('.//*[@data-type="status"]')[0].text_content())[0]
except:
score = ''
status_text += " (" + cpu_time + ', ' + score + ")" if score else " (" + cpu_time + ")"
except:
pass
if status_id != _COMPILE_ERROR_STATUS:
Expand Down Expand Up @@ -504,7 +512,6 @@ def main():
pass

if submission_url:
print(submission_url)
if not show_judgement(submission_url, cfg):
sys.exit(1)

Expand Down