Beispiel #1
0
    def test_eol_preservation(self):

        # Tests input eol is kept after saving

        self.temp_eol_path = join(
            self.static_path, 'temp_eol_preserv.vtt')
        end_of_lines = ['\n', '\r', '\r\n']
        enc = 'utf-8'

        for eols in end_of_lines:
            input_eol = open(self.temp_eol_path, 'wb')
            input_eol.write(
                "00:01:00,000 --> 00:02:00,000"
                " {0} TestEOLPreservation + {0}".format(eols).encode())
            input_eol.close()

            input_file = open(self.temp_eol_path, 'rU', encoding=enc)
            input_file.read()
            self.assertEqual(eols, input_file.newlines)

            vtt_file = vttopen(self.temp_eol_path, encoding=enc)
            vtt_file.save(self.temp_eol_path, eol=input_file.newlines)

            output_file = open(self.temp_eol_path, 'rU', encoding=enc)
            output_file.read()
            self.assertEqual(output_file.newlines, input_file.newlines)

            remove(self.temp_eol_path)
Beispiel #2
0
    def test_eol_preservation(self):

        # Tests input eol is kept after saving

        self.temp_eol_path = os.path.join(self.static_path,
                                          'temp_eol_preserv.vtt')
        end_of_lines = ['\n', '\r', '\r\n']
        enc = 'utf-8'

        for eols in end_of_lines:
            input_eol = open(self.temp_eol_path, 'wb')
            input_eol.write(
                str('00:01:00,000 --> 00:02:00,000' + eols +
                    'TestEOLPreservation' + eols))
            input_eol.close()

            input_file = open(self.temp_eol_path, 'rU', encoding=enc)
            input_file.read()
            self.assertEqual(eols, input_file.newlines)

            vtt_file = pyvtt.open(self.temp_eol_path, encoding=enc)
            vtt_file.save(self.temp_eol_path, eol=input_file.newlines)

            output_file = open(self.temp_eol_path, 'rU', encoding=enc)
            output_file.read()
            self.assertEqual(output_file.newlines, input_file.newlines)

            os.remove(self.temp_eol_path)
Beispiel #3
0
    def test_eol_preservation(self):

        # Tests input eol is kept after saving

        self.temp_eol_path = join(self.static_path, 'temp_eol_preserv.vtt')
        end_of_lines = ['\n', '\r', '\r\n']
        enc = 'utf-8'

        for eols in end_of_lines:
            input_eol = open(self.temp_eol_path, 'wb')
            input_eol.write(
                "00:01:00,000 --> 00:02:00,000"
                " {0} TestEOLPreservation + {0}".format(eols).encode())
            input_eol.close()

            input_file = open(self.temp_eol_path, 'rU', encoding=enc)
            input_file.read()
            self.assertEqual(eols, input_file.newlines)

            vtt_file = vttopen(self.temp_eol_path, encoding=enc)
            vtt_file.save(self.temp_eol_path, eol=input_file.newlines)

            output_file = open(self.temp_eol_path, 'rU', encoding=enc)
            output_file.read()
            self.assertEqual(output_file.newlines, input_file.newlines)

            remove(self.temp_eol_path)
Beispiel #4
0
    def test_eol_conversion(self):
        input_file = open(self.windows_path, 'rU', encoding='windows-1252')
        input_file.read()
        self.assertEqual(input_file.newlines, '\r\n')

        vtt_file = pyvtt.open(self.windows_path, encoding='windows-1252')
        vtt_file.save(self.temp_path, eol='\n')

        output_file = open(self.temp_path, 'rU', encoding='windows-1252')
        output_file.read()
        self.assertEqual(output_file.newlines, '\n')
Beispiel #5
0
    def test_eol_conversion(self):
        input_file = open(self.windows_path, 'rU', encoding='windows-1252')
        input_file.read()
        self.assertEqual(input_file.newlines, '\r\n')

        vtt_file = pyvtt.open(self.windows_path, encoding='windows-1252')
        vtt_file.save(self.temp_path, eol='\n')

        output_file = open(self.temp_path, 'rU', encoding='windows-1252')
        output_file.read()
        self.assertEqual(output_file.newlines, '\n')
Beispiel #6
0
 def test_save_with_indexes(self):
     file = pyvtt.open(os.path.join(self.static_path, 'no-indexes.srt'))
     file.clean_indexes()
     file_with_indexes = os.path.join(file_path, 'tests', 'vtt_test',
                                      'file_with_indexes.vtt')
     file_with_indexes_target_path = os.path.join(
         file_path, 'tests', 'vtt_test', 'file_with_indexes_target.vtt')
     file.save(file_with_indexes_target_path, include_indexes=True)
     self.assertEqual(
         bytes(open(file_with_indexes, 'rb').read()),
         bytes(open(file_with_indexes_target_path, 'rb').read()))
     os.remove(file_with_indexes_target_path)
Beispiel #7
0
 def test_save_with_indexes(self):
     file = vttopen(join(self.static_path, 'no-indexes.srt'))
     file.clean_indexes()
     file_with_indexes = join(
         file_path, 'tests', 'vtt_test', 'file_with_indexes.vtt')
     file_with_indexes_target_path = join(
         file_path, 'tests', 'vtt_test', 'file_with_indexes_target.vtt')
     file.save(file_with_indexes_target_path, include_indexes=True)
     self.assertEqual(
         bytes(open(file_with_indexes, 'rb').read()),
         bytes(open(file_with_indexes_target_path, 'rb').read()))
     remove(file_with_indexes_target_path)
Beispiel #8
0
    def test_save_overwrite(self):
        overwrite_source_path1 = join(
            file_path, 'tests', 'vtt_test', 'overwrite_source1.vtt')
        overwrite_source_path2 = join(
            file_path, 'tests', 'vtt_test', 'overwrite_source2.vtt')
        overwrite_target_path = join(
            file_path, 'tests', 'vtt_test', 'overwrite_target.vtt')

        vtt_file1 = vttopen(overwrite_source_path1, encoding='utf-8')
        vtt_file1.save(overwrite_target_path, eol=vtt_file1._eol,
                       encoding=vtt_file1.encoding)
        self.assertEqual(bytes(open(overwrite_source_path1, 'rb').read()),
                         bytes(open(overwrite_target_path, 'rb').read()))

        vtt_file2 = vttopen(overwrite_source_path2, encoding='utf-8')
        vtt_file2.save(overwrite_target_path, eol=vtt_file2._eol,
                       encoding=vtt_file2.encoding)
        self.assertEqual(bytes(open(overwrite_source_path2, 'rb').read()),
                         bytes(open(overwrite_target_path, 'rb').read()))

        remove(overwrite_target_path)
Beispiel #9
0
    def test_save_overwrite(self):
        overwrite_source_path1 = os.path.join(file_path, 'tests', 'vtt_test',
                                              'overwrite_source1.vtt')
        overwrite_source_path2 = os.path.join(file_path, 'tests', 'vtt_test',
                                              'overwrite_source2.vtt')
        overwrite_target_path = os.path.join(file_path, 'tests', 'vtt_test',
                                             'overwrite_target.vtt')

        vtt_file1 = pyvtt.open(overwrite_source_path1, encoding='utf-8')
        vtt_file1.save(overwrite_target_path,
                       eol=vtt_file1._eol,
                       encoding=vtt_file1.encoding)
        self.assertEqual(bytes(open(overwrite_source_path1, 'rb').read()),
                         bytes(open(overwrite_target_path, 'rb').read()))

        vtt_file2 = pyvtt.open(overwrite_source_path2, encoding='utf-8')
        vtt_file2.save(overwrite_target_path,
                       eol=vtt_file2._eol,
                       encoding=vtt_file2.encoding)
        self.assertEqual(bytes(open(overwrite_source_path2, 'rb').read()),
                         bytes(open(overwrite_target_path, 'rb').read()))

        os.remove(overwrite_target_path)
Beispiel #10
0
 def test_save(self):
     vtt_file = pyvtt.open(self.windows_path, encoding='windows-1252')
     vtt_file.save(self.temp_path, eol='\n', encoding='utf-8')
     self.assertEqual(bytes(open(self.temp_path, 'rb').read()),
                      bytes(open(self.utf8_path, 'rb').read()))
     os.remove(self.temp_path)
Beispiel #11
0
 def test_utf8(self):
     unicode_content = codecs.open(self.utf8_path, encoding='utf_8').read()
     self.assertEqual(len(pyvtt.from_string(unicode_content)), 1332)
     self.assertRaises(UnicodeDecodeError, open(self.windows_path).read)
Beispiel #12
0
 def test_utf8(self):
     unicode_content = codecs.open(self.utf8_path, encoding='utf_8').read()
     self.assertEqual(len(pyvtt.from_string(unicode_content)), 1332)
     self.assertRaises(UnicodeDecodeError, open(self.windows_path).read)
Beispiel #13
0
 def test_save_new_eol_and_encoding(self):
     vtt_file = pyvtt.open(self.windows_path, encoding='windows-1252')
     vtt_file.save(self.temp_path, eol='\n', encoding='utf-8')
     self.assertEqual(bytes(open(self.temp_path, 'rb').read()),
                      bytes(open(self.utf8_path, 'rb').read()))
     os.remove(self.temp_path)