Repository navigation
Expand file tree
/
Copy pathtest_cmdline.py
More file actions
128 lines (103 loc) · 5.9 KB
/
Copy pathtest_cmdline.py
File metadata and controls
128 lines (103 loc) · 5.9 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os.path
import unittest
from unittest.mock import ANY, Mock, patch
import streamlink_cli.main
from streamlink import Streamlink
from streamlink_cli.compat import is_win32
class CommandLineTestCase(unittest.TestCase):
"""
Test that when invoked for the command line arguments are parsed as expected
"""
@patch('streamlink_cli.main.CONFIG_FILES', [])
@patch('streamlink_cli.main.setup_streamlink')
@patch('streamlink_cli.output.sleep')
@patch('streamlink_cli.output.subprocess.call')
@patch('streamlink_cli.output.subprocess.Popen')
@patch('sys.argv')
def _test_args(self, args, commandline, mock_argv, mock_popen, mock_call, mock_sleep, mock_setup_streamlink,
passthrough=False, exit_code=0):
mock_argv.__getitem__.side_effect = lambda x: args[x]
def side_effect(results):
def fn(*args):
result = results.pop(0)
return result
return fn
mock_popen.return_value = Mock(poll=Mock(side_effect=side_effect([None, 0])))
session = Streamlink()
session.load_plugins(os.path.join(os.path.dirname(__file__), "plugin"))
actual_exit_code = 0
with patch('streamlink_cli.main.streamlink', session):
try:
streamlink_cli.main.main()
except SystemExit as exc:
actual_exit_code = exc.code
self.assertEqual(exit_code, actual_exit_code)
mock_setup_streamlink.assert_called_with()
if not passthrough:
mock_popen.assert_called_with(commandline, stderr=ANY, stdout=ANY, bufsize=ANY, stdin=ANY)
else:
mock_call.assert_called_with(commandline, stderr=ANY, stdout=ANY)
@unittest.skipIf(is_win32, "test only applicable in a POSIX OS")
class TestCommandLinePOSIX(CommandLineTestCase):
"""
Commandline tests under POSIX-like operating systems
"""
def test_open_regular_path_player(self):
self._test_args(["streamlink", "-p", "/usr/bin/player", "http://test.se", "test"],
["/usr/bin/player", "-"])
def test_open_space_path_player(self):
self._test_args(["streamlink", "-p", "\"/Applications/Video Player/player\"", "http://test.se", "test"],
["/Applications/Video Player/player", "-"])
# escaped
self._test_args(["streamlink", "-p", "/Applications/Video\\ Player/player", "http://test.se", "test"],
["/Applications/Video Player/player", "-"])
def test_open_player_extra_args_in_player(self):
self._test_args(["streamlink", "-p", "/usr/bin/player",
"-a", '''--input-title-format "Poker \\"Stars\\"" {filename}''',
"http://test.se", "test"],
["/usr/bin/player", "--input-title-format", 'Poker "Stars"', "-"])
def test_open_player_extra_args_in_player_pass_through(self):
self._test_args(["streamlink", "--player-passthrough", "rtmp", "-p", "/usr/bin/player",
"-a", '''--input-title-format "Poker \\"Stars\\"" {filename}''',
"test.se", "rtmp"],
["/usr/bin/player", "--input-title-format", 'Poker "Stars"', "rtmp://test.se"],
passthrough=True)
def test_single_hyphen_extra_player_args_971(self):
"""single hyphen params at the beginning of --player-args
- https://github.com/streamlink/streamlink/issues/971 """
self._test_args(["streamlink", "-p", "/usr/bin/player", "-a", "-v {filename}",
"http://test.se", "test"],
["/usr/bin/player", "-v", "-"])
@unittest.skipIf(not is_win32, "test only applicable on Windows")
class TestCommandLineWindows(CommandLineTestCase):
"""
Commandline tests for Windows
"""
def test_open_space_path_player(self):
self._test_args(["streamlink", "-p", "c:\\Program Files\\Player\\player.exe", "http://test.se", "test"],
"c:\\Program Files\\Player\\player.exe -")
def test_open_space_quote_path_player(self):
self._test_args(["streamlink", "-p", "\"c:\\Program Files\\Player\\player.exe\"", "http://test.se", "test"],
"\"c:\\Program Files\\Player\\player.exe\" -")
def test_open_player_args_with_quote_in_player(self):
self._test_args(["streamlink", "-p",
'''c:\\Program Files\\Player\\player.exe --input-title-format "Poker \\"Stars\\""''',
"http://test.se", "test"],
'''c:\\Program Files\\Player\\player.exe --input-title-format "Poker \\"Stars\\"" -''')
def test_open_player_extra_args_in_player(self):
self._test_args(["streamlink", "-p", "c:\\Program Files\\Player\\player.exe",
"-a", '''--input-title-format "Poker \\"Stars\\"" {filename}''',
"http://test.se", "test"],
'''c:\\Program Files\\Player\\player.exe --input-title-format "Poker \\"Stars\\"" -''')
def test_open_player_extra_args_in_player_pass_through(self):
self._test_args(["streamlink", "--player-passthrough", "rtmp", "-p", "c:\\Program Files\\Player\\player.exe",
"-a", '''--input-title-format "Poker \\"Stars\\"" {filename}''',
"test.se", "rtmp"],
'''c:\\Program Files\\Player\\player.exe --input-title-format "Poker \\"Stars\\"" \"rtmp://test.se\"''',
passthrough=True)
def test_single_hyphen_extra_player_args_971(self):
"""single hyphen params at the beginning of --player-args
- https://github.com/streamlink/streamlink/issues/971 """
self._test_args(["streamlink", "-p", "c:\\Program Files\\Player\\player.exe",
"-a", "-v {filename}", "http://test.se", "test"],
"c:\\Program Files\\Player\\player.exe -v -")