mirror of
https://gitlab.com/2-chainz/2chainz.git
synced 2025-06-15 17:36: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.
|
||||
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:
|
||||
image: ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER
|
||||
stage: test
|
||||
|
@ -37,13 +37,12 @@ class TestApi:
|
||||
response = client.get("/api/")
|
||||
assert response.json()["uptime_seconds"] == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("endpoint", ["/api/quote", "/api/alias"])
|
||||
class TestDataEndpoints:
|
||||
|
||||
def test_endpoint_nonempty(self, endpoint):
|
||||
for _ in range(1000): # Data is random so run the test a ton
|
||||
|
||||
# Given we have an endpoint
|
||||
for _ in range(1000): # Data is random so run the test a ton
|
||||
# Given we have an endpoint
|
||||
|
||||
# When we do a get request
|
||||
response = client.get(endpoint)
|
||||
@ -58,28 +57,31 @@ class TestDataEndpoints:
|
||||
|
||||
# Then the values should not be empty
|
||||
key, value = next(iter(data.items()))
|
||||
assert key
|
||||
assert key
|
||||
assert value
|
||||
|
||||
|
||||
class TestData:
|
||||
def test_data_exists(self):
|
||||
assert two_chainz.data
|
||||
assert two_chainz.data['quotes']
|
||||
assert two_chainz.data['aliases']
|
||||
assert two_chainz.data["quotes"]
|
||||
assert two_chainz.data["aliases"]
|
||||
|
||||
@pytest.mark.parametrize("quote", two_chainz.data['quotes'])
|
||||
@pytest.mark.parametrize("quote", two_chainz.data["quotes"])
|
||||
class TestQuotes:
|
||||
def test_no_empty(self, quote):
|
||||
assert quote
|
||||
|
||||
def test_no_ending_period(self, quote):
|
||||
assert quote[-1] != "."
|
||||
|
||||
def test_no_ending_newline(self, quote):
|
||||
assert quote[-1] != "\n"
|
||||
|
||||
@pytest.mark.parametrize("alias", two_chainz.data['quotes'])
|
||||
@pytest.mark.parametrize("alias", two_chainz.data["quotes"])
|
||||
class TestAlias:
|
||||
def test_no_empty(self, alias):
|
||||
assert 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]:
|
||||
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
|
||||
|
||||
|
||||
data = read_data()
|
||||
|
||||
|
||||
@app.get("/api/")
|
||||
async def ping():
|
||||
return {
|
||||
@ -29,12 +33,12 @@ async def ping():
|
||||
|
||||
@app.get("/api/quote")
|
||||
async def quote():
|
||||
return {"quote": random.choice(data['quotes'])}
|
||||
return {"quote": random.choice(data["quotes"])}
|
||||
|
||||
|
||||
@app.get("/api/alias")
|
||||
async def alias():
|
||||
return {"alias": random.choice(data['aliases'])}
|
||||
return {"alias": random.choice(data["aliases"])}
|
||||
|
||||
|
||||
# Mount static files
|
||||
|
Loading…
x
Reference in New Issue
Block a user