Esempio n. 1
0
class TestTagRemoval(TestCase):

    def setUp(self):
        self.item = WebVTTItem(1, text='Hello world !')
        self.item.shift(minutes=1)
        self.item.end.shift(seconds=20)

    def test_italics_tag(self):
        self.item.text = '<i>Hello world !</i>'
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_bold_tag(self):
        self.item.text = '<b>Hello world !</b>'
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_underline_tag(self):
        self.item.text = '<u>Hello world !</u>'
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_color_tag(self):
        self.item.text = '<font color="#ff0000">Hello world !</font>'
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_tag_as_text(self):
        self.item.text = '<This is not a tag>'
        self.assertEqual(self.item.text_without_tags, 'This is not a tag')

    def test_split_tag_as_text(self):
        self.item.text = '<This is\n not a tag>'
        self.assertEqual(self.item.text_without_tags, 'This is\n not a tag')

    def test_all_tags(self):
        self.item.text = '<b>Bold</b>, <i>italic</i>, <u>underlined</u>\n' + \
                         '<font color="#ff0000">red text</font>' + \
                         ', <b>one,<i> two,<u> three</u></i></b>.'
        self.assertEqual(
            self.item.text_without_tags,
            'Bold, italic, underlined\nred text, one, two, three.')

    def test_bracket_tag(self):
        self.item.text = '[b]Hello world ![/b]'
        self.assertEqual(self.item.text_without_brackets, 'Hello world !')

    def test_key_tag(self):
        self.item.text = '{b}Hello world !{/b}'
        self.assertEqual(self.item.text_without_keys, 'Hello world !')

    def test_replacements(self):
        self.item.text = 'P & G, A + B'
        self.assertEqual(
            self.item.text_with_replacements([('&', 'and'), ('+', 'plus')]),
            'P and G, A plus B')

    def test_regex_eplacements(self):
        self.item.text = '\\tag21 This is a test!'
        self.assertEqual(
            self.item.text_with_replacements([(compile(r'\\tag\d+ '), '')]),
            'This is a test!')
Esempio n. 2
0
class TestTagRemoval(unittest.TestCase):
    def setUp(self):
        self.item = WebVTTItem(1, text="Hello world !")
        self.item.shift(minutes=1)
        self.item.end.shift(seconds=20)

    def test_italics_tag(self):
        self.item.text = "<i>Hello world !</i>"
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_bold_tag(self):
        self.item.text = "<b>Hello world !</b>"
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_underline_tag(self):
        self.item.text = "<u>Hello world !</u>"
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_color_tag(self):
        self.item.text = '<font color="#ff0000">Hello world !</font>'
        self.assertEqual(self.item.text_without_tags, 'Hello world !')

    def test_all_tags(self):
        self.item.text = '<b>Bold</b>, <i>italic</i>, <u>underlined</u>\n' + \
        '<font color="#ff0000">red text</font>' + \
        ', <b>one,<i> two,<u> three</u></i></b>.'
        self.assertEqual(self.item.text_without_tags,'Bold, italic, underlined' + \
                '\nred text, one, two, three.')

    def test_bracket_tag(self):
        self.item.text = "[b]Hello world ![/b]"
        self.assertEqual(self.item.text_without_brackets, 'Hello world !')

    def test_key_tag(self):
        self.item.text = "{b}Hello world !{/b}"
        self.assertEqual(self.item.text_without_keys, 'Hello world !')

    def test_replacements(self):
        self.item.text = "P & G, A + B"
        self.assertEqual(
            self.item.text_with_replacements({
                '&': 'and',
                '+': 'plus'
            }), 'P and G, A plus B')