feat: add resumable dataset uploads
This commit is contained in:
parent
f8ed08b854
commit
8d40cff227
23 changed files with 913 additions and 21 deletions
59
tests/test_imports.py
Normal file
59
tests/test_imports.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
"""Server zip import: pure COCO mapping + job validation (no R2 touched)."""
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
from src.services.imports import build_bulk_from_coco
|
||||
from src.services import imports as svc
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db():
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
from src.core.db import Base
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield async_sessionmaker(engine, expire_on_commit=False)
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
COCO = {
|
||||
"images": [{"id": 1, "file_name": "a.jpg"}, {"id": 2, "file_name": "b.jpg"}],
|
||||
"annotations": [
|
||||
{"image_id": 1, "category_id": 1, "bbox": [10, 20, 30, 40]},
|
||||
{"image_id": 1, "category_id": 2,
|
||||
"segmentation": [[0, 0, 10, 0, 10, 10, 0, 10]]},
|
||||
{"image_id": 2, "category_id": 9, "iscrowd": 1,
|
||||
"segmentation": {"counts": "xyz"}},
|
||||
{"image_id": 999, "category_id": 1, "bbox": [0, 0, 5, 5]},
|
||||
],
|
||||
"categories": [{"id": 1, "name": "car"}, {"id": 2, "name": "bus"}],
|
||||
}
|
||||
CATS = {"car": {"id": "c1", "name": "car", "color": "#fff"},
|
||||
"bus": {"id": "c2", "name": "bus", "color": "#000"}}
|
||||
|
||||
|
||||
def test_bulk_mapping_bbox_polygon_and_skips():
|
||||
payload = build_bulk_from_coco(
|
||||
COCO, {"a.jpg": "img1", "b.jpg": "img2"}, CATS)
|
||||
assert set(payload) == {"img1"} # b.jpg: RLE-only + unknown image 999 skipped
|
||||
kinds = sorted(s.type for s in payload["img1"].shapes)
|
||||
assert kinds == ["bbox", "polygon"]
|
||||
poly = next(s for s in payload["img1"].shapes if s.type == "polygon")
|
||||
assert [(p.x, p.y) for p in poly.points or []] == [(0, 0), (10, 0), (10, 10), (0, 10)]
|
||||
assert payload["img1"].shapes[0].labelId == "c1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_local_zip_validates(db):
|
||||
from fastapi import HTTPException
|
||||
async with db() as s:
|
||||
await s.execute(text(
|
||||
"INSERT INTO projects (id, slug, name, task_type, status) "
|
||||
"VALUES ('p1', 'p1', 'P', 'object_detection', 'annotating')"))
|
||||
await s.commit()
|
||||
with pytest.raises(HTTPException):
|
||||
await svc.start_local_zip("p1", "relative.zip", s)
|
||||
with pytest.raises(HTTPException):
|
||||
await svc.start_local_zip("nope", "/tmp/x.zip", s)
|
||||
Loading…
Add table
Add a link
Reference in a new issue