2022-06-10 20:28:36 +02:00
import json
2022-03-26 09:32:30 +01:00
import os
2022-06-10 20:28:36 +02:00
import platform
2022-03-26 09:32:30 +01:00
import svtplay_dl . subtitle
from svtplay_dl . utils . parser import setup_defaults
def parse ( subfile ) :
with open ( os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , " subtitle " , subfile ) , encoding = " utf8 " ) as fd :
data = fd . read ( )
return data
2022-06-10 20:28:36 +02:00
def parse2 ( subfile ) :
encoding = None
if platform . system ( ) == " Windows " :
encoding = " utf8 "
with open ( os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , " subtitle " , subfile ) , encoding = encoding ) as fd :
data = fd . read ( )
return data
2022-03-26 09:32:30 +01:00
def test_wsrt_old ( ) :
data = parse ( " wsrt-old.srt " )
subtitle = svtplay_dl . subtitle . subtitle ( setup_defaults ( ) , " " , " " )
assert subtitle . _wrst ( data ) == " 1 \n 01:23:45,678 --> 01:23:46,789 \n Hello world! \n \n 2 \n 01:23:48,910 --> 01:23:49,101 \n Hello \n world! \n "
def test_wsrt_pretext ( ) :
data = parse ( " wsrt-pretext.srt " )
subtitle = svtplay_dl . subtitle . subtitle ( setup_defaults ( ) , " " , " " )
assert (
subtitle . _wrst ( data )
== " 1 \n 00:00:10,040 --> 00:00:12,520 \n Nån försökte slå ihjäl mig. \n \n 2 \n 00:00:12,600 --> 00:00:16,200 \n -Var fan har du varit? \n -Vad? \n "
)
def test_wsrt_style_hash ( ) :
data = parse ( " wsrt-style-hash.srt " )
subtitle = svtplay_dl . subtitle . subtitle ( setup_defaults ( ) , " " , " " )
assert (
subtitle . _wrst ( data )
== " 1 \n 00:00:06,360 --> 00:00:10,080 \n 1845 gav sig \n en brittisk expedition ut- \n \n 2 \n 00:00:10,240 --> 00:00:15,040 \n -för att söka ett av forsknings- \n resornas mest eftertraktade mål: \n "
)
2022-06-10 20:28:36 +02:00
def test_wrst_segment ( ) :
dataj = json . loads ( parse ( " wsrt-segments.json " ) )
data = parse2 ( " wrst-correct.srt " ) + " \n " # last \n to fix UT with extra new line
assert svtplay_dl . subtitle . _wrstsegments ( dataj ) == data
def test_wrst_segment2 ( ) :
dataj = json . loads ( parse ( " wsrt-segments-2.json " ) )
data = parse2 ( " wrst-correct-2.srt " ) + " \n " # last \n to fix UT with extra new line
assert svtplay_dl . subtitle . _wrstsegments ( dataj ) == data