diff options
author | Lars Wirzenius <liw@gytha> | 2008-03-23 13:39:07 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@gytha> | 2008-03-23 13:39:07 +0200 |
commit | 0230eb21a695cbc307596c912fd2b9d357c52024 (patch) | |
tree | 57fa3dfa6e754fb459c9dac33028028e4d428512 /obnam | |
parent | ee1d4ee67239ded39513ca08ca276551b8cf3388 (diff) | |
download | obnam-0230eb21a695cbc307596c912fd2b9d357c52024.tar.gz |
Started on implementing OperationFactory.get_operation method.
Diffstat (limited to 'obnam')
-rw-r--r-- | obnam/oper.py | 25 | ||||
-rw-r--r-- | obnam/operTests.py | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/obnam/oper.py b/obnam/oper.py index eeeda01c..3d785f77 100644 --- a/obnam/oper.py +++ b/obnam/oper.py @@ -65,6 +65,19 @@ class Operation: """ +class NoArguments(obnam.ObnamException): + + def __init__(self): + self._msg = ("Command line argument list is empty. " + "Need at least the operation name.") + + +class OperationNotFound(obnam.ObnamException): + + def __init__(self, name): + self._msg = "Unknown operation %s" % name + + class OperationFactory: """Instantiate Operation subclasses based on command line arguments.""" @@ -79,3 +92,15 @@ class OperationFactory: if inspect.isclass(x) and issubclass(x, Operation): list.append(x) return list + + def get_operation(self, args): + """Instantiate the right operation given the command line. + + If there is no corresponding operation, raise an error. + + """ + + if not args: + raise NoArguments() + + raise OperationNotFound(args[0]) diff --git a/obnam/operTests.py b/obnam/operTests.py index 120bad4d..5876acec 100644 --- a/obnam/operTests.py +++ b/obnam/operTests.py @@ -50,3 +50,11 @@ class OperationFactoryTests(unittest.TestCase): def testFindsOperations(self): self.failUnless(self.factory.find_operations()) + + def testRaisesErrorForNoArguments(self): + self.failUnlessRaises(obnam.ObnamException, + self.factory.get_operation, []) + + def testRaisesErrorForUnknownArgument(self): + self.failUnlessRaises(obnam.ObnamException, + self.factory.get_operation, ["pink"]) |