fsub/tests/integration.py

111 lines
3.6 KiB
Python
Raw Permalink 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-17 18:45:38 -05:00
def run_on(self, args, samples, expect_out_files, replace=False):
2021-11-15 16:14:33 -05:00
caller = inspect.stack()[1][3]
2021-11-17 18:45:38 -05:00
cloned_samples = []
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:
2021-11-17 18:45:38 -05:00
cloned_sample = str(i) + '.' + caller + '.srt'
shutil.copy(sample, cloned_sample)
args.append(cloned_sample)
cloned_samples.append(cloned_sample)
2021-11-15 16:14:33 -05:00
i += 1
2021-11-15 14:58:23 -05:00
fsub.run(args)
2021-11-17 18:45:38 -05:00
limit = len(expect_out_files)
for i, cloned_sample in enumerate(cloned_samples):
2021-11-15 16:24:50 -05:00
if i < limit:
2021-11-15 17:30:59 -05:00
if not replace:
2021-11-17 18:45:38 -05:00
os.remove(cloned_sample)
cloned_sample = 'out-' + cloned_sample
out = open(cloned_sample)
2021-11-15 16:24:50 -05:00
result = out.read()
out.close()
2021-11-17 18:45:38 -05:00
expect_out_file = str(self.samples/expect_out_files[i])+'.srt'
expect_out_file = open(expect_out_file)
expect_out = expect_out_file.read()
expect_out_file.close()
2021-11-15 16:24:50 -05:00
2021-11-17 18:45:38 -05:00
self.assertEqual(result, expect_out)
2021-11-15 17:30:59 -05:00
try:
2021-11-17 18:45:38 -05:00
os.remove(cloned_sample)
2021-11-15 17:30:59 -05:00
except FileNotFoundError:
pass
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
2021-11-17 18:45:38 -05:00
def test_cleaned_begin(self):
args = ['-f', str(self.samples / 'blacklist'), '-b', '3']
self.run_on(args, ['sample1'], ['sample1-cleaned-begin'])
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
2021-11-17 18:45:38 -05:00
def test_stripped_end(self):
args = ['-n', '-e', '00:00:55,500']
self.run_on(args, ['sample1'], ['sample1-stripped-end'])
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'])
2021-11-17 18:45:38 -05:00
def test_shifted_minus_1h_begin(self):
args = ['-s', '-3600000', '-b', '00:00:53,500']
self.run_on(args, ['sample1'], ['sample1-shifted-minus-1h-begin'])
2021-11-15 16:14:33 -05:00
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
2021-11-17 18:45:38 -05:00
def test_cut_begin(self):
args = ['-b', '2', '-u']
self.run_on(args, ['sample1'], ['sample1-cut-out-begin'])
def test_cut_end(self):
args = ['-e', '1', '-u']
self.run_on(args, ['sample1'], ['sample1-cut-out-end'])
def test_cut_begin_end(self):
args = ['-b', '2', '-e', '4', '-u']
self.run_on(args, ['sample1'], ['sample1-cut-out-begin-end'])
def test_cut_end_joined(self):
args = ['-e', '1', '-u', '-j']
self.run_on(args, ['sample1', 'sample3'],
['sample1-sample3-cut-out-end-joined'])
2021-11-15 14:58:23 -05:00
if __name__ == '__main__':
unittest.main()