def test_to_inline_wrapper(self):
     truth = u'<span class="gloss">my</span> <span class="url">car</span> is blue.'  # noqa
     text = u'my car is blue.'
     wrappers = [{"start": 0, "end": 2, "type": "gloss"},
                 {"start": 3, "end": 6, "type": "url"}]
     inline = annotation_to_inline(text, None, wrappers)
     self.assertEqual(inline, truth)
 def test_to_inline_incomplete_markup_sanitize_end(self):
     truth = u'my car is <b>blue.'
     text = u'my car is blue.'
     markup = {10: [{'added_space': False,
                     'close_tid': 1,
                     'tag_type': 'open',
                     'text': u'<b>',
                     'tid': 0}]}
     inline = annotation_to_inline(text, markup, None)
     self.assertEqual(inline, truth)
 def test_to_inline_incomplete_markup_sanitize_begin(self):
     truth = u'my car is blue</b>.'
     text = u'my car is blue.'
     markup = {14: [{'added_space': False,
                     'open_tid': 0,
                     'tag_type': 'close',
                     'text': u'</b>',
                     'tid': 1}]}
     inline = annotation_to_inline(text, markup, None)
     self.assertEqual(inline, truth)
 def test_to_inline_wrapper_markup(self):
     truth = u'<span class="gloss">my</span> <span class="url">car</span> is <b>blue.'  # noqa
     text = u'my car is blue.'
     markup = {10: [{'added_space': False,
                     'close_tid': 1,
                     'tag_type': 'open',
                     'text': u'<b>',
                     'tid': 0}]}
     wrappers = [{"start": 0, "end": 2, "type": "gloss"},
                 {"start": 3, "end": 6, "type": "url"}]
     inline = annotation_to_inline(text,
                                   markup,
                                   wrappers)
     self.assertEqual(inline, truth)
 def test_to_inline_only_markup(self):
     truth = u'my car is <b>blue</b>.'
     text = u'my car is blue.'
     markup = {10: [{'added_space': False,
                     'close_tid': 1,
                     'tag_type': 'open',
                     'text': u'<b>',
                     'tid': 0}],
               14: [{'added_space': False,
                     'open_tid': 0,
                     'tag_type': 'close',
                     'text': u'</b>',
                     'tid': 1}]}
     inline = annotation_to_inline(text, markup, None)
     self.assertEqual(inline, truth)
    def test_example_file(self):
        from unbabel_text_utils.umtf_utils.wrappers_func import umtf_funcs_dict, \
            umtf_wrapper_funcs

        raw_file = codecs.open(
            get_data_dir()+"/inline_examples/examples.txt",
            encoding="utf-8").read()

        for i, line in enumerate(raw_file.split("\n")):
            with self.subTest(i=i):
                text, markup, wrappers = \
                    inline_to_annotation(line,
                                         umtf_wrapper_funcs,
                                         final_wrapper=get_wrappers)
                # print "I am doing in here...."

                new_inline = annotation_to_inline(
                    text,
                    markup,
                    wrappers,
                    wrappers_dict=umtf_funcs_dict)
                self.assertEqual(line, new_inline, "%i\nOrig: %s\nNext: %s\n" %
                                                   (i, line, new_inline))
 def test_to_inline_only_text(self):
     truth = u'my car is blue.'
     text = u'my car is blue.'
     inline = annotation_to_inline(text, None, None)
     self.assertEqual(inline, truth)