diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-24 20:02:08 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-24 20:02:08 +0100 |
commit | 4d6847eb93aa269130ad803fb50be99c4a7508d0 (patch) | |
tree | 9ae1cbfa28ca7bd6430b82f5fbca83316ea084ee | |
parent | 6c4f5846c8e21d6e48347b7e661edb72ffabb9f1 (diff) | |
download | factory-boy-4d6847eb93aa269130ad803fb50be99c4a7508d0.tar factory-boy-4d6847eb93aa269130ad803fb50be99c4a7508d0.tar.gz |
Default Sequence.type to int (Closes #50).
-rw-r--r-- | docs/changelog.rst | 1 | ||||
-rw-r--r-- | factory/declarations.py | 2 | ||||
-rw-r--r-- | tests/test_containers.py | 8 | ||||
-rw-r--r-- | tests/test_using.py | 30 |
4 files changed, 21 insertions, 20 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst index 695670f..b9ea79f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,7 @@ ChangeLog - Allow overriding the base factory class for :func:`~factory.make_factory` and friends. - Add support for Python3 (Thanks to `kmike <https://github.com/kmike>`_ and `nkryptic <https://github.com/nkryptic>`_) - Add support for ``get_or_create`` in :class:`~factory.DjangoModelFactory` + - The default :attr:`~factory.Sequence.type` for :class:`~factory.Sequence` is now :obj:`int` *Removed:* diff --git a/factory/declarations.py b/factory/declarations.py index 2b1fc05..a284930 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -168,7 +168,7 @@ class Sequence(OrderedDeclaration): type (function): A function converting an integer into the expected kind of counter for the 'function' attribute. """ - def __init__(self, function, type=str): + def __init__(self, function, type=int): super(Sequence, self).__init__() self.function = function self.type = type diff --git a/tests/test_containers.py b/tests/test_containers.py index 4f70e29..70ed885 100644 --- a/tests/test_containers.py +++ b/tests/test_containers.py @@ -253,7 +253,7 @@ class AttributeBuilderTestCase(unittest.TestCase): self.assertEqual({'one': 2}, ab.build(create=False)) def test_factory_defined_sequence(self): - seq = declarations.Sequence(lambda n: 'xx' + n) + seq = declarations.Sequence(lambda n: 'xx%d' % n) class FakeFactory(object): @classmethod @@ -270,7 +270,7 @@ class AttributeBuilderTestCase(unittest.TestCase): self.assertEqual({'one': 'xx1'}, ab.build(create=False)) def test_additionnal_sequence(self): - seq = declarations.Sequence(lambda n: 'xx' + n) + seq = declarations.Sequence(lambda n: 'xx%d' % n) class FakeFactory(object): @classmethod @@ -287,8 +287,8 @@ class AttributeBuilderTestCase(unittest.TestCase): self.assertEqual({'one': 1, 'two': 'xx1'}, ab.build(create=False)) def test_replaced_sequence(self): - seq = declarations.Sequence(lambda n: 'xx' + n) - seq2 = declarations.Sequence(lambda n: 'yy' + n) + seq = declarations.Sequence(lambda n: 'xx%d' % n) + seq2 = declarations.Sequence(lambda n: 'yy%d' % n) class FakeFactory(object): @classmethod diff --git a/tests/test_using.py b/tests/test_using.py index a0b0db7..2e07621 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -315,8 +315,8 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.Sequence(lambda n: 'one' + n) - two = factory.Sequence(lambda n: 'two' + n) + one = factory.Sequence(lambda n: 'one%d' % n) + two = factory.Sequence(lambda n: 'two%d' % n) test_object0 = TestObjectFactory.build() self.assertEqual(test_object0.one, 'one0') @@ -334,8 +334,8 @@ class UsingFactoryTestCase(unittest.TestCase): def _setup_next_sequence(cls): return 42 - one = factory.Sequence(lambda n: 'one' + n) - two = factory.Sequence(lambda n: 'two' + n) + one = factory.Sequence(lambda n: 'one%d' % n) + two = factory.Sequence(lambda n: 'two%d' % n) test_object0 = TestObjectFactory.build() self.assertEqual('one42', test_object0.one) @@ -382,8 +382,8 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.Sequence(lambda n: 'one' + n) - two = factory.Sequence(lambda n: 'two' + n) + one = factory.Sequence(lambda n: 'one%d' % n) + two = factory.Sequence(lambda n: 'two%d' % n) objs = TestObjectFactory.build_batch(20) @@ -408,8 +408,8 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.LazyAttributeSequence(lambda a, n: 'abc' + n) - two = factory.LazyAttributeSequence(lambda a, n: a.one + ' xyz' + n) + one = factory.LazyAttributeSequence(lambda a, n: 'abc%d' % n) + two = factory.LazyAttributeSequence(lambda a, n: a.one + ' xyz%d' % n) test_object0 = TestObjectFactory.build() self.assertEqual(test_object0.one, 'abc0') @@ -472,7 +472,7 @@ class UsingFactoryTestCase(unittest.TestCase): @factory.sequence def one(n): - return 'one' + n + return 'one%d' % n test_object = TestObjectFactory.build() self.assertEqual(test_object.one, 'one0') @@ -483,10 +483,10 @@ class UsingFactoryTestCase(unittest.TestCase): @factory.lazy_attribute_sequence def one(a, n): - return 'one' + n + return 'one%d' % n @factory.lazy_attribute_sequence def two(a, n): - return a.one + ' two' + n + return a.one + ' two%d' % n test_object = TestObjectFactory.build() self.assertEqual(test_object.one, 'one0') @@ -496,8 +496,8 @@ class UsingFactoryTestCase(unittest.TestCase): class TestObjectFactory(factory.Factory): FACTORY_FOR = TestObject - one = factory.Sequence(lambda n: 'one' + n) - two = factory.Sequence(lambda n: 'two' + n) + one = factory.Sequence(lambda n: 'one%d' % n) + two = factory.Sequence(lambda n: 'two%d' % n) test_object0 = TestObjectFactory.build(three='three') self.assertEqual(test_object0.one, 'one0') @@ -673,7 +673,7 @@ class UsingFactoryTestCase(unittest.TestCase): three = factory.Sequence(lambda n: int(n)) objs = TestObjectFactory.stub_batch(20, - one=factory.Sequence(lambda n: n)) + one=factory.Sequence(lambda n: str(n))) self.assertEqual(20, len(objs)) self.assertEqual(20, len(set(objs))) @@ -862,7 +862,7 @@ class SubFactoryTestCase(unittest.TestCase): class TestModel2Factory(FakeModelFactory): FACTORY_FOR = TestModel2 two = factory.SubFactory(TestModelFactory, - one=factory.Sequence(lambda n: 'x%sx' % n), + one=factory.Sequence(lambda n: 'x%dx' % n), two=factory.LazyAttribute( lambda o: '%s%s' % (o.one, o.one))) |