Skip to content

Commit

Permalink
Lint bench sources
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaupetit committed Dec 2, 2024
1 parent 1fa14ab commit 9d22eaa
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 56 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ jobs:
- name: Lint with MyPy
run: pipenv run mypy qualicharge tests

lint-bench:
needs: build-api
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/bench
steps:
- uses: actions/checkout@v4
- name: Install pipenv
run: pipx install pipenv
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pipenv"
cache-dependency-path: "src/api/Pipfile.lock"
- name: Lint with Black
run: pipenv run black --check .
- name: Lint with Ruff
run: pipenv run ruff check .
- name: Lint with MyPy
run: pipenv run mypy .

bench-api:
needs: build-api
runs-on: ubuntu-latest
Expand Down
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ seed-dashboard: ## seed dashboard
lint: ## lint all sources
lint: \
lint-api \
lint-bench \
lint-client \
lint-prefect \
lint-dashboard
Expand All @@ -381,6 +382,13 @@ lint-api: \
lint-api-mypy
.PHONY: lint-api

lint-bench: ## lint api python sources
lint-bench: \
lint-bench-black \
lint-bench-ruff \
lint-bench-mypy
.PHONY: lint-bench

lint-client: ## lint client python sources
lint-client: \
lint-client-black \
Expand Down Expand Up @@ -423,6 +431,26 @@ lint-api-mypy: ## lint api python sources with mypy
@$(COMPOSE_RUN_API_PIPENV) mypy qualicharge tests
.PHONY: lint-api-mypy

lint-bench-black: ## lint bench python sources with black
@echo 'lint:black started…'
@$(COMPOSE_RUN_API_PIPENV) black /mnt/bench
.PHONY: lint-bench-black

lint-bench-ruff: ## lint bench python sources with ruff
@echo 'lint:ruff started…'
@$(COMPOSE_RUN_API_PIPENV) ruff check /mnt/bench
.PHONY: lint-bench-ruff

lint-bench-ruff-fix: ## lint and fix api python sources with ruff
@echo 'lint:ruff-fix started…'
@$(COMPOSE_RUN_API_PIPENV) ruff check --fix /mnt/bench
.PHONY: lint-bench-ruff-fix

lint-bench-mypy: ## lint bench python sources with mypy
@echo 'lint:mypy started…'
@$(COMPOSE_RUN_API_PIPENV) mypy /mnt/bench
.PHONY: lint-bench-mypy

lint-client-black: ## lint api python sources with black
@echo 'lint:black started…'
@$(COMPOSE_RUN_CLIENT) black qcc tests
Expand Down
1 change: 1 addition & 0 deletions src/api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ qualicharge = {path = ".", editable = true}
ruff = "==0.7.4"
types-passlib = "==1.7.7.20240819"
types-python-jose = "==3.3.4.20240106"
types-requests = "==2.32.0.20241016"

[requires]
python_version = "3.12"
99 changes: 54 additions & 45 deletions src/api/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/bench/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env python

"""Locust benchmark utility.
This client provides utilities to modify Locust output files.
"""

from pathlib import Path

import pandas as pd
import typer

import qualicharge


app = typer.Typer(no_args_is_help=True)


Expand Down Expand Up @@ -44,8 +48,7 @@ def diff(database: Path, current: Path, short: bool = True):

# Calculate diff
cols = list(
set(latest.columns.values)
- set(["Type", "Name", "git", "timestamp", "version"])
set(latest.columns.values) - {"Type", "Name", "git", "timestamp", "version"}
)
diff = bench[cols] - latest[cols]
diff.insert(0, "Type", latest["Type"])
Expand Down
19 changes: 11 additions & 8 deletions src/bench/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def on_start(self):
"username": self.username,
"password": self.password,
}
response = requests.post(f"{self.host}/auth/token", data=credentials)
response = requests.post(
f"{self.host}/auth/token", data=credentials, timeout=30
)
token = response.json()["access_token"]
self.client.auth_header = f"Bearer {token}"
self.statique_db = load_statique_db(self.static_db_path)
Expand All @@ -67,7 +69,8 @@ def statique_get(self):
with self.rest("GET", f"/statique/{id_pdc_itinerance}") as response:
if "id_pdc_itinerance" not in response.js:
response.failure(
f"Database does not contain target statique entry {id_pdc_itinerance}"
"Database does not contain target statique entry "
f"{id_pdc_itinerance}"
)

@task
Expand All @@ -80,7 +83,8 @@ def statique_update(self):
with self.rest("PUT", f"/statique/{id_pdc_itinerance}", json=data) as response:
if "id_pdc_itinerance" not in response.js:
response.failure(
f"Database does not contain target statique entry {id_pdc_itinerance}"
"Database does not contain target statique entry"
f"{id_pdc_itinerance}"
)

@task
Expand Down Expand Up @@ -146,7 +150,7 @@ def status_create(self):
"etat_prise_type_ef": "fonctionnel",
"id_pdc_itinerance": "FRALLEGO002006P3",
}
with self.rest("POST", "/dynamique/status/", json=data) as response:
with self.rest("POST", "/dynamique/status/", json=data) as _:
pass

@task
Expand All @@ -169,7 +173,7 @@ def status_bulk(self):
dict(base, horodatage=(now - delta * n).isoformat()) for n in range(size)
]

with self.rest("POST", "/dynamique/status/bulk", json=data) as response:
with self.rest("POST", "/dynamique/status/bulk", json=data) as _:
pass

@task
Expand All @@ -182,7 +186,7 @@ def session_create(self):
"energy": 666.66,
"id_pdc_itinerance": "FRALLEGO002006P3",
}
with self.rest("POST", "/dynamique/session/", json=data) as response:
with self.rest("POST", "/dynamique/session/", json=data) as _:
pass

@task
Expand All @@ -195,7 +199,6 @@ def session_bulk(self):
"energy": 666.66,
"id_pdc_itinerance": "FRALLEGO002006P3",
}
delta = timedelta(seconds=3)
size = 10
data = [
dict(
Expand All @@ -207,7 +210,7 @@ def session_bulk(self):
for n in range(size)
]

with self.rest("POST", "/dynamique/session/bulk", json=data) as response:
with self.rest("POST", "/dynamique/session/bulk", json=data) as _:
pass


Expand Down

0 comments on commit 9d22eaa

Please sign in to comment.