mirror of https://github.com/doccano/doccano.git
Hironsan
2 years ago
3 changed files with 54 additions and 11 deletions
Split View
Diff Options
-
22backend/data_import/datasets.py
-
18backend/data_import/pipeline/examples.py
-
25backend/data_import/tests/test_examples.py
@ -0,0 +1,18 @@ |
|||
from typing import Dict, List |
|||
|
|||
from pydantic import UUID4 |
|||
|
|||
from examples.models import Example |
|||
|
|||
|
|||
class Examples: |
|||
def __init__(self, examples: List[Example]): |
|||
self.examples = examples |
|||
self.uuid_to_example: Dict[UUID4, Example] = {} |
|||
|
|||
def __getitem__(self, uuid: UUID4): |
|||
return self.uuid_to_example[uuid] |
|||
|
|||
def save(self): |
|||
examples = Example.objects.bulk_create(self.examples) |
|||
self.uuid_to_example = {example.uuid: example for example in examples} |
@ -0,0 +1,25 @@ |
|||
import uuid |
|||
|
|||
from django.test import TestCase |
|||
|
|||
from data_import.pipeline.examples import Examples |
|||
from examples.models import Example |
|||
from projects.models import DOCUMENT_CLASSIFICATION |
|||
from projects.tests.utils import prepare_project |
|||
|
|||
|
|||
class TestCategories(TestCase): |
|||
def setUp(self): |
|||
self.project = prepare_project(DOCUMENT_CLASSIFICATION) |
|||
self.example_uuid = uuid.uuid4() |
|||
self.example = Example(uuid=self.example_uuid, text="A", project=self.project.item) |
|||
self.examples = Examples([self.example]) |
|||
|
|||
def test_save(self): |
|||
self.examples.save() |
|||
self.assertEqual(Example.objects.count(), 1) |
|||
|
|||
def test_getitem(self): |
|||
self.examples.save() |
|||
example = self.examples[self.example_uuid] |
|||
self.assertEqual(example, self.example) |
Write
Preview
Loading…
Cancel
Save