summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-15 01:39:57 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-15 01:39:57 +0100
commitefc0ca41dcec074176064faf1e899ea275bb2901 (patch)
tree0c69c443ae2022f8a7ca2f1df786e094ae9c15e7 /factory
parent6e9bf5af909e1e164a294fd5589edc4fada06731 (diff)
downloadfactory-boy-efc0ca41dcec074176064faf1e899ea275bb2901.tar
factory-boy-efc0ca41dcec074176064faf1e899ea275bb2901.tar.gz
Fix exception hierarchy.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory')
-rw-r--r--factory/base.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/factory/base.py b/factory/base.py
index aef21d5..2418675 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -41,6 +41,22 @@ CLASS_ATTRIBUTE_POSTGEN_DECLARATIONS = '_postgen_declarations'
CLASS_ATTRIBUTE_ASSOCIATED_CLASS = '_associated_class'
+class FactoryError(Exception):
+ """Any exception raised by factory_boy."""
+
+
+class AssociatedClassError(FactoryError):
+ """Exception for Factory subclasses lacking FACTORY_FOR."""
+
+
+class UnknownStrategy(FactoryError):
+ """Raised when a factory uses an unknown strategy."""
+
+
+class UnsupportedStrategy(FactoryError):
+ """Raised when trying to use a strategy on an incompatible Factory."""
+
+
# Factory metaclasses
def get_factory_bases(bases):
@@ -64,7 +80,7 @@ class FactoryMetaClass(type):
elif cls.FACTORY_STRATEGY == STUB_STRATEGY:
return cls.stub(**kwargs)
else:
- raise BaseFactory.UnknownStrategy('Unknown FACTORY_STRATEGY: {0}'.format(cls.FACTORY_STRATEGY))
+ raise UnknownStrategy('Unknown FACTORY_STRATEGY: {0}'.format(cls.FACTORY_STRATEGY))
@classmethod
def _discover_associated_class(cls, class_name, attrs, inherited=None):
@@ -200,15 +216,12 @@ class FactoryMetaClass(type):
class BaseFactory(object):
"""Factory base support for sequences, attributes and stubs."""
- class UnknownStrategy(RuntimeError):
- pass
-
- class UnsupportedStrategy(RuntimeError):
- pass
+ UnknownStrategy = UnknownStrategy
+ UnsupportedStrategy = UnsupportedStrategy
def __new__(cls, *args, **kwargs):
"""Would be called if trying to instantiate the class."""
- raise RuntimeError('You cannot instantiate BaseFactory')
+ raise FactoryError('You cannot instantiate BaseFactory')
# ID to use for the next 'declarations.Sequence' attribute.
_next_sequence = None
@@ -431,10 +444,6 @@ class BaseFactory(object):
return cls.generate_batch(strategy, size, **kwargs)
-class AssociatedClassError(RuntimeError):
- pass
-
-
class Factory(BaseFactory):
"""Factory base with build and create support.