mirror of
https://gitlab.com/2-chainz/2chainz.git
synced 2025-06-16 01:46:39 +00:00
do ruff stuff in CI
This commit is contained in:
parent
fdcf5be4c9
commit
972ce7c8cb
@ -6,6 +6,28 @@ variables:
|
|||||||
# so we need to copy instead of using hard links.
|
# so we need to copy instead of using hard links.
|
||||||
UV_LINK_MODE: copy
|
UV_LINK_MODE: copy
|
||||||
|
|
||||||
|
.base_ruff:
|
||||||
|
stage: build
|
||||||
|
interruptible: true
|
||||||
|
image:
|
||||||
|
name: ghcr.io/astral-sh/ruff:0.11.10-alpine
|
||||||
|
before_script:
|
||||||
|
- cd $CI_PROJECT_DIR
|
||||||
|
- ruff --version
|
||||||
|
|
||||||
|
Ruff Check:
|
||||||
|
extends: .base_ruff
|
||||||
|
script:
|
||||||
|
- ruff check --output-format=gitlab > code-quality-report.json
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
codequality: $CI_PROJECT_DIR/code-quality-report.json
|
||||||
|
|
||||||
|
Ruff Format:
|
||||||
|
extends: .base_ruff
|
||||||
|
script:
|
||||||
|
- ruff format --diff
|
||||||
|
|
||||||
pytest:
|
pytest:
|
||||||
image: ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER
|
image: ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER
|
||||||
stage: test
|
stage: test
|
||||||
|
@ -37,12 +37,11 @@ class TestApi:
|
|||||||
response = client.get("/api/")
|
response = client.get("/api/")
|
||||||
assert response.json()["uptime_seconds"] == expected
|
assert response.json()["uptime_seconds"] == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("endpoint", ["/api/quote", "/api/alias"])
|
@pytest.mark.parametrize("endpoint", ["/api/quote", "/api/alias"])
|
||||||
class TestDataEndpoints:
|
class TestDataEndpoints:
|
||||||
|
|
||||||
def test_endpoint_nonempty(self, endpoint):
|
def test_endpoint_nonempty(self, endpoint):
|
||||||
for _ in range(1000): # Data is random so run the test a ton
|
for _ in range(1000): # Data is random so run the test a ton
|
||||||
|
|
||||||
# Given we have an endpoint
|
# Given we have an endpoint
|
||||||
|
|
||||||
# When we do a get request
|
# When we do a get request
|
||||||
@ -65,21 +64,24 @@ class TestDataEndpoints:
|
|||||||
class TestData:
|
class TestData:
|
||||||
def test_data_exists(self):
|
def test_data_exists(self):
|
||||||
assert two_chainz.data
|
assert two_chainz.data
|
||||||
assert two_chainz.data['quotes']
|
assert two_chainz.data["quotes"]
|
||||||
assert two_chainz.data['aliases']
|
assert two_chainz.data["aliases"]
|
||||||
|
|
||||||
@pytest.mark.parametrize("quote", two_chainz.data['quotes'])
|
@pytest.mark.parametrize("quote", two_chainz.data["quotes"])
|
||||||
class TestQuotes:
|
class TestQuotes:
|
||||||
def test_no_empty(self, quote):
|
def test_no_empty(self, quote):
|
||||||
assert quote
|
assert quote
|
||||||
|
|
||||||
def test_no_ending_period(self, quote):
|
def test_no_ending_period(self, quote):
|
||||||
assert quote[-1] != "."
|
assert quote[-1] != "."
|
||||||
|
|
||||||
def test_no_ending_newline(self, quote):
|
def test_no_ending_newline(self, quote):
|
||||||
assert quote[-1] != "\n"
|
assert quote[-1] != "\n"
|
||||||
|
|
||||||
@pytest.mark.parametrize("alias", two_chainz.data['quotes'])
|
@pytest.mark.parametrize("alias", two_chainz.data["quotes"])
|
||||||
class TestAlias:
|
class TestAlias:
|
||||||
def test_no_empty(self, alias):
|
def test_no_empty(self, alias):
|
||||||
assert alias
|
assert alias
|
||||||
|
|
||||||
def test_no_ending_newline(self, alias):
|
def test_no_ending_newline(self, alias):
|
||||||
assert alias[-1] != "\n"
|
assert alias[-1] != "\n"
|
@ -12,12 +12,16 @@ start_time = time.time()
|
|||||||
|
|
||||||
def read_data() -> dict[str, str]:
|
def read_data() -> dict[str, str]:
|
||||||
raw_data = tomllib.loads(Path("data.toml").read_text())
|
raw_data = tomllib.loads(Path("data.toml").read_text())
|
||||||
raw_data['aliases'] = [alias['name'] for alias in raw_data['aliases'] for _ in range(alias['weight'])]
|
raw_data["aliases"] = [
|
||||||
|
alias["name"] for alias in raw_data["aliases"] for _ in range(alias["weight"])
|
||||||
|
]
|
||||||
|
|
||||||
return raw_data
|
return raw_data
|
||||||
|
|
||||||
|
|
||||||
data = read_data()
|
data = read_data()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/")
|
@app.get("/api/")
|
||||||
async def ping():
|
async def ping():
|
||||||
return {
|
return {
|
||||||
@ -29,12 +33,12 @@ async def ping():
|
|||||||
|
|
||||||
@app.get("/api/quote")
|
@app.get("/api/quote")
|
||||||
async def quote():
|
async def quote():
|
||||||
return {"quote": random.choice(data['quotes'])}
|
return {"quote": random.choice(data["quotes"])}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/alias")
|
@app.get("/api/alias")
|
||||||
async def alias():
|
async def alias():
|
||||||
return {"alias": random.choice(data['aliases'])}
|
return {"alias": random.choice(data["aliases"])}
|
||||||
|
|
||||||
|
|
||||||
# Mount static files
|
# Mount static files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user