Add join flag

This commit is contained in:
Augusto Gunsch
2021-11-15 18:14:33 -03:00
parent dc7c0da24c
commit 3aa66545ea
6 changed files with 110 additions and 25 deletions

View File

@@ -8,54 +8,68 @@ from pathlib import Path
class TestFsub(unittest.TestCase):
samples = Path('tests/samples')
maxDiff = None
def run_on(self, args, sample, ofile):
ifile = inspect.stack()[1][3] + '.srt'
def run_on(self, args, samples, ofiles):
caller = inspect.stack()[1][3]
ifiles = []
sample = str(self.samples / sample) + '.srt'
shutil.copy(sample, ifile)
args.append(ifile)
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
fsub.run(args)
out = open(ifile)
result = out.read()
out.close()
limit = len(ofiles)
for i, ifile in enumerate(ifiles):
if i == limit:
break
out = open(ifile)
result = out.read()
out.close()
ofile = str(self.samples / ofile) + '.srt'
cmp_file = open(ofile)
cmp = cmp_file.read()
cmp_file.close()
ofile = str(self.samples / ofiles[i]) + '.srt'
cmp_file = open(ofile)
cmp = cmp_file.read()
cmp_file.close()
self.assertEqual(result, cmp)
os.remove(ifile)
self.assertEqual(result, cmp)
os.remove(ifile)
def test_cleaned(self):
args = ['-f', str(self.samples / 'blacklist')]
self.run_on(args, 'sample1', 'sample1-cleaned')
self.run_on(args, ['sample1'], ['sample1-cleaned'])
def test_stripped(self):
self.run_on(['-n'], 'sample1', 'sample1-stripped')
self.run_on(['-n'], ['sample1'], ['sample1-stripped'])
def test_cleaned_stripped(self):
args = ['-c', '-f', str(self.samples / 'blacklist'), '-n']
self.run_on(args, 'sample1', 'sample1-cleaned-stripped')
self.run_on(args, ['sample1'], ['sample1-cleaned-stripped'])
def test_cleaned_stripped_shifted_1h(self):
args = ['-c',
'-f', str(self.samples / 'blacklist'),
'-n',
'-s', '3600000']
self.run_on(args, 'sample1', 'sample1-cleaned-stripped-shifted-1h')
self.run_on(args, ['sample1'], ['sample1-cleaned-stripped-shifted-1h'])
def test_shifted_minus_1h(self):
args = ['-s', '-3600000']
self.run_on(args, 'sample1', 'sample1-shifted-minus-1h')
self.run_on(args, ['sample1'], ['sample1-shifted-minus-1h'])
def test_shifted_minus_52s(self):
args = ['-s', '-52000']
self.run_on(args, 'sample1', 'sample1-shifted-minus-52s')
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'])
if __name__ == '__main__':

View File

@@ -0,0 +1,37 @@
1
00:00:48,900 --> 00:00:49,800
<b>This one is full of HTML tags.</b>
<i>Above, below, everywhere</i>
2
00:00:51,800 --> 00:00:52,700
<a href='dummy'>Even <a>'s!</a>
3
00:00:53,500 --> 00:00:55,200
<html>The script should not
care whether the tag is
valid or not</html>
4
00:00:56,000 --> 00:00:57,000
<p>It should just strip all of
them mercilessly</p>
5
00:00:58,100 --> 00:00:59,600
<ul>Including this one!</ul>
6
00:01:59,600 --> 00:02:00,600
Just a dummy line, I'm sorry.
But there's whitespace!
7
10:05:00,600 --> 10:06:12,800
This one has even more whitespace!
8
10:07:00,600 --> 10:07:02,600
And it's waaay longer!
Amazing

View File

@@ -1,6 +1,6 @@
1
00:01:00,000 --> 00:01:01,000
Just a dummy line, I'm sorry
Just a dummy line, I'm sorry.
But there's whitespace!

13
tests/samples/sample3.srt Normal file
View File

@@ -0,0 +1,13 @@
1
10:03:00,000 --> 10:04:12,200
This one has even more whitespace!
2
10:05:00,000 --> 10:05:02,000
And it's waaay longer!
Amazing