Skip to content

Commit

Permalink
fix: avoid mutable default values as arguments + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Oct 10, 2024
1 parent 86d0f4c commit b2b0232
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion diracx-db/src/diracx/db/sql/pilot_agents/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ async def addPilotReferences(
pilotRef: list[str],
VO: str,
gridType: str = "DIRAC",
pilotStampDict: dict = {},
pilotStampDict: dict | None = None,
) -> list[int]:

if pilotStampDict is None:
pilotStampDict = {}
row_ids = []
for ref in pilotRef:
stamp = ""
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions diracx-db/tests/pilot_agents/test_pilotAgentsDB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

import pytest

from diracx.db.sql.pilot_agents.db import PilotAgentsDB


@pytest.fixture
async def pilot_agents_db(tmp_path) -> PilotAgentsDB:
agents_db = PilotAgentsDB("sqlite+aiosqlite:///:memory:")
async with agents_db.engine_context():
async with agents_db.engine.begin() as conn:
await conn.run_sync(agents_db.metadata.create_all)
yield agents_db


async def test_insert_and_select(pilot_agents_db: PilotAgentsDB):

async with pilot_agents_db as pilot_agents_db:
# Add a pilot reference
refs = [f"ref_{i}" for i in range(10)]
stamps = [f"stamp_{i}" for i in range(10)]
stamp_dict = dict(zip(refs, stamps))

pilot_id = await pilot_agents_db.addPilotReferences(
refs, "test_vo", gridType="DIRAC", pilotStampDict=stamp_dict
)
assert pilot_id
assert pilot_id == list(range(1, 11))

0 comments on commit b2b0232

Please sign in to comment.