diff --git a/pirate/pirate.py b/pirate/pirate.py index c3d4113..04a5480 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -271,9 +271,7 @@ def search_mirrors(printer, pages, category, sort, action, search): return [], None -def main(): - args = combine_configs(load_config(), parse_args(sys.argv[1:])) - +def pirate_main(args): printer = Printer(args.color) # check it transmission is running @@ -392,5 +390,10 @@ def main(): subprocess.call(args.transmission_command + ['-l']) +def main(): + args = combine_configs(load_config(), parse_args(sys.argv[1:])) + pirate_main(args) + + if __name__ == '__main__': main() diff --git a/tests/test_pirate.py b/tests/test_pirate.py index 6451adb..5c59d8f 100755 --- a/tests/test_pirate.py +++ b/tests/test_pirate.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import socket import unittest +import subprocess from unittest import mock from unittest.mock import patch, call, MagicMock @@ -22,6 +23,21 @@ 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']) + def test_parse_torrent_command(self): tests = [ [['h'], ('h', [])],