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