Use click CliRunner for tests
parent
2e0225a287
commit
31df0b8eb7
|
@ -1,41 +1,45 @@
|
|||
from anime_downloader import cli
|
||||
|
||||
import pytest
|
||||
|
||||
pytest_plugins = ["pytester"]
|
||||
from click.testing import CliRunner
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run(testdir):
|
||||
def do_run(*args):
|
||||
args = ["anime-dl"] + list(args)
|
||||
return testdir._run(*args)
|
||||
return do_run
|
||||
|
||||
|
||||
def test_streamurl(run):
|
||||
result = run(
|
||||
'https://www4.9anime.is/watch/the-seven-deadly-sins-signs-of-holy-war.lxqm/39px7y',
|
||||
'--url'
|
||||
def test_streamurl():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli.cli,
|
||||
[
|
||||
'https://www4.9anime.is/watch/the-seven-deadly-sins-signs-of-holy-war.lxqm/39px7y',
|
||||
'--url'
|
||||
]
|
||||
)
|
||||
|
||||
assert result.ret == 0
|
||||
assert result.exit_code == 0
|
||||
|
||||
for line in result.stdout.lines:
|
||||
assert line.endswith('.mp4')
|
||||
# print(result.output)
|
||||
lines = [r.strip() for r in result.output.split('\n')]
|
||||
for line in lines:
|
||||
if line and not line.startswith('INFO'):
|
||||
assert line.endswith('.mp4')
|
||||
|
||||
|
||||
def test_range(run):
|
||||
result = run(
|
||||
'https://www4.9anime.is/watch/naruto.xx8z/r9k04y',
|
||||
'--url',
|
||||
'-e',
|
||||
'50:55'
|
||||
def test_range():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli.cli,
|
||||
[
|
||||
'https://www4.9anime.is/watch/naruto.xx8z/r9k04y',
|
||||
'--url',
|
||||
'-e',
|
||||
'50:55'
|
||||
]
|
||||
)
|
||||
|
||||
assert result.ret == 0
|
||||
assert result.exit_code == 0
|
||||
|
||||
for line in result.stdout.lines:
|
||||
assert line.endswith('.mp4')
|
||||
lines = [r.strip() for r in result.output.split('\n')]
|
||||
|
||||
assert len(result.stdout.lines) == 5
|
||||
for line in lines:
|
||||
if line and not line.startswith('INFO'):
|
||||
assert line.endswith('.mp4')
|
||||
|
||||
assert len(lines[:-1]) == 5
|
||||
|
|
Loading…
Reference in New Issue