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') srt_file = pysrt.open(self.windows_path, encoding='windows-1252') srt_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')
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") srt_file = pysrt.open(self.windows_path, encoding="windows-1252") srt_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")
def test_save(self): srt_file = pysrt.open(self.windows_path, encoding='windows-1252') srt_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)
def test_utf8(self): unicode_content = codecs.open(self.utf8_path, encoding='utf_8').read() self.assertEqual(len(pysrt.from_string(unicode_content)), 1332) self.assertRaises(UnicodeDecodeError, open(self.windows_path).read)
def test_save(self): srt_file = pysrt.open(self.windows_path, encoding="windows-1252") srt_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)
def test_utf8(self): unicode_content = codecs.open(self.utf8_path, encoding="utf_8").read() self.assertEqual(len(pysrt.from_string(unicode_content)), 1332) self.assertRaises(UnicodeDecodeError, open(self.windows_path).read)