本文整理汇总了Python中pysrt.SubRipItem类的典型用法代码示例。如果您正苦于以下问题:Python SubRipItem类的具体用法?Python SubRipItem怎么用?Python SubRipItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubRipItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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.')
示例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 !')
示例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)
示例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))
示例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)
示例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)
示例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)
示例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'
示例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)
示例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')
示例12: test_dots
def test_dots(self):
self.assertEquals(SubRipItem.from_string(self.dots), self.item)
示例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)
示例14: test_junk_after_timestamp
def test_junk_after_timestamp(self):
item = SubRipItem.from_string(self.junk_after_timestamp)
self.assertEquals(item, self.item)
示例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')