• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pysrt.SubRipItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pysrt.SubRipItem的典型用法代码示例。如果您正苦于以下问题:Python SubRipItem类的具体用法?Python SubRipItem怎么用?Python SubRipItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SubRipItem类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: TestShifting

class TestShifting(unittest.TestCase):

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

    def test_shift_up(self):
        self.item.shift(1, 2, 3, 4)
        self.assertEqual(self.item.start, (1, 3, 3, 4))
        self.assertEqual(self.item.end, (1, 3, 23, 4))
        self.assertEqual(self.item.duration, (0, 0, 20, 0))
        self.assertEqual(self.item.characters_per_second, 0.65)

    def test_shift_down(self):
        self.item.shift(5)
        self.item.shift(-1, -2, -3, -4)
        self.assertEqual(self.item.start, (3, 58, 56, 996))
        self.assertEqual(self.item.end, (3, 59, 16, 996))
        self.assertEqual(self.item.duration, (0, 0, 20, 0))
        self.assertEqual(self.item.characters_per_second, 0.65)

    def test_shift_by_ratio(self):
        self.item.shift(ratio=2)
        self.assertEqual(self.item.start, {'minutes': 2})
        self.assertEqual(self.item.end, {'minutes': 2, 'seconds': 40})
        self.assertEqual(self.item.duration, (0, 0, 40, 0))
        self.assertEqual(self.item.characters_per_second, 0.325)
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:28,代码来源:test_srtitem.py


示例2: TestTagRemoval

class TestTagRemoval(unittest.TestCase):

    def setUp(self):
        self.item = SubRipItem(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.')
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:29,代码来源:test_srtitem.py


示例3: TestSerialAndParsing

class TestSerialAndParsing(unittest.TestCase):

    def setUp(self):
        self.item = SubRipItem(1, text="Hello world !")
        self.item.shift(minutes=1)
        self.item.end.shift(seconds=20)
        self.string = u'1\n00:01:00,000 --> 00:01:20,000\nHello world !\n'
        self.bad_string = u'foobar'
        self.coordinates = (u'1\n00:01:00,000 --> 00:01:20,000 X1:000 X2:000 '
                                'Y1:050 Y2:100\nHello world !\n')
        self.vtt = (u'1\n00:01:00,000 --> 00:01:20,000 D:vertical A:start '
                                'L:12%\nHello world !\n')
        self.dots = u'1\n00:01:00.000 --> 00:01:20.000\nHello world !\n'
        self.string_index = u'foo\n00:01:00,000 --> 00:01:20,000\nHello !\n'
        self.no_index = u'00:01:00,000 --> 00:01:20,000\nHello world !\n'

    def test_serialization(self):
        self.assertEqual(unicode(self.item), self.string)

    def test_from_string(self):
        self.assertEquals(SubRipItem.from_string(self.string), self.item)
        self.assertRaises(InvalidItem, SubRipItem.from_string,
            self.bad_string)

    def test_coordinates(self):
        item = SubRipItem.from_string(self.coordinates)
        self.assertEquals(item, self.item)
        self.assertEquals(item.position, 'X1:000 X2:000 Y1:050 Y2:100')

    def test_vtt_positioning(self):
        vtt = SubRipItem.from_string(self.vtt)
        self.assertEquals(vtt.position, 'D:vertical A:start L:12%')
        self.assertEquals(vtt.index, 1)
        self.assertEquals(vtt.text, 'Hello world !')

    def test_idempotence(self):
        vtt = SubRipItem.from_string(self.vtt)
        self.assertEquals(unicode(vtt), self.vtt)
        item = SubRipItem.from_string(self.coordinates)
        self.assertEquals(unicode(item), self.coordinates)

    def test_dots(self):
        self.assertEquals(SubRipItem.from_string(self.dots), self.item)

    # Bug reported in https://github.com/byroot/pysrt/issues/16
    def test_paring_error(self):
        self.assertRaises(InvalidItem, SubRipItem.from_string, u'1\n'
            '00:01:00,000 -> 00:01:20,000 X1:000 X2:000 '
            'Y1:050 Y2:100\nHello world !\n')

    def test_string_index(self):
        item = SubRipItem.from_string(self.string_index)
        self.assertEquals(item.index, 'foo')
        self.assertEquals(item.text, 'Hello !')

    def test_no_index(self):
        item = SubRipItem.from_string(self.no_index)
        self.assertEquals(item.index, None)
        self.assertEquals(item.text, 'Hello world !')
开发者ID:MestreLion,项目名称:pysrt,代码行数:59,代码来源:test_srtitem.py


示例4: TestOperators

class TestOperators(unittest.TestCase):

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

    def test_cmp(self):
        self.assertEquals(self.item, self.item)
开发者ID:GunioRobot,项目名称:pysrt,代码行数:9,代码来源:test_srtitem.py


示例5: TestDuration

class TestDuration(unittest.TestCase):

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

    def test_duration(self):
        self.assertEqual(self.item.duration, (0, 0, 20, 0))
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:9,代码来源:test_srtitem.py


示例6: TestCPS

class TestCPS(unittest.TestCase):

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

    def test_characters_per_second(self):
        self.assertEqual(self.item.characters_per_second, 0.65)

    def test_text_change(self):
        self.item.text = "Hello world !\nHello world again !"
        self.assertEqual(self.item.characters_per_second, 1.6)
开发者ID:imclab,项目名称:pysrt,代码行数:13,代码来源:test_srtitem.py


示例7: setUp

    def setUp(self):
        original = """77777777 333 1
55555 55555
4444 4444
22 22 22"""
        self.item = SubRipItem(1, text=original)
        self.item.break_lines(5)
开发者ID:limpbrains,项目名称:pysrt,代码行数:7,代码来源:test_srtitem.py


示例8: TestBreakingLines

class TestBreakingLines(unittest.TestCase):

    def setUp(self):
        original = """77777777 333 1
55555 55555
4444 4444
22 22 22"""
        self.item = SubRipItem(1, text=original)
        self.item.break_lines(5)

    def test_break(self):
        shouldbe = """77777777
333 1
55555
55555
4444
4444
22 22
22"""
        self.assertEqual(shouldbe, self.item.text)
开发者ID:limpbrains,项目名称:pysrt,代码行数:20,代码来源:test_srtitem.py


示例9: setUp

 def setUp(self):
     self.item = SubRipItem(1, text="Hello world !")
     self.item.shift(minutes=1)
     self.item.end.shift(seconds=20)
     self.string = u'1\n00:01:00,000 --> 00:01:20,000\nHello world !\n'
     self.bad_string = u'foobar'
     self.coordinates = (u'1\n00:01:00,000 --> 00:01:20,000 X1:000 X2:000 '
                             'Y1:050 Y2:100\nHello world !\n')
     self.vtt = (u'1\n00:01:00,000 --> 00:01:20,000 D:vertical A:start '
                             'L:12%\nHello world !\n')
     self.dots = u'1\n00:01:00.000 --> 00:01:20.000\nHello world !\n'
开发者ID:GunioRobot,项目名称:pysrt,代码行数:11,代码来源:test_srtitem.py


示例10: TestCPS

class TestCPS(unittest.TestCase):

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

    def test_characters_per_second(self):
        self.assertEqual(self.item.characters_per_second, 0.65)

    def test_text_change(self):
        self.item.text = "Hello world !\nHello world again !"
        self.assertEqual(self.item.characters_per_second, 1.6)

    def test_zero_duration(self):
        self.item.start.shift(seconds = 20)
        self.assertEqual(self.item.characters_per_second, 0.0)

    def test_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.characters_per_second, 2.45)
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:23,代码来源:test_srtitem.py


示例11: setUp

 def setUp(self):
     self.item = SubRipItem(1, text="Hello world !")
     self.item.shift(minutes=1)
     self.item.end.shift(seconds=20)
     self.string = '1\n00:01:00,000 --> 00:01:20,000\nHello world !\n'
     self.bad_string = 'foobar'
     self.coordinates = ('1\n00:01:00,000 --> 00:01:20,000 X1:000 X2:000 '
                             'Y1:050 Y2:100\nHello world !\n')
     self.vtt = ('1\n00:01:00,000 --> 00:01:20,000 D:vertical A:start '
                             'L:12%\nHello world !\n')
     self.string_index = 'foo\n00:01:00,000 --> 00:01:20,000\nHello !\n'
     self.dots = '1\n00:01:00.000 --> 00:01:20.000\nHello world !\n'
     self.no_index = '00:01:00,000 --> 00:01:20,000\nHello world !\n'
     self.junk_after_timestamp = ('1\n00:01:00,000 --> 00:01:20,000?\n'
                             'Hello world !\n')
开发者ID:EdwardBetts,项目名称:pysrt,代码行数:15,代码来源:test_srtitem.py


示例12: test_dots

 def test_dots(self):
     self.assertEquals(SubRipItem.from_string(self.dots), self.item)
开发者ID:GunioRobot,项目名称:pysrt,代码行数:2,代码来源:test_srtitem.py


示例13: test_idempotence

 def test_idempotence(self):
     vtt = SubRipItem.from_string(self.vtt)
     self.assertEquals(unicode(vtt), self.vtt)
     item = SubRipItem.from_string(self.coordinates)
     self.assertEquals(unicode(item), self.coordinates)
开发者ID:GunioRobot,项目名称:pysrt,代码行数:5,代码来源:test_srtitem.py


示例14: test_junk_after_timestamp

 def test_junk_after_timestamp(self):
     item = SubRipItem.from_string(self.junk_after_timestamp)
     self.assertEquals(item, self.item)
开发者ID:maksbotan,项目名称:pysrt,代码行数:3,代码来源:test_srtitem.py


示例15: test_coordinates

 def test_coordinates(self):
     item = SubRipItem.from_string(self.coordinates)
     self.assertEquals(item, self.item)
     self.assertEquals(item.position, 'X1:000 X2:000 Y1:050 Y2:100')
开发者ID:GunioRobot,项目名称:pysrt,代码行数:4,代码来源:test_srtitem.py


示例16: test_from_string

 def test_from_string(self):
     self.assertEquals(SubRipItem.from_string(self.string), self.item)
     self.assertRaises(InvalidItem, SubRipItem.from_string,
         self.bad_string)
开发者ID:GunioRobot,项目名称:pysrt,代码行数:4,代码来源:test_srtitem.py


示例17: test_string_index

 def test_string_index(self):
     item = SubRipItem.from_string(self.string_index)
     self.assertEquals(item.index, 'foo')
     self.assertEquals(item.text, 'Hello !')
开发者ID:maksbotan,项目名称:pysrt,代码行数:4,代码来源:test_srtitem.py


示例18: test_vtt_positioning

 def test_vtt_positioning(self):
     vtt = SubRipItem.from_string(self.vtt)
     self.assertEquals(vtt.position, 'D:vertical A:start L:12%')
     self.assertEquals(vtt.index, 1)
     self.assertEquals(vtt.text, 'Hello world !')
开发者ID:GunioRobot,项目名称:pysrt,代码行数:5,代码来源:test_srtitem.py


示例19: test_no_index

 def test_no_index(self):
     item = SubRipItem.from_string(self.no_index)
     self.assertEquals(item.index, None)
     self.assertEquals(item.text, 'Hello world !')
开发者ID:maksbotan,项目名称:pysrt,代码行数:4,代码来源:test_srtitem.py



注:本文中的pysrt.SubRipItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pystache.parse函数代码示例发布时间:2022-05-27
下一篇:
Python pysrt.SubRipFile类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap