-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_mainfile.py
87 lines (68 loc) · 2.57 KB
/
test_mainfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import hashlib
import shutil
from yt2flp import *
import os
def test_startup():
assert startup_and_options(["you", "--debug"]) == {"boost": False, "debug": True, "name": "DEBUGoutput", "url":"you"}
class TestUrls:
def test_valid_url(self):
assert (
stripurl("https://www.youtube.com/watch?v=EIyixC9NsLI&si=ksjrhgksjrbg")
== "https://youtu.be/EIyixC9NsLI"
)
def test_random_url(self):
import secrets
urldata = secrets.token_hex(15)
assert (
stripurl(
f"https://www.youtube.com/watch?v={urldata}&si={secrets.token_hex(10)}"
)
== f"https://youtu.be/{urldata}"
)
def getPython():
return "python3" if not os.system("python3 -c 'exit(0)'") else "python"
def hashFile(file):
with open(file, "rb") as fd:
return hashlib.sha256(fd.read()).hexdigest()
def copyNeeded(temppth):
shutil.copy("examples/rickroll.bnd", temppth)
shutil.copy("test/output.mp4", temppth)
shutil.copy("helper1.py", temppth)
shutil.copy("yt2flp.py", temppth)
# def test_ALL(tmp_path):
# copyNeeded(tmp_path)
# origDir = os.path.abspath(".")
# os.chdir(tmp_path)
# os.system(f"{getPython()} yt2flp.py https://www.youtube.com/watch?v=dQw4w9WgXcQ DEBUG")
# assert hashFile("rickroll.bnd") == hashFile("output.bnd")
# os.chdir(origDir)
class TestConsistency:
def test_downloader(self, tmp_path):
copyNeeded(tmp_path)
origDir = os.path.abspath(".")
os.chdir(tmp_path)
download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
shutil.move("vid.mp4", "vid1.mp4")
download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
assert hashFile("vid.mp4") == hashFile("vid.mp4")
os.chdir(origDir)
def test_booster(self, tmp_path):
copyNeeded(tmp_path)
origDir = os.path.abspath(".")
os.chdir(tmp_path)
shutil.copy("output.mp4", "vid.mp4")
shutil.move("output.mp4", "oldput.mp4")
boost(True)
shutil.move("oldput.mp4", "vid.mp4")
shutil.move("output.mp4", "output1.mp4")
boost(True)
assert hashFile("output1.mp4") == hashFile("output.mp4")
os.chdir(origDir)
def test_converter(self, tmp_path):
copyNeeded(tmp_path)
origDir = os.path.abspath(".")
os.chdir(tmp_path)
os.system(f"{getPython()} helper1.py output.mp4 output.bnd")
os.system(f"{getPython()} helper1.py output.mp4 output1.bnd")
assert hashFile("output1.bnd") == hashFile("output.bnd")
os.chdir(origDir)