Skip to content

Commit

Permalink
tests: Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Mar 5, 2024
1 parent f07bf9f commit cf7f3ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 53 deletions.
59 changes: 25 additions & 34 deletions tests/unit/client/feedback/schemas/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from datetime import datetime
from uuid import uuid4

from argilla import ValueSchema
from argilla.client.sdk.users.models import UserModel, UserRole
from argilla.feedback import ResponseBuilder, ResponseSchema, ResponseStatus, SpanValueSchema, TextQuestion
from argilla.feedback import (
FeedbackDataset,
ResponseSchema,
ResponseStatus,
SpanValueSchema,
TextQuestion,
ValueSchema,
)


def test_create_span_response_wrong_limits():
with pytest.raises(ValueError, match="The end of the span must be greater than the start."):
SpanValueSchema(start=10, end=8, label="test")


def test_create_response_from_builder():
def test_create_response():
question = TextQuestion(name="text")
user = UserModel(
id=uuid4(),
api_key="test",
username="test",
role=UserRole.annotator,
first_name="test",
last_name="test",
inserted_at=datetime.utcnow(),
updated_at=datetime.utcnow(),
)

response = ResponseBuilder().status("draft").question_value(question, "Value for text").user(user).build()
response = ResponseSchema(status="draft").with_question_value(question, "Value for text")

assert response.user_id == user.id
assert response.status == ResponseStatus.draft
assert question.name in response.values
assert response.values[question.name].value == "Value for text"


def test_create_response_with_wrong_value():
with pytest.raises(ValueError, match="Value 10 is not valid for question type text. Expected <class 'str'>."):
ResponseBuilder().status("draft").question_value(TextQuestion(name="text"), 10).build()


def test_create_response_builder_from_response():
response = ResponseSchema(
user_id=uuid4(), status=ResponseStatus.draft, values={"text": ValueSchema(value="Value for text")}
def test_create_responses_with_multiple_questions():
question1 = TextQuestion(name="text")
question2 = TextQuestion(name="text2")
response = (
ResponseSchema(status="draft")
.with_question_value(question1, "Value for text")
.with_question_value(question2, "Value for text2")
)

builder = ResponseBuilder.from_response(response)
assert response.status == ResponseStatus.draft
assert question1.name in response.values
assert response.values[question1.name].value == "Value for text"
assert question2.name in response.values
assert response.values[question2.name].value == "Value for text2"

new_response = builder.question_value(TextQuestion(name="other-text"), "Value for other text").build()

assert new_response.user_id == response.user_id
assert new_response.status == response.status
assert "text" in new_response.values
assert "other-text" in new_response.values
assert new_response.values["text"].value == "Value for text"
assert new_response.values["other-text"].value == "Value for other text"
def test_create_response_with_wrong_value():
with pytest.raises(ValueError, match="Value 10 is not valid for question type text. Expected <class 'str'>."):
ResponseSchema(status="draft").with_question_value(TextQuestion(name="text"), 10)
23 changes: 4 additions & 19 deletions tests/unit/client/feedback/schemas/test_suggestions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

from argilla.feedback import TextQuestion, SuggestionBuilder, SuggestionSchema
from argilla.feedback import SuggestionSchema, TextQuestion


def test_create_suggestion_from_builder():
def test_create_suggestion():
question = TextQuestion(name="text")

suggestion = SuggestionBuilder().question_value(question, "Value for text").agent("mock").type("human").build()
suggestion = SuggestionSchema.with_question_value(question, "Value for text", agent="mock", type="human")

assert suggestion.question_name == question.name
assert suggestion.agent == "mock"
Expand All @@ -16,19 +16,4 @@ def test_create_suggestion_from_builder():

def test_create_suggestion_with_wrong_value():
with pytest.raises(ValueError, match="Value 10 is not valid for question type text. Expected <class 'str'>."):
SuggestionBuilder().question_value(TextQuestion(name="text"), 10).agent("mock").type("human").build()


def test_create_builder_from_suggestion():
suggestion = SuggestionSchema(question_name="text", value="Value for text", agent="mock", type="human")
builder = SuggestionBuilder.from_suggestion(suggestion)

new_suggestion = builder.question_value(TextQuestion(name="other-text"), "Value for other text").build()

assert new_suggestion.agent == suggestion.agent
assert new_suggestion.type == suggestion.type
assert new_suggestion.question_name == "other-text"
assert new_suggestion.value == "Value for other text"

assert new_suggestion.question_name != suggestion.question_name
assert new_suggestion.value != suggestion.value
SuggestionSchema.with_question_value(TextQuestion(name="text"), 10, agent="Mock")

0 comments on commit cf7f3ab

Please sign in to comment.