def test_annotation_array_serialize(tag_data): namespace = 'tag_open' ann = jams.Annotation(namespace, data=tag_data) arr = jams.AnnotationArray(annotations=[ann, ann]) arr_js = arr.__json__ arr2 = jams.AnnotationArray(annotations=arr_js) assert arr == arr2
def test_jams(): data = dict(time=[0.0, 1.0], duration=[0.5, 0.5], value=['one', 'two'], confidence=[0.9, 0.9]) real_ann = jams.AnnotationArray( annotations=[jams.Annotation('tag_open', data=data)]) meta = dict(title='Test track', artist='Test artist', release='Test release', duration=31.3) real_fm = jams.FileMetadata(**meta) real_sandbox = jams.Sandbox(description='none') def __test(annotations, file_metadata, sandbox): jam = jams.JAMS(annotations=annotations, file_metadata=file_metadata, sandbox=sandbox) if file_metadata is not None: eq_(dict(file_metadata), dict(jam.file_metadata)) if sandbox is not None: eq_(dict(sandbox), dict(jam.sandbox)) if annotations is not None: eq_(annotations, jam.annotations) for ann in [None, real_ann]: for fm in [None, real_fm]: for sandbox in [None, real_sandbox]: yield __test, ann, fm, sandbox
def test_annotation_array_serialize(): data = dict(time=[0.0, 1.0], duration=[0.5, 0.5], value=['one', 'two'], confidence=[0.9, 0.9]) namespace = 'tag_open' ann = jams.Annotation(namespace, data=data) arr = jams.AnnotationArray(annotations=[ann, ann]) arr_js = arr.__json__ arr2 = jams.AnnotationArray(annotations=arr_js) eq_(arr, arr2)
def test_jams(tag_data, file_metadata, ann_sandbox): ann = jams.Annotation('tag_open', data=tag_data) annotations = jams.AnnotationArray(annotations=[ann]) jam = jams.JAMS(annotations=annotations, file_metadata=file_metadata, sandbox=ann_sandbox) assert dict(file_metadata) == dict(jam.file_metadata) assert dict(ann_sandbox) == dict(jam.sandbox) assert annotations == jam.annotations
def test_annotation_array_data(tag_data): ann = jams.Annotation('tag_open', data=tag_data) arr = jams.AnnotationArray(annotations=[ann, ann]) assert len(arr) == 2 arr.append(ann) assert len(arr) == 3 for t_ann in arr: assert ann.data == t_ann.data
def test_annotation_array_data(): data = dict(time=[0.0, 1.0], duration=[0.5, 0.5], value=['one', 'two'], confidence=[0.9, 0.9]) ann = jams.Annotation('tag_open', data=data) arr = jams.AnnotationArray(annotations=[ann, ann]) eq_(len(arr), 2) arr.append(ann) eq_(len(arr), 3) for t_ann in arr: assert ann.data.equals(t_ann.data)
def test_jams_search(): def __test(jam, query, expected): result = jam.search(**query) eq_(result, expected) fn = 'fixtures/valid.jams' jam = jams.load(fn) yield __test, jam, dict(corpus='SMC_MIREX'), jam.annotations yield __test, jam, dict(), [] yield __test, jam, dict(namespace='beat'), jam.annotations[0:1] yield __test, jam, dict(namespace='tag_open'), jam.annotations[1:] yield __test, jam, dict(namespace='segment_tut'), jams.AnnotationArray() yield __test, jam.file_metadata, dict(duration=40.0), True yield __test, jam.file_metadata, dict(duration=39.0), False
def test_jams_add(tag_data): fn = 'tests/fixtures/valid.jams' # The original jam jam_orig = jams.load(fn) jam = jams.load(fn) # Make a new jam with the same metadata and different data jam2 = jams.load(fn) ann = jams.Annotation('tag_open', data=tag_data) jam2.annotations = jams.AnnotationArray(annotations=[ann]) # Add the two jam.add(jam2) assert len(jam.annotations) == 3 assert jam.annotations[:-1] == jam_orig.annotations assert jam.annotations[-1] == jam2.annotations[0]
def __test(): fn = 'fixtures/valid.jams' # The original jam jam_orig = jams.load(fn) jam = jams.load(fn) # Make a new jam with the same metadata and different data jam2 = jams.load(fn) data = dict(time=[0.0, 1.0], duration=[0.5, 0.5], value=['one', 'two'], confidence=[0.9, 0.9]) ann = jams.Annotation('tag_open', data=data) jam2.annotations = jams.AnnotationArray(annotations=[ann]) # Add the two jam.add(jam2) eq_(len(jam.annotations), 3) eq_(jam.annotations[:-1], jam_orig.annotations) eq_(jam.annotations[-1], jam2.annotations[0])
def test_annotation_array(): arr = jams.AnnotationArray() assert len(arr) == 0
assert jam.file_metadata == jam_orig.file_metadata @pytest.fixture(scope='module') def jam_search(): jam = jams.load('tests/fixtures/valid.jams', validate=False) jam.annotations[0].sandbox.foo = None return jam @parametrize('query, expected', [(dict(corpus='SMC_MIREX'), jam_search().annotations), (dict(), []), (dict(namespace='beat'), jam_search().annotations[:1]), (dict(namespace='tag_open'), jam_search().annotations[1:]), (dict(namespace='segment_tut'), jams.AnnotationArray()), (dict(foo='bar'), jams.AnnotationArray())]) def test_jams_search(jam_search, query, expected): result = jam_search.search(**query) assert result == expected def test_jams_validate_good(): fn = 'tests/fixtures/valid.jams' j1 = jams.load(fn, validate=False) j1.validate()
def test_display_multi_fail(): anns = jams.AnnotationArray() jams.display.display_multi(anns)
def test_annotation_array(): arr = jams.AnnotationArray() eq_(len(arr), 0)