From 31df0b8eb798f601e5b1eff4219aa3a523f9287e Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Tue, 29 May 2018 01:23:40 +0530 Subject: [PATCH] Use click CliRunner for tests --- tests/test_cli.py | 60 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1a8c625..d561cc6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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