Add tests; they take a long time atm

Former-commit-id: bed5286907c49988378f58a1e78c4f34f6e25627
This commit is contained in:
Theelgirl 2021-03-09 08:30:19 -08:00
parent 69b64cca77
commit e35057a0d7
10 changed files with 114 additions and 0 deletions

7
tests/decoded/README.txt Normal file
View File

@ -0,0 +1,7 @@
large_pdf.pdf:
- yt fvid -d.mp4
- yt fvid -dz.mp4
rio_de_janeiro_skyline.jpg:
- yt fvid -dz5.mp4
- fvid -dz5.mp4

View File

@ -0,0 +1 @@
a28df2863dd91173b0baa5043b8a15ff6ae67b85

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 KiB

View File

@ -0,0 +1 @@
11240b442e7a29da7eef80457e0d726f690ed794

View File

@ -0,0 +1 @@
caa3defe33182e8d166539f2c8e93d80779fb485

View File

@ -0,0 +1 @@
9b0e4fbde08c8b11e7a767a0b5969fd8600f5732

93
tests/encoding_test.py Normal file
View File

@ -0,0 +1,93 @@
import pytest
import unittest
import os
import sys
import subprocess
import fvid
import ffpb
import tqdm
import platform
from helper import SkippableTest
from shlex import split
from collections import namedtuple
from functools import reduce
proc_output = namedtuple('proc_output', 'stdout stderr')
def pipeline(starter_command, *commands):
if not commands:
try:
starter_command, *commands = starter_command.split('|')
except AttributeError:
pass
starter_command = _parse(starter_command)
starter = subprocess.Popen(starter_command, stdout=subprocess.PIPE)
last_proc = reduce(_create_pipe, map(_parse, commands), starter)
return proc_output(*last_proc.communicate())
def _create_pipe(previous, command):
proc = subprocess.Popen(command, stdin=previous.stdout, stdout=subprocess.PIPE)
previous.stdout.close()
return proc
def _parse(cmd):
try:
ok = list(map(str, split(cmd)))
print(ok)
return ok
except Exception:
return cmd
class FvidTestCase(unittest.TestCase):
def test_decode_from_yt(self):
logging_info = ""
encoded_yt_videos = [i for i in sorted(os.listdir('../tests/encoded/'), reverse=True) if i.lower().startswith('yt')]
for video_name in encoded_yt_videos:
cmd = "python3 -m" + video_name[2:-4] + " -i '../tests/encoded/" + video_name + "'"
if platform.system().lower() in ("linux", "darwin"):
cmd += ' -o /dev/null'
elif platform.system().lower() in ("windows",):
cmd += ' -o nul'
resp = pipeline(cmd)[0].decode('utf-8')
print(resp)
logging_info += resp
assert 'error' not in logging_info.lower()
def test_encode_and_decode_files(self):
logging_info = ""
files = [i for i in sorted(os.listdir('../tests/decoded/'), reverse=True) if not i == 'README.txt']
possible_encodings = ['-ey5', '-ey5 -f 3', '-eyz5', '-eyz']
for file_name in files:
for encoding in possible_encodings:
cmd = "python3 -m fvid " + encoding + " -i ../tests/decoded/" + file_name + " -o '../tests/temp/yt_fvid_" + encoding + ".mp4'"
resp = pipeline(cmd)[0].decode('utf-8')
print(resp)
logging_info += resp
break # only doing one for now so we can test decoding
break
videos = [i for i in sorted(os.listdir('./temp/'), reverse=True)]
possible_decodings = ['-dy5', '-dy5 -f 3', '-dyz5', '-dyz']
for video_name in videos:
for decoding in possible_decodings:
cmd = "python3 -m" + video_name[2:-4].replace('_', ' ') + " -i ../tests/temp/" + video_name
if platform.system().lower() in ("linux", "darwin"):
cmd += ' -o /dev/null'
elif platform.system().lower() in ("windows",):
cmd += ' -o nul'
resp = pipeline(cmd)[0].decode('utf-8')
print(resp)
logging_info += resp
break
break
print(logging_info.lower())
assert 'error' not in logging_info.lower()
if __name__ == '__main__':
# try:
# print(FvidTestCase().test_decode_from_yt())
# print(FvidTestCase().test_encode_and_decode_files())
# except KeyboardInterrupt:
# pass
pytest.main([__file__])

8
tests/helper.py Normal file
View File

@ -0,0 +1,8 @@
import unittest
class SkippableTest(unittest.TestCase):
def skip(self, msg):
if hasattr(self, 'skipTest'):
return self.skipTest(msg)
return None

2
tests/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pytest
tqdm

BIN
tests/temp/yt_fvid_-ey5.mp4 Normal file

Binary file not shown.