本文整理汇总了Python中pysrt.SubRipItem.shift方法的典型用法代码示例。如果您正苦于以下问题:Python SubRipItem.shift方法的具体用法?Python SubRipItem.shift怎么用?Python SubRipItem.shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysrt.SubRipItem
的用法示例。
在下文中一共展示了SubRipItem.shift方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTagRemoval
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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.')
示例2: TestShifting
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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)
示例3: TestSerialAndParsing
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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 !')
示例4: TestOperators
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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)
示例5: TestDuration
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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))
示例6: TestCPS
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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)
示例7: TestCPS
# 需要导入模块: from pysrt import SubRipItem [as 别名]
# 或者: from pysrt.SubRipItem import shift [as 别名]
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)