Skip to content

Commit c57591b

Browse files
committed
Add ruff linter and fix formatting.
1 parent a551a47 commit c57591b

10 files changed

Lines changed: 51 additions & 23 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
DEFAULT_TEMPERATURE=0
2-
WEBUI_TOKEN=
2+
WEBUI_TOKEN=

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
ruff:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Ruff (lint)
16+
uses: astral-sh/ruff-action@v3
17+
18+
- name: Ruff (format check)
19+
uses: astral-sh/ruff-action@v3
20+
with:
21+
args: "format --check --diff"

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ Run this test with 2 users for 1 minute.
6464
locust -f ./tests/test_owui_api.py --users 2 --run-time 1m
6565
```
6666

67-
6867
### Verify setup of Locust
6968

7069
```bash
7170
locust --headless -f ./tests/test_verify_setup.py --users 1 --run-time 10s
7271
```
72+
73+
## Development
74+
75+
Install and use ruff
76+
```bash
77+
python -m pip install -U ruff
78+
ruff check .
79+
ruff format --check .
80+
```

common/cli_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from locust import events
22

3+
34
def _has_option(parser, option_string: str) -> bool:
45
return any(option_string in action.option_strings for action in parser._actions)
56

common/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
from datetime import datetime
55
from pathlib import Path
6-
from typing import Optional
76

87
from locust import events
98
from locust.html import get_html_report
@@ -35,11 +34,11 @@ def write_locust_html_report(
3534
*,
3635
environment,
3736
report_prefix: str,
38-
model: Optional[str] = None,
37+
model: str | None = None,
3938
reports_dir: str = "reports",
40-
timestamp: Optional[str] = None,
39+
timestamp: str | None = None,
4140
enabled: bool = True,
42-
) -> Optional[str]:
41+
) -> str | None:
4342
"""
4443
Create a Locust HTML report and write it to disk.
4544

locust.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ spawn-rate = 1
99
run-time = 1m
1010
#tags = [Critical, Normal]
1111
#csv = stats/locust
12-
loglevel = INFO
12+
loglevel = INFO

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[tool.ruff]
2+
line-length = 100
3+
4+
[tool.ruff.lint]
5+
select = ["E", "F", "I", "B", "UP"]

tests/test_owui_api.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""Locust test file to test Open WebUI."""
22

3-
import os
4-
from dotenv import load_dotenv
5-
63
import logging
4+
import os
75
import warnings
86

7+
from dotenv import load_dotenv
98
from locust import HttpUser, between, events, tag, task
109

1110
import common.cli_args # noqa: F401 (registers common args)
@@ -36,20 +35,18 @@ def on_test_stop(environment, **kwargs):
3635

3736

3837
class ApiClientUser(HttpUser):
39-
"""The main purpose of this test user is to test the API endpoints.
40-
"""
38+
"""The main purpose of this test user is to test the API endpoints."""
4139

4240
wait_time = between(2, 4)
4341

44-
@tag('api', 'health')
42+
@tag("api", "health")
4543
@task()
4644
def get_health(self):
4745
self.client.get("/health")
4846

49-
@tag('api')
47+
@tag("api")
5048
@task()
5149
def get_models_list(self):
52-
5350
bearer_token = os.getenv("WEBUI_TOKEN")
5451

5552
headers = {
@@ -63,7 +60,6 @@ def get_models_list(self):
6360
else:
6461
response.failure(f"Failed: {response.status_code}")
6562

66-
6763
def on_start(self):
6864
self.client.verify = False # Don't to check if certificate is valid
6965
logger.info("ONSTART new user of type ApiClientUser")

tests/test_owui_web.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Locust test file to test Open WebUI."""
22

3-
import os
43
import logging
54
import warnings
65

@@ -31,24 +30,22 @@ def on_test_stop(environment, **kwargs):
3130
print("[locust] Report creation disabled")
3231

3332

34-
3533
class WebUser(HttpUser):
36-
"""The main purpose of this test user is to test the web pages.
37-
"""
34+
"""The main purpose of this test user is to test the web pages."""
3835

3936
wait_time = between(1, 2)
4037

41-
@tag('web')
38+
@tag("web")
4239
@task(4)
4340
def browse_homepage(self):
4441
self.client.get("/")
4542

46-
@tag('web')
43+
@tag("web")
4744
@task
4845
def browse_workspace_models(self):
4946
self.client.get("/workspace/models")
5047

51-
@tag('web')
48+
@tag("web")
5249
@task
5350
def browse_notes(self):
5451
self.client.get("/notes")

tests/test_verify_setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class VerifyLocustUser(HttpUser):
1414
"""The main purpose of this test user is to verify the setup of the Locust test framework."""
15+
1516
wait_time = between(1, 2)
1617

1718
@task

0 commit comments

Comments
 (0)