You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.6 KiB

  1. from django.core.exceptions import ValidationError
  2. from django.test import TestCase
  3. from model_mommy import mommy
  4. from projects.models import SEQUENCE_LABELING
  5. from projects.tests.utils import prepare_project
  6. class TestRelationLabeling(TestCase):
  7. @classmethod
  8. def setUpTestData(cls):
  9. cls.project = prepare_project(SEQUENCE_LABELING)
  10. cls.example = mommy.make("Example", project=cls.project.item)
  11. cls.label_type = mommy.make("RelationType", project=cls.project.item)
  12. cls.user = cls.project.admin
  13. def test_can_annotate_relation(self):
  14. from_id = mommy.make("Span", example=self.example, start_offset=0, end_offset=1)
  15. to_id = mommy.make("Span", example=self.example, start_offset=1, end_offset=2)
  16. mommy.make("Relation", example=self.example, from_id=from_id, to_id=to_id)
  17. def test_cannot_annotate_relation_if_span_example_is_different(self):
  18. from_id = mommy.make("Span", example=self.example, start_offset=0, end_offset=1)
  19. to_id = mommy.make("Span", start_offset=1, end_offset=2)
  20. with self.assertRaises(ValidationError):
  21. mommy.make("Relation", example=self.example, from_id=from_id, to_id=to_id)
  22. def test_cannot_annotate_relation_if_relation_example_is_different_from_span_example(self):
  23. from_id = mommy.make("Span", example=self.example, start_offset=0, end_offset=1)
  24. to_id = mommy.make("Span", example=self.example, start_offset=1, end_offset=2)
  25. with self.assertRaises(ValidationError):
  26. mommy.make("Relation", from_id=from_id, to_id=to_id)