Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DIA-1862: Improve SDK coverage and data flow #6993

Merged
merged 15 commits into from
Feb 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests
nik committed Jan 29, 2025
commit 81462d0a55aa405e8dc40a21e52e4d3b4bfcb10d
2 changes: 2 additions & 0 deletions label_studio/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@
print('\n\n !!! Please, pip install pytest-env \n\n')
exit(-100)

from label_studio.tests.sdk.fixtures import * # noqa: F403

from .utils import (
azure_client_mock,
create_business,
29 changes: 29 additions & 0 deletions label_studio/tests/sdk/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from label_studio_sdk.client import LabelStudio
from label_studio_sdk.data_manager import Column, Filters, Operator, Type

from .common import LABEL_CONFIG_AND_TASKS


@pytest.fixture
def test_project_with_view(django_live_url, business_client):
ls = LabelStudio(base_url=django_live_url, api_key=business_client.api_key)
p = ls.projects.create(title='New Project', label_config=LABEL_CONFIG_AND_TASKS['label_config'])

project = ls.projects.get(id=p.id)

task_data = [{'data': {'my_text': 'Test task ' + str(i)}} for i in range(10)]
ls.projects.import_tasks(id=project.id, request=task_data)
orig_tasks = []
for task in ls.tasks.list(project=project.id):
orig_tasks.append(task)

filters = Filters.create(
Filters.OR,
[Filters.item(Column.id, Operator.EQUAL, Type.Number, Filters.value(t.id)) for t in orig_tasks[::2]],
)

view = ls.views.create(
project=project.id, data=dict(title='Test View', filters=filters, ordering=['-' + Column.id])
)
return ls, project, orig_tasks, view
21 changes: 21 additions & 0 deletions label_studio/tests/sdk/test_export.py
Original file line number Diff line number Diff line change
@@ -35,3 +35,24 @@ def test_direct_export(test_project):
df = ls.projects.exports.as_pandas(project.id)
assert isinstance(df, pd.DataFrame)
assert len(df) == 1

# Test low level export - import new task without annotations
ls.projects.import_tasks(
id=project.id,
request={
'data': {
'my_text': 'Opossums are great',
'ref_id': 456,
'meta_info': {'timestamp': '2020-03-09 18:15:28.212882', 'location': 'North Pole'},
}
},
)
data = ls.projects.exports.download_sync(project.id, download_all_tasks=False)
from label_studio_sdk.projects.exports.client_ext import _bytestream_to_json

assert len(_bytestream_to_json(data)) == 1

data = ls.projects.exports.download_sync(project.id, download_all_tasks=True)
from label_studio_sdk.projects.exports.client_ext import _bytestream_to_json

assert len(_bytestream_to_json(data)) == 2
24 changes: 5 additions & 19 deletions label_studio/tests/sdk/test_views.py
Original file line number Diff line number Diff line change
@@ -32,27 +32,13 @@ def test_create_view(django_live_url, business_client):
}


def test_get_tasks_from_view(django_live_url, business_client):
ls = LabelStudio(base_url=django_live_url, api_key=business_client.api_key)
p = ls.projects.create(title='New Project', label_config=LABEL_CONFIG_AND_TASKS['label_config'])

project = ls.projects.get(id=p.id)

task_data = [{'data': {'my_text': 'Test task ' + str(i)}} for i in range(10)]
ls.projects.import_tasks(id=project.id, request=task_data)
orig_tasks = []
for task in ls.tasks.list(project=project.id):
orig_tasks.append(task)

filters = Filters.create(
Filters.OR,
[Filters.item(Column.id, Operator.EQUAL, Type.Number, Filters.value(t.id)) for t in orig_tasks[::2]],
)

ls.views.create(project=project.id, data=dict(title='Test View', filters=filters, ordering=['-' + Column.id]))
def test_get_tasks_from_view(test_project_with_view):
ls, project, orig_tasks, view = test_project_with_view
views = ls.views.list(project=project.id)
assert len(views) == 1
view = views[0]
found_view = views[0]

assert found_view.id == view.id
tasks = []
for task in ls.tasks.list(view=view.id):
tasks.append(task)