Source code for intent.tests.meta_tests

from unittest import TestCase

from intent.consts import DATA_PROV, DATA_SRC_ATTR, INTENT_META_SOURCE, DATA_METH_ATTR, INTENT_ALN_GIZA, \
    WORDS_TYPE, GLOSS_WORD_TYPE, INTENT_GLOSS_WORD, INTENT_GLOSS_MORPH
from intent.igt.create_tiers import is_word_level_gloss
from intent.igt.metadata import set_meta_attr, find_meta, find_meta_attr, get_meta_timestamp, timestamp_meta, is_contentful_meta, \
    del_meta_attr, add_word_level_info
from xigt import Meta, Metadata, Tier, Igt

__author__ = 'rgeorgi'

[docs]class ProvenanceTest(TestCase):
[docs] def setUp(self): self.t = Tier(id='t') self.metadata = []
[docs] def add_meta_test(self): set_meta_attr(self.t, DATA_PROV, DATA_SRC_ATTR, INTENT_META_SOURCE) set_meta_attr(self.t, DATA_PROV, DATA_METH_ATTR, INTENT_ALN_GIZA) self.assertEqual(find_meta_attr(self.t, DATA_PROV, DATA_METH_ATTR), INTENT_ALN_GIZA) self.assertEqual(find_meta_attr(self.t, DATA_PROV, DATA_SRC_ATTR), INTENT_META_SOURCE) self.assertEqual(len(self.t.metadata), 1) self.assertEqual(len(self.t.metadata[0].metas), 1)
[docs] def timestamp_test(self): set_meta_attr(self.t, DATA_PROV, DATA_SRC_ATTR, INTENT_META_SOURCE) self.assertIsNotNone(get_meta_timestamp(find_meta(self.t, DATA_PROV)))
[docs]class WordTypeTest(TestCase):
[docs] def setUp(self): self.i = Igt(id='i1') self.w = Tier(id='w', type=WORDS_TYPE) self.gw =Tier(id='gw', type=GLOSS_WORD_TYPE, alignment=self.w.id) self.i.extend([self.w, self.gw])
[docs] def test_wo_metadata(self): self.assertTrue(is_word_level_gloss(self.gw))
[docs] def test_w_metadata(self): self.gw.alignment = None self.assertFalse(is_word_level_gloss(self.gw)) add_word_level_info(self.gw, INTENT_GLOSS_WORD) self.assertTrue(is_word_level_gloss(self.gw)) add_word_level_info(self.gw, INTENT_GLOSS_MORPH) self.assertFalse(is_word_level_gloss(self.gw))
[docs]class ContentfulMeta(TestCase):
[docs] def setUp(self): self.m1 = Meta(text='Something') self.m2 = Meta(attributes={'Something':'test'}) self.m3 = Meta() timestamp_meta(self.m3) self.m4 = Meta()
[docs] def content_test(self): self.assertTrue(is_contentful_meta(self.m1)) self.assertTrue(is_contentful_meta(self.m2)) self.assertFalse(is_contentful_meta(self.m3)) self.assertFalse(is_contentful_meta(self.m4))
[docs]class DelMetaTests(TestCase):
[docs] def setUp(self): self.t = Tier() self.md = Metadata() self.t.metadata = [self.md] self.m1 = Meta(text='foo') self.m2 = Meta(type='foobar', attributes={'foo':'bar'})
[docs] def no_meta_remains_test(self): self.md.append(self.m2) self.assertEqual(len(self.t.metadata), 1) self.assertEqual(len(self.md), 1) del_meta_attr(self.t, 'foobar', 'foo') self.assertEqual(len(self.md), 0) self.assertEqual(len(self.t.metadata), 0)
[docs] def meta_remains_test(self): self.md.append(self.m1) self.md.append(self.m2) self.assertEqual(len(self.t.metadata), 1) self.assertEqual(len(self.md), 2) del_meta_attr(self.t, 'foobar', 'foo') self.assertEqual(len(self.t.metadata), 1)