From f2d04144167120dc8820401940172d10fdda007b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 18 May 2014 15:15:45 +0200 Subject: Rename hidden/arg_parameters to exclude/inline_args. --- docs/introduction.rst | 4 ++-- docs/reference.rst | 18 +++++++++--------- factory/base.py | 16 ++++++++-------- tests/test_base.py | 4 ++-- tests/test_using.py | 18 +++++++++--------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/introduction.rst b/docs/introduction.rst index 5e3b4d8..d00154d 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -218,14 +218,14 @@ Non-kwarg arguments Some classes take a few, non-kwarg arguments first. -This is handled by the :data:`~factory.FactoryOptions.arg_parameters` attribute: +This is handled by the :data:`~factory.FactoryOptions.inline_args` attribute: .. code-block:: python class MyFactory(factory.Factory): class Meta: model = MyClass - arg_parameters = ('x', 'y') + inline_args = ('x', 'y') x = 1 y = 2 diff --git a/docs/reference.rst b/docs/reference.rst index d616d1c..25fef22 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -47,10 +47,10 @@ The :class:`Factory` class .. versionadded:: 2.4.0 - .. attribute:: arg_parameters + .. attribute:: inline_args Some factories require non-keyword arguments to their :meth:`~object.__init__`. - They should be listed, in order, in the :attr:`arg_parameters` + They should be listed, in order, in the :attr:`inline_args` attribute: .. code-block:: python @@ -58,7 +58,7 @@ The :class:`Factory` class class UserFactory(factory.Factory): class Meta: model = User - arg_parameters = ('login', 'email') + inline_args = ('login', 'email') login = 'john' email = factory.LazyAttribute(lambda o: '%s@example.com' % o.login) @@ -72,14 +72,14 @@ The :class:`Factory` class .. versionadded:: 2.4.0 - .. attribute:: hidden_args + .. attribute:: exclude While writing a :class:`Factory` for some object, it may be useful to have general fields helping defining others, but that should not be passed to the model class; for instance, a field named 'now' that would hold a reference time used by other objects. - Factory fields whose name are listed in :attr:`hidden_args` will + Factory fields whose name are listed in :attr:`exclude` will be removed from the set of args/kwargs passed to the underlying class; they can be any valid factory_boy declaration: @@ -88,7 +88,7 @@ The :class:`Factory` class class OrderFactory(factory.Factory): class Meta: model = Order - hidden_args = ('now',) + exclude = ('now',) now = factory.LazyAttribute(lambda o: datetime.datetime.utcnow()) started_at = factory.LazyAttribute(lambda o: o.now - datetime.timedelta(hours=1)) @@ -125,12 +125,12 @@ The :class:`Factory` class .. attribute:: FACTORY_ARG_PARAMETERS .. deprecated:: 2.4.0 - See :attr:`FactoryOptions.arg_parameters`. + See :attr:`FactoryOptions.inline_args`. .. attribute:: FACTORY_HIDDEN_ARGS .. deprecated:: 2.4.0 - See :attr:`FactoryOptions.hidden_args`. + See :attr:`FactoryOptions.exclude`. **Class-level attributes:** @@ -231,7 +231,7 @@ The :class:`Factory` class The :meth:`_adjust_kwargs` extension point allows for late fields tuning. It is called once keyword arguments have been resolved and post-generation - items removed, but before the :attr:`~FactoryOptions.arg_parameters` extraction + items removed, but before the :attr:`~FactoryOptions.inline_args` extraction phase. .. code-block:: python diff --git a/factory/base.py b/factory/base.py index e5c31f7..923c56b 100644 --- a/factory/base.py +++ b/factory/base.py @@ -192,8 +192,8 @@ class FactoryOptions(object): OptionDefault('model', None, inherit=True), OptionDefault('abstract', False, inherit=False), OptionDefault('strategy', CREATE_STRATEGY, inherit=True), - OptionDefault('arg_parameters', (), inherit=True), - OptionDefault('hidden_args', (), inherit=True), + OptionDefault('inline_args', (), inherit=True), + OptionDefault('exclude', (), inherit=True), ] def _fill_from_meta(self, meta, base_meta): @@ -326,8 +326,8 @@ class BaseFactory(object): 'FACTORY_FOR': 'model', 'ABSTRACT_FACTORY': 'abstract', 'FACTORY_STRATEGY': 'strategy', - 'FACTORY_ARG_PARAMETERS': 'arg_parameters', - 'FACTORY_HIDDEN_ARGS': 'hidden_args', + 'FACTORY_ARG_PARAMETERS': 'inline_args', + 'FACTORY_HIDDEN_ARGS': 'exclude', } # ID to use for the next 'declarations.Sequence' attribute. @@ -470,11 +470,11 @@ class BaseFactory(object): kwargs = cls._adjust_kwargs(**kwargs) # Remove 'hidden' arguments. - for arg in cls._meta.hidden_args: + for arg in cls._meta.exclude: del kwargs[arg] # Extract *args from **kwargs - args = tuple(kwargs.pop(key) for key in cls._meta.arg_parameters) + args = tuple(kwargs.pop(key) for key in cls._meta.inline_args) logger.debug('BaseFactory: Generating %s.%s(%s)', cls.__module__, @@ -725,7 +725,7 @@ class BaseDictFactory(Factory): def _build(cls, model_class, *args, **kwargs): if args: raise ValueError( - "DictFactory %r does not support Meta.arg_parameters.", cls) + "DictFactory %r does not support Meta.inline_args.", cls) return model_class(**kwargs) @classmethod @@ -747,7 +747,7 @@ class BaseListFactory(Factory): def _build(cls, model_class, *args, **kwargs): if args: raise ValueError( - "ListFactory %r does not support Meta.arg_parameters.", cls) + "ListFactory %r does not support Meta.inline_args.", cls) values = [v for k, v in sorted(kwargs.items())] return model_class(values) diff --git a/tests/test_base.py b/tests/test_base.py index d93bf29..d1df58e 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -122,8 +122,8 @@ class OptionsTests(unittest.TestCase): # Declarative attributes self.assertTrue(AbstractFactory._meta.abstract) self.assertIsNone(AbstractFactory._meta.model) - self.assertEqual((), AbstractFactory._meta.arg_parameters) - self.assertEqual((), AbstractFactory._meta.hidden_args) + self.assertEqual((), AbstractFactory._meta.inline_args) + self.assertEqual((), AbstractFactory._meta.exclude) self.assertEqual(base.CREATE_STRATEGY, AbstractFactory._meta.strategy) # Non-declarative attributes diff --git a/tests/test_using.py b/tests/test_using.py index 5486d33..e20f949 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -906,7 +906,7 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual(TestObjectFactory.alt_create(foo=1), {"foo": 1}) - def test_arg_parameters(self): + def test_inline_args(self): class TestObject(object): def __init__(self, *args, **kwargs): self.args = args @@ -915,7 +915,7 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): class Meta: model = TestObject - arg_parameters = ('x', 'y') + inline_args = ('x', 'y') x = 1 y = 2 @@ -926,7 +926,7 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual((42, 2), obj.args) self.assertEqual({'z': 5, 't': 4}, obj.kwargs) - def test_hidden_args(self): + def test_exclude(self): class TestObject(object): def __init__(self, *args, **kwargs): self.args = args @@ -935,7 +935,7 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): class Meta: model = TestObject - hidden_args = ('x', 'z') + exclude = ('x', 'z') x = 1 y = 2 @@ -946,7 +946,7 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual((), obj.args) self.assertEqual({'y': 2, 't': 4}, obj.kwargs) - def test_hidden_args_and_arg_parameters(self): + def test_exclude_and_inline_args(self): class TestObject(object): def __init__(self, *args, **kwargs): self.args = args @@ -955,8 +955,8 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): class Meta: model = TestObject - hidden_args = ('x', 'z') - arg_parameters = ('y',) + exclude = ('x', 'z') + inline_args = ('y',) x = 1 y = 2 @@ -979,7 +979,7 @@ class NonKwargParametersTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): class Meta: model = TestObject - arg_parameters = ('one', 'two',) + inline_args = ('one', 'two',) one = 1 two = 2 @@ -1005,7 +1005,7 @@ class NonKwargParametersTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): class Meta: model = TestObject - arg_parameters = ('one', 'two') + inline_args = ('one', 'two') one = 1 two = 2 -- cgit v1.2.3