summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-ximdb-lookup/imdbinfo.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 81e4d48..5c27ec7 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -159,6 +159,21 @@ def weight_rating(infos):
return infos
class Protector(object):
+ """ The Protector saves the caller from exception.
+ All callable attributes of child are dynamically
+ replaced by function returning 'None' in case of an
+ exception - except for KeyboardInterrupt exceptions.
+ >>> class Thrower(object):
+ ... def some_func(self):
+ ... raise Exception("I'm evil")
+ >>> t = Thrower()
+ >>> t.some_func() == None
+ Traceback (most recent call last):
+ Exception: I'm evil
+ >>> p = Protector(t)
+ >>> p.some_func() == None
+ True
+ """
def __init__(self, child):
self.child = child
def __getattr__(self, name):
@@ -277,6 +292,10 @@ class HelpAction(argparse._HelpAction):
print(formatter.format_help())
parser.exit(0)
+def do_test(args):
+ import doctest
+ doctest.testmod()
+
if __name__ == u"__main__":
tmdb.API_KEY = read_key()
@@ -312,10 +331,16 @@ if __name__ == u"__main__":
parser_index.set_defaults(func=do_index)
parser_index.add_argument("files", action="append", nargs="+", help="Files containing distinct movie-ids")
+ parser_test = subparsers.add_parser("test", add_help=False, help="Run testsuite")
+ parser_test.set_defaults(func=do_test)
+
args = parser.parse_args(sys.argv[1:])
if "log_level" in args:
logging.basicConfig(level=args.log_level)
- ids = map(lambda filename: (lambda x: (filename, x.groups()[0]) if x else None)(re.match(".*#(tt[0-9]{7}).*", filename)),
- args.files[0])
- args.func(args, filter(lambda i: i is not None, ids))
+ if "files" in args:
+ ids = map(lambda filename: (lambda x: (filename, x.groups()[0]) if x else None)(re.match(".*#(tt[0-9]{7}).*", filename)),
+ args.files[0])
+ args.func(args, filter(lambda i: i is not None, ids))
+ else:
+ args.func(args)