-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/cli' into develop
- Loading branch information
Showing
10 changed files
with
730 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .base import start_server_background | ||
from .cli import cli_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .base import app as cli_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Optional | ||
|
||
import requests | ||
import typer | ||
from rich import print | ||
from rich.markdown import Markdown | ||
from rich.panel import Panel | ||
from rich.text import Text | ||
|
||
from .judge import app as judge_typer | ||
|
||
app = typer.Typer() | ||
app.add_typer(judge_typer) | ||
|
||
|
||
@app.command(name='intro', help='查看ItsWA介绍') | ||
def intro(): | ||
md = Markdown( | ||
""" | ||
## 欢迎使用 ItsWA 评测系统 | ||
ItsWA是一个基于Python搭建,使用`Lrun`提供安全运行时的Linux下的竞赛代码评测系统。 | ||
查看`docs/guide.pdf`获取使用教程 | ||
""" | ||
) | ||
|
||
print(md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import Annotated, Optional, Union | ||
|
||
import typer | ||
|
||
from ccf_parser import CCF | ||
from judge import start_judging | ||
from utils import manager_logger | ||
|
||
app = typer.Typer(name='judge', help='评测相关') | ||
|
||
|
||
@app.command('start', help='开始评测') | ||
def start_judging_command(path: Annotated[Path, typer.Argument(help='比赛目录或CCF文件')] = Path('.')): | ||
ccf: Optional[CCF] = None | ||
|
||
if path.name == 'ccf.json': | ||
ccf = CCF(**json.loads(path.read_text('utf-8'))) | ||
elif path.is_dir() and path.joinpath('ccf.json').exists(): | ||
ccf = CCF(**json.loads(path.joinpath('ccf.json').read_text('utf-8'))) | ||
else: | ||
raise FileNotFoundError('评测目录不正确,可能是不存在CCF文件') | ||
|
||
start_judging(ccf) | ||
return 0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import shutil | ||
import tempfile | ||
from pathlib import Path | ||
from typing import Generator | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def temp_contest(): | ||
tmpcon = tempfile.mkdtemp() | ||
Path(tmpcon).mkdir(parents=True, exist_ok=True) | ||
|
||
shutil.copytree( | ||
Path('./tests/environment').absolute().__str__(), | ||
tmpcon, | ||
dirs_exist_ok=True | ||
) | ||
|
||
yield Path(tmpcon).absolute() | ||
|
||
# shutil.rmtree(tmpcon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from typer.testing import CliRunner | ||
|
||
from manager import cli_app | ||
|
||
|
||
@pytest.fixture | ||
def cli_runner() -> CliRunner: | ||
return CliRunner() | ||
|
||
|
||
def test_intro(cli_runner: CliRunner): | ||
result = cli_runner.invoke(cli_app, ["intro"]) | ||
|
||
assert result.exit_code == 0 | ||
assert "欢迎使用 ItsWA 评测系统" in result.stdout | ||
|
||
|
||
def test_start_judging(cli_runner: CliRunner, temp_contest: Path): | ||
result = cli_runner.invoke( | ||
cli_app, ["judge", "start", temp_contest.absolute().__str__()]) | ||
assert result.exit_code == 0 | ||
|
||
result = cli_runner.invoke( | ||
cli_app, ["judge", "start", temp_contest.joinpath('ccf.json').absolute().__str__()]) | ||
assert result.exit_code == 0 | ||
|
||
result = cli_runner.invoke( | ||
cli_app, ["judge", "start", temp_contest.joinpath('114514').absolute().__str__()]) | ||
assert result.exit_code != 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters