|
| 1 | +from datetime import datetime |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import pytest |
| 5 | + |
| 6 | +from yarrow import Annotation, Contributor, Image, Info, YarrowDataset |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def contributor_base(): |
| 11 | + return Contributor(name="Jean Claude Vandamme", human=True) |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +def yarrow_base(contributor_base): |
| 16 | + yarrow = YarrowDataset( |
| 17 | + info=Info(date_created=datetime.now(), source="Bruxelles"), |
| 18 | + images=[ |
| 19 | + Image( |
| 20 | + file_name="image1.jpg", |
| 21 | + height=100, |
| 22 | + width=100, |
| 23 | + date_captured=datetime.now(), |
| 24 | + ), |
| 25 | + Image( |
| 26 | + file_name="image2.jpg", |
| 27 | + height=100, |
| 28 | + width=100, |
| 29 | + date_captured=datetime.now(), |
| 30 | + ), |
| 31 | + ], |
| 32 | + contributors=[contributor_base], |
| 33 | + ) |
| 34 | + return yarrow |
| 35 | + |
| 36 | + |
| 37 | +def test_create_multiple_annotations_with_same_attributes_expected_polygon_should_works( |
| 38 | + yarrow_base: YarrowDataset, contributor_base: Contributor |
| 39 | +): |
| 40 | + """In this test we make sure adding annotations with different polygon shape is working. |
| 41 | +
|
| 42 | + Args: |
| 43 | + yarrow (YarrowDataset): _description_ |
| 44 | + contributor (Contributor): _description_ |
| 45 | + """ |
| 46 | + # Given |
| 47 | + annotation_shape_23 = Annotation( |
| 48 | + contributor_base, |
| 49 | + name="chaussure", |
| 50 | + images=yarrow_base.images, |
| 51 | + polygon=np.zeros((23, 2)), |
| 52 | + ) |
| 53 | + annotation_shape_10 = Annotation( |
| 54 | + contributor_base, |
| 55 | + name="chaussure", |
| 56 | + images=yarrow_base.images, |
| 57 | + polygon=np.zeros((10, 2)), |
| 58 | + ) |
| 59 | + list_annotations = [annotation_shape_23, annotation_shape_10] |
| 60 | + |
| 61 | + # When |
| 62 | + yarrow_base.add_annotations(list_annotations) |
| 63 | + |
| 64 | + # Then |
| 65 | + assert np.asarray(yarrow_base.annotations[0].polygon).shape[0] == 23 |
| 66 | + assert np.asarray(yarrow_base.annotations[1].polygon).shape[0] == 10 |
0 commit comments