fsub/tests/integration.py

76 lines
2.2 KiB
Python
Raw Normal View History

2021-11-15 14:58:23 -05:00
import unittest
import src.fsub.fsub as fsub
import shutil
import os
import inspect
from pathlib import Path
class TestFsub(unittest.TestCase):
samples = Path('tests/samples')
2021-11-15 16:14:33 -05:00
def run_on(self, args, samples, ofiles):
caller = inspect.stack()[1][3]
ifiles = []
2021-11-15 14:58:23 -05:00
2021-11-15 16:14:33 -05:00
samples = map(lambda s: str(self.samples / s) + '.srt', samples)
i = 1
for sample in samples:
ifile = str(i) + '.' + caller + '.srt'
shutil.copy(sample, ifile)
args.append(ifile)
ifiles.append(ifile)
i += 1
2021-11-15 14:58:23 -05:00
fsub.run(args)
2021-11-15 16:14:33 -05:00
limit = len(ofiles)
for i, ifile in enumerate(ifiles):
2021-11-15 16:24:50 -05:00
if i < limit:
out = open(ifile)
result = out.read()
out.close()
ofile = str(self.samples / ofiles[i]) + '.srt'
cmp_file = open(ofile)
cmp = cmp_file.read()
cmp_file.close()
self.assertEqual(result, cmp)
2021-11-15 16:14:33 -05:00
os.remove(ifile)
2021-11-15 14:58:23 -05:00
def test_cleaned(self):
args = ['-f', str(self.samples / 'blacklist')]
2021-11-15 16:14:33 -05:00
self.run_on(args, ['sample1'], ['sample1-cleaned'])
2021-11-15 14:58:23 -05:00
def test_stripped(self):
2021-11-15 16:14:33 -05:00
self.run_on(['-n'], ['sample1'], ['sample1-stripped'])
2021-11-15 14:58:23 -05:00
def test_cleaned_stripped(self):
args = ['-c', '-f', str(self.samples / 'blacklist'), '-n']
2021-11-15 16:14:33 -05:00
self.run_on(args, ['sample1'], ['sample1-cleaned-stripped'])
2021-11-15 14:58:23 -05:00
def test_cleaned_stripped_shifted_1h(self):
args = ['-c',
'-f', str(self.samples / 'blacklist'),
'-n',
'-s', '3600000']
2021-11-15 16:14:33 -05:00
self.run_on(args, ['sample1'], ['sample1-cleaned-stripped-shifted-1h'])
2021-11-15 14:58:23 -05:00
def test_shifted_minus_1h(self):
args = ['-s', '-3600000']
2021-11-15 16:14:33 -05:00
self.run_on(args, ['sample1'], ['sample1-shifted-minus-1h'])
2021-11-15 14:58:23 -05:00
def test_shifted_minus_52s(self):
args = ['-s', '-52000']
2021-11-15 16:14:33 -05:00
self.run_on(args, ['sample1'], ['sample1-shifted-minus-52s'])
def test_joined(self):
args = ['-j']
self.run_on(args, ['sample1', 'sample2', 'sample3'],
['sample1-sample2-sample3-joined'])
2021-11-15 14:58:23 -05:00
if __name__ == '__main__':
unittest.main()