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

Adding support for list fields to dynamic schema methods #2882

Merged
merged 13 commits into from
Apr 5, 2023
Prev Previous commit
Next Next commit
adding unit test for list subfield type declaration
  • Loading branch information
brimoor committed Apr 5, 2023
commit 63aeb2826ff8a21037df08b3c0dfbaeb7f9f3fc6
35 changes: 35 additions & 0 deletions tests/unittests/dataset_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,41 @@ def test_frame_field_schemas(self):
"frames.spam", embedded_doc_type=fo.Detections
)

@drop_datasets
def test_add_list_subfield(self):
sample = fo.Sample(
filepath="image.jpg",
ground_truth=fo.Classification(
label="cat",
info=[
fo.DynamicEmbeddedDocument(
author="Alice",
notes=["foo", "bar"],
),
fo.DynamicEmbeddedDocument(author="Bob"),
],
),
)

dataset = fo.Dataset()
dataset.add_sample(sample)

dataset.add_sample_field("ground_truth.info", fo.ListField)

field = dataset.get_field("ground_truth.info")
self.assertIsNone(field.field)

# Syntax for declaring the subfield type of an existing list field
dataset.add_sample_field(
"ground_truth.info[]",
fo.EmbeddedDocumentField,
embedded_doc_type=fo.DynamicEmbeddedDocument,
)

field = dataset.get_field("ground_truth.info")
self.assertIsInstance(field.field, fo.EmbeddedDocumentField)
self.assertEqual(field.field.document_type, fo.DynamicEmbeddedDocument)

@drop_datasets
def test_merge_samples1(self):
# Windows compatibility
Expand Down