Skip to content

Commit ba9b9d6

Browse files
Added test cases for main.py
1 parent 845cc7a commit ba9b9d6

9 files changed

Lines changed: 35 additions & 9 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class ConnectionFailure(RuntimeError):
22
def __init__(self, arg):
3-
self.args = arg
3+
self.args = (arg,)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class DeletionFailure(RuntimeError):
22
def __init__(self, arg):
3-
self.args = arg
3+
self.args = (arg,)

autoremovetorrents/exception/loginfailure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
class LoginFailure(RuntimeError):
44
def __init__(self, arg):
5-
self.args = arg
5+
self.args = (arg,)

autoremovetorrents/exception/nosuchclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
class NoSuchClient(RuntimeError):
44
def __init__(self, arg):
5-
self.args = arg
5+
self.args = (arg,)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class NoSuchTorrent(RuntimeError):
22
def __init__(self, arg):
3-
self.args = arg
3+
self.args = (arg,)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class RemoteFailure(RuntimeError):
22
def __init__(self, arg):
3-
self.args = arg
3+
self.args = (arg,)

autoremovetorrents/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import yaml
77
from . import logger
88
from .task import Task
9+
from autoremovetorrents.version import __version__
910

10-
def main():
11+
def main(argv):
1112
# View Mode
1213
view_mode = False
1314
# The path of the configuration file
@@ -19,7 +20,7 @@ def main():
1920

2021
# Get arguments
2122
try:
22-
opts = getopt.getopt(sys.argv[1:], 'vc:t:', ['view', 'conf=', 'task='])[0]
23+
opts = getopt.getopt(argv, 'vc:t:', ['view', 'conf=', 'task='])[0]
2324
except getopt.GetoptError:
2425
print('Invalid arguments.')
2526
sys.exit(255)
@@ -33,6 +34,8 @@ def main():
3334

3435
# Run autoremove
3536
try:
37+
# Show version
38+
lg.info('Auto Remove Torrents %s' % __version__)
3639
# Load configurations
3740
lg.info('Loading configurations...')
3841
with open(conf_path, 'r') as stream:
@@ -51,4 +54,4 @@ def main():
5154
lg.critical('An error occured. Please contact the administrator for more information.')
5255

5356
if __name__ == '__main__':
54-
main()
57+
main(sys.argv[1:])

pytest/test_main/command_lines.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--conf=pytest/test_main/config.yml
2+
-c pytest/test_main/config.yml
3+
-v -c pytest/test_main/config.yml
4+
--view -c pytest/test_main/config.yml
5+
-v --task=task1 -c pytest/test_main/config.yml
6+
-t task1 -c pytest/test_main/config.yml
7+
-t task10000 -c pytest/test_main/config.yml
8+
abcdefghijklmnopqrstuvwxyz

pytest/test_main/test_main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
from autoremovetorrents.main import main
3+
4+
def test_main():
5+
basic_dir = os.path.realpath(os.path.dirname(__file__))
6+
print('Basic directory: %s' % basic_dir)
7+
8+
# Open file of command lines
9+
with open(os.path.join(basic_dir, 'command_lines.txt')) as f:
10+
lines = f.readlines()
11+
# Get command lines
12+
for line in lines:
13+
print('Command line: %s' % line)
14+
argv = line.split()
15+
main(argv) # Execute it

0 commit comments

Comments
 (0)