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
910 B

import unittest
from ...views.upload.utils import append_field
class TestDatasetUtils(unittest.TestCase):
def test_can_append_field(self):
data = [
{'label': 'A'},
{'label': 'B'}
]
append_field(data, project=1)
expected = [
{'label': 'A', 'project': 1},
{'label': 'B', 'project': 1}
]
self.assertEqual(data, expected)
def test_can_append_field_to_nested_list(self):
annotation = [
[{'label': '18'}],
[{'label': '7'}, {'label': '4'}]
]
docs = list(range(len(annotation)))
for a, d in zip(annotation, docs):
append_field(a, document=d)
expected = [
[{'label': '18', 'document': 0}],
[{'label': '7', 'document': 1}, {'label': '4', 'document': 1}]
]
self.assertEqual(annotation, expected)