Implement new flags

This commit is contained in:
Augusto Gunsch
2021-11-17 20:45:38 -03:00
parent e51110847e
commit d9c25e1b27
11 changed files with 282 additions and 75 deletions

View File

@@ -9,39 +9,39 @@ from pathlib import Path
class TestFsub(unittest.TestCase):
samples = Path('tests/samples')
def run_on(self, args, samples, ofiles, replace=False):
def run_on(self, args, samples, expect_out_files, replace=False):
caller = inspect.stack()[1][3]
ifiles = []
cloned_samples = []
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)
cloned_sample = str(i) + '.' + caller + '.srt'
shutil.copy(sample, cloned_sample)
args.append(cloned_sample)
cloned_samples.append(cloned_sample)
i += 1
fsub.run(args)
limit = len(ofiles)
for i, ifile in enumerate(ifiles):
limit = len(expect_out_files)
for i, cloned_sample in enumerate(cloned_samples):
if i < limit:
if not replace:
os.remove(ifile)
ifile = 'out-' + ifile
out = open(ifile)
os.remove(cloned_sample)
cloned_sample = 'out-' + cloned_sample
out = open(cloned_sample)
result = out.read()
out.close()
ofile = str(self.samples / ofiles[i]) + '.srt'
cmp_file = open(ofile)
cmp = cmp_file.read()
cmp_file.close()
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()
self.assertEqual(result, cmp)
self.assertEqual(result, expect_out)
try:
os.remove(ifile)
os.remove(cloned_sample)
except FileNotFoundError:
pass
@@ -49,9 +49,17 @@ class TestFsub(unittest.TestCase):
args = ['-f', str(self.samples / 'blacklist')]
self.run_on(args, ['sample1'], ['sample1-cleaned'])
def test_cleaned_begin(self):
args = ['-f', str(self.samples / 'blacklist'), '-b', '3']
self.run_on(args, ['sample1'], ['sample1-cleaned-begin'])
def test_stripped(self):
self.run_on(['-n'], ['sample1'], ['sample1-stripped'])
def test_stripped_end(self):
args = ['-n', '-e', '00:00:55,500']
self.run_on(args, ['sample1'], ['sample1-stripped-end'])
def test_cleaned_stripped(self):
args = ['-c', '-f', str(self.samples / 'blacklist'), '-n']
self.run_on(args, ['sample1'], ['sample1-cleaned-stripped'])
@@ -71,11 +79,32 @@ class TestFsub(unittest.TestCase):
args = ['-s', '-52000']
self.run_on(args, ['sample1'], ['sample1-shifted-minus-52s'])
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'])
def test_joined(self):
args = ['-j']
self.run_on(args, ['sample1', 'sample2', 'sample3'],
['sample1-sample2-sample3-joined'])
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'])
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,17 @@
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:56,000 --> 00:00:57,000
<p>It should just strip all of
them mercilessly</p>
4
00:00:58,100 --> 00:00:59,600
<ul>Including this one!</ul>

View File

@@ -0,0 +1,14 @@
1
00:00:51,800 --> 00:00:52,700
<a href='dummy'>Even <a>'s!</a>
2
00:00:53,500 --> 00:00:55,200
<html>The script should not
care whether the tag is
valid or not</html>
3
00:00:56,000 --> 00:00:57,000
<p>It should just strip all of
them mercilessly</p>

View File

@@ -0,0 +1,18 @@
1
00:00:51,800 --> 00:00:52,700
<a href='dummy'>Even <a>'s!</a>
2
00:00:53,500 --> 00:00:55,200
<html>The script should not
care whether the tag is
valid or not</html>
3
00:00:56,000 --> 00:00:57,000
<p>It should just strip all of
them mercilessly</p>
4
00:00:58,100 --> 00:00:59,600
<ul>Including this one!</ul>

View File

@@ -0,0 +1,4 @@
1
00:00:48,900 --> 00:00:49,800
<b>This one is full of HTML tags.</b>
<i>Above, below, everywhere</i>

View File

@@ -0,0 +1,8 @@
1
00:00:48,900 --> 00:00:49,800
<b>This one is full of HTML tags.</b>
<i>Above, below, everywhere</i>
2
10:03:49,800 --> 10:05:02,000
This one has even more whitespace!

View File

@@ -0,0 +1,8 @@
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>

View File

@@ -0,0 +1,23 @@
1
00:00:48,900 --> 00:00:49,800
This one is full of HTML tags.
Above, below, everywhere
2
00:00:51,800 --> 00:00:52,700
Even 's!
3
00:00:53,500 --> 00:00:55,200
The script should not
care whether the tag is
valid or not
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>