diff --git a/pirate/pirate.py b/pirate/pirate.py index 04a5480..aecdc25 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -7,6 +7,7 @@ import socket import urllib.request as request import urllib.error import sys +import builtins from collections import OrderedDict import webbrowser @@ -325,7 +326,7 @@ def pirate_main(args): printer.print("\nSelect links (Type 'h' for more options" ", 'q' to quit)", end='\b', color='alt') try: - l = input(': ') + l = builtins.input(': ') except (KeyboardInterrupt, EOFError): printer.print('\nCancelled.') return diff --git a/tests/test_pirate.py b/tests/test_pirate.py index 5c59d8f..552db2f 100755 --- a/tests/test_pirate.py +++ b/tests/test_pirate.py @@ -23,20 +23,36 @@ class TestPirate(unittest.TestCase): for test in tests: self.assertEqual(pirate.pirate.parse_cmd(*test[0]), test[1]) - def test_main(self): - with patch('subprocess.call') as mock_call: - result = { - 'magnet': 'dn=derp', - 'seeds': '1', - 'leechers': '1', - 'size': ('1', 'mb'), - 'uploaded': '1', - } - with patch('pirate.torrent.remote', return_value=[result]) as mock_remote: - config = pirate.pirate.parse_config_file('') - args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['-0', 'term', '-C', 'blah %s'])) - pirate.pirate.pirate_main(args) - mock_call.assert_called_once_with(['blah', 'dn=derp']) + @patch('subprocess.call') + def test_main(self, mock_call): + result = { + 'magnet': 'dn=derp', + 'seeds': '1', + 'leechers': '1', + 'size': ('1', 'mb'), + 'uploaded': '1', + } + with patch('pirate.torrent.remote', return_value=[result]) as mock_remote: + config = pirate.pirate.parse_config_file('') + args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['-0', 'term', '-C', 'blah %s'])) + pirate.pirate.pirate_main(args) + mock_call.assert_called_once_with(['blah', 'dn=derp']) + + @patch('pirate.pirate.builtins.input', return_value='0') + @patch('subprocess.call') + def test_main_choice(self, mock_call, mock_input): + result = { + 'magnet': 'dn=derp', + 'seeds': '1', + 'leechers': '1', + 'size': ('1', 'mb'), + 'uploaded': '1', + } + with patch('pirate.torrent.remote', return_value=[result]) as mock_remote: + config = pirate.pirate.parse_config_file('') + args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['term', '-C', 'blah %s'])) + pirate.pirate.pirate_main(args) + mock_call.assert_called_once_with(['blah', 'dn=derp']) def test_parse_torrent_command(self): tests = [