summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--factory/compat.py8
-rw-r--r--factory/fuzzy.py2
-rw-r--r--tests/alter_time.py4
-rw-r--r--tests/compat.py8
-rw-r--r--tests/test_base.py4
-rw-r--r--tests/test_containers.py2
-rw-r--r--tests/test_declarations.py2
-rw-r--r--tests/test_django.py8
-rw-r--r--tests/test_using.py140
-rw-r--r--tests/utils.py2
11 files changed, 95 insertions, 95 deletions
diff --git a/Makefile b/Makefile
index 274ee32..6e798c9 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@ PACKAGE=factory
TESTS_DIR=tests
DOC_DIR=docs
+# Use current python binary instead of system default.
+COVERAGE = python $(shell which coverage)
all: default
@@ -20,10 +22,10 @@ pylint:
pylint --rcfile=.pylintrc --report=no $(PACKAGE)/
coverage:
- coverage erase
- coverage run "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py" --branch setup.py test
- coverage report "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py"
- coverage html "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py"
+ $(COVERAGE) erase
+ $(COVERAGE) run "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py" --branch setup.py test
+ $(COVERAGE) report "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py"
+ $(COVERAGE) html "--include=$(PACKAGE)/*.py,$(TESTS_DIR)/*.py"
doc:
$(MAKE) -C $(DOC_DIR) html
diff --git a/factory/compat.py b/factory/compat.py
index 9594550..7c9b845 100644
--- a/factory/compat.py
+++ b/factory/compat.py
@@ -28,17 +28,17 @@ import sys
PY2 = (sys.version_info[0] == 2)
-if PY2:
+if PY2: # pragma: no cover
def is_string(obj):
return isinstance(obj, (str, unicode))
-else:
+else: # pragma: no cover
def is_string(obj):
return isinstance(obj, str)
-try:
+try: # pragma: no cover
# Python >= 3.2
UTC = datetime.timezone.utc
-except AttributeError:
+except AttributeError: # pragma: no cover
try:
# Fallback to pytz
from pytz import UTC
diff --git a/factory/fuzzy.py b/factory/fuzzy.py
index e266b93..d3b130b 100644
--- a/factory/fuzzy.py
+++ b/factory/fuzzy.py
@@ -37,7 +37,7 @@ class BaseFuzzyAttribute(declarations.OrderedDeclaration):
Custom fuzzers should override the `fuzz()` method.
"""
- def fuzz(self):
+ def fuzz(self): # pragma: no cover
raise NotImplementedError()
def evaluate(self, sequence, obj, create, extra=None, containers=()):
diff --git a/tests/alter_time.py b/tests/alter_time.py
index f426e03..db0a611 100644
--- a/tests/alter_time.py
+++ b/tests/alter_time.py
@@ -82,7 +82,7 @@ def mock_date_today(target, datetime_module):
return mock.patch.object(datetime_module, 'date', MockedDate)
-def main():
+def main(): # pragma: no cover
"""Run a couple of tests"""
target_dt = real_datetime_class(2009, 1, 1)
target_date = real_date_class(2009, 1, 1)
@@ -109,5 +109,5 @@ def main():
print("- isinstance(target, date) ->", isinstance(target_date, datetime.date))
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
main()
diff --git a/tests/compat.py b/tests/compat.py
index 6a1eb80..f11076c 100644
--- a/tests/compat.py
+++ b/tests/compat.py
@@ -25,13 +25,13 @@ import sys
is_python2 = (sys.version_info[0] == 2)
-try:
+if sys.version_info[0:2] < (2, 7): # pragma: no cover
import unittest2 as unittest
-except ImportError:
+else: # pragma: no cover
import unittest
-if sys.version_info[0:2] < (3, 3):
+if sys.version_info[0:2] < (3, 3): # pragma: no cover
import mock
-else:
+else: # pragma: no cover
from unittest import mock
diff --git a/tests/test_base.py b/tests/test_base.py
index 4978d10..8ac2f44 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -321,7 +321,7 @@ class FactoryCreationTestCase(unittest.TestCase):
try:
class Test(base.Factory):
pass
- self.fail()
+ self.fail() # pragma: no cover
except base.Factory.AssociatedClassError as e:
self.assertTrue('autodiscovery' not in str(e))
@@ -348,5 +348,5 @@ class PostGenerationParsingTestCase(unittest.TestCase):
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
unittest.main()
diff --git a/tests/test_containers.py b/tests/test_containers.py
index 75e3237..8b78dc7 100644
--- a/tests/test_containers.py
+++ b/tests/test_containers.py
@@ -359,5 +359,5 @@ class AttributeBuilderTestCase(unittest.TestCase):
pass
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
unittest.main()
diff --git a/tests/test_declarations.py b/tests/test_declarations.py
index 7e7c2fb..86bc8b5 100644
--- a/tests/test_declarations.py
+++ b/tests/test_declarations.py
@@ -296,5 +296,5 @@ class PostGenerationMethodCallTestCase(unittest.TestCase):
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
unittest.main()
diff --git a/tests/test_django.py b/tests/test_django.py
index aacde76..70bc376 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -28,7 +28,7 @@ import factory.django
try:
import django
-except ImportError:
+except ImportError: # pragma: no cover
django = None
@@ -43,7 +43,7 @@ if django is not None:
from django.test import simple as django_test_simple
from django.test import utils as django_test_utils
from .djapp import models
-else:
+else: # pragma: no cover
django_test = unittest
class Fake(object):
@@ -58,7 +58,7 @@ test_state = {}
def setUpModule():
- if django is None:
+ if django is None: # pragma: no cover
return
django_test_utils.setup_test_environment()
runner = django_test_simple.DjangoTestSuiteRunner()
@@ -70,7 +70,7 @@ def setUpModule():
def tearDownModule():
- if django is None:
+ if django is None: # pragma: no cover
return
runner = test_state['runner']
runner_state = test_state['runner_state']
diff --git a/tests/test_using.py b/tests/test_using.py
index db65002..0898a13 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -299,7 +299,7 @@ class UsingFactoryTestCase(unittest.TestCase):
test_object = TestObjectFactory.build()
self.assertEqual(test_object.one, 'one')
- def test_inheritance(self):
+ def test_inheriting_target_class(self):
@factory.use_strategy(factory.BUILD_STRATEGY)
class TestObjectFactory(factory.Factory, TestObject):
FACTORY_FOR = TestObject
@@ -1253,7 +1253,7 @@ class IteratorTestCase(unittest.TestCase):
@factory.iterator
def one():
- for i in range(10, 50):
+ for i in range(10, 50): # pragma: no cover
yield i
objs = TestObjectFactory.build_batch(20)
@@ -1389,6 +1389,72 @@ class DjangoModelFactoryTestCase(unittest.TestCase):
self.assertEqual(4, obj.z)
self.assertEqual(2, obj.id)
+ def test_sequence(self):
+ class TestModelFactory(factory.django.DjangoModelFactory):
+ FACTORY_FOR = TestModel
+
+ a = factory.Sequence(lambda n: 'foo_%s' % n)
+
+ o1 = TestModelFactory()
+ o2 = TestModelFactory()
+
+ self.assertEqual('foo_2', o1.a)
+ self.assertEqual('foo_3', o2.a)
+
+ o3 = TestModelFactory.build()
+ o4 = TestModelFactory.build()
+
+ self.assertEqual('foo_4', o3.a)
+ self.assertEqual('foo_5', o4.a)
+
+ def test_no_get_or_create(self):
+ class TestModelFactory(factory.django.DjangoModelFactory):
+ FACTORY_FOR = TestModel
+
+ a = factory.Sequence(lambda n: 'foo_%s' % n)
+
+ o = TestModelFactory()
+ self.assertEqual(None, o._defaults)
+ self.assertEqual('foo_2', o.a)
+ self.assertEqual(2, o.id)
+
+ def test_get_or_create(self):
+ class TestModelFactory(factory.django.DjangoModelFactory):
+ FACTORY_FOR = TestModel
+ FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b')
+
+ a = factory.Sequence(lambda n: 'foo_%s' % n)
+ b = 2
+ c = 3
+ d = 4
+
+ o = TestModelFactory()
+ self.assertEqual({'c': 3, 'd': 4}, o._defaults)
+ self.assertEqual('foo_2', o.a)
+ self.assertEqual(2, o.b)
+ self.assertEqual(3, o.c)
+ self.assertEqual(4, o.d)
+ self.assertEqual(2, o.id)
+
+ def test_full_get_or_create(self):
+ """Test a DjangoModelFactory with all fields in get_or_create."""
+ class TestModelFactory(factory.django.DjangoModelFactory):
+ FACTORY_FOR = TestModel
+ FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b', 'c', 'd')
+
+ a = factory.Sequence(lambda n: 'foo_%s' % n)
+ b = 2
+ c = 3
+ d = 4
+
+ o = TestModelFactory()
+ self.assertEqual({}, o._defaults)
+ self.assertEqual('foo_2', o.a)
+ self.assertEqual(2, o.b)
+ self.assertEqual(3, o.c)
+ self.assertEqual(4, o.d)
+ self.assertEqual(2, o.id)
+
class PostGenerationTestCase(unittest.TestCase):
def test_post_generation(self):
@@ -1806,73 +1872,5 @@ class ListTestCase(unittest.TestCase):
], o.two)
-class DjangoModelFactoryTestCase(unittest.TestCase):
- def test_sequence(self):
- class TestModelFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = TestModel
-
- a = factory.Sequence(lambda n: 'foo_%s' % n)
-
- o1 = TestModelFactory()
- o2 = TestModelFactory()
-
- self.assertEqual('foo_2', o1.a)
- self.assertEqual('foo_3', o2.a)
-
- o3 = TestModelFactory.build()
- o4 = TestModelFactory.build()
-
- self.assertEqual('foo_4', o3.a)
- self.assertEqual('foo_5', o4.a)
-
- def test_no_get_or_create(self):
- class TestModelFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = TestModel
-
- a = factory.Sequence(lambda n: 'foo_%s' % n)
-
- o = TestModelFactory()
- self.assertEqual(None, o._defaults)
- self.assertEqual('foo_2', o.a)
- self.assertEqual(2, o.id)
-
- def test_get_or_create(self):
- class TestModelFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = TestModel
- FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b')
-
- a = factory.Sequence(lambda n: 'foo_%s' % n)
- b = 2
- c = 3
- d = 4
-
- o = TestModelFactory()
- self.assertEqual({'c': 3, 'd': 4}, o._defaults)
- self.assertEqual('foo_2', o.a)
- self.assertEqual(2, o.b)
- self.assertEqual(3, o.c)
- self.assertEqual(4, o.d)
- self.assertEqual(2, o.id)
-
- def test_full_get_or_create(self):
- """Test a DjangoModelFactory with all fields in get_or_create."""
- class TestModelFactory(factory.django.DjangoModelFactory):
- FACTORY_FOR = TestModel
- FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b', 'c', 'd')
-
- a = factory.Sequence(lambda n: 'foo_%s' % n)
- b = 2
- c = 3
- d = 4
-
- o = TestModelFactory()
- self.assertEqual({}, o._defaults)
- self.assertEqual('foo_2', o.a)
- self.assertEqual(2, o.b)
- self.assertEqual(3, o.c)
- self.assertEqual(4, o.d)
- self.assertEqual(2, o.id)
-
-
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
unittest.main()
diff --git a/tests/utils.py b/tests/utils.py
index 0111df3..215fc83 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -33,7 +33,7 @@ class MultiModulePatcher(object):
super(MultiModulePatcher, self).__init__(**kwargs)
self.patchers = [self._build_patcher(mod) for mod in target_modules]
- def _build_patcher(self, target_module):
+ def _build_patcher(self, target_module): # pragma: no cover
"""Build a mock patcher for the target module."""
raise NotImplementedError()