summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml12
-rw-r--r--README2
-rw-r--r--docs/changelog.rst2
-rw-r--r--factory/base.py2
-rw-r--r--factory/compat.py33
-rw-r--r--factory/containers.py4
-rw-r--r--factory/declarations.py7
-rw-r--r--factory/utils.py3
-rwxr-xr-xsetup.py3
-rw-r--r--tests/compat.py2
10 files changed, 58 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml
index aa990e6..e32214b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,17 @@
language: python
+
python:
- "2.6"
- "2.7"
-script: "python setup.py test"
-install: "if [[ $TRAVIS_PYTHON_VERSION = 2.6 ]]; then pip install unittest2 --use-mirrors; fi"
+ - "3.2"
+ - "3.3"
+
+script:
+ - python setup.py test
+
+install:
+ - "if [[ $TRAVIS_PYTHON_VERSION = 2.6 ]]; then pip install unittest2 --use-mirrors; fi"
+
notifications:
email: false
irc: "irc.freenode.org#factory_boy"
diff --git a/README b/README
index a3fa2e4..a4629af 100644
--- a/README
+++ b/README
@@ -22,7 +22,7 @@ Links
* Official repository: https://github.com/rbarrois/factory_boy
* Package: https://pypi.python.org/pypi/factory_boy/
-factory_boy supports Python 2.6 and 2.7 (Python 3 is in the works), and requires only the standard Python library.
+factory_boy supports Python 2.6, 2.7, 3.2 and 3.3; and requires only the standard Python library.
Download
diff --git a/docs/changelog.rst b/docs/changelog.rst
index b73e33b..695670f 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -9,7 +9,7 @@ ChangeLog
*New:*
- Allow overriding the base factory class for :func:`~factory.make_factory` and friends.
- - Add support for Python3
+ - 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`
*Removed:*
diff --git a/factory/base.py b/factory/base.py
index f3d5eab..ff3e558 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -24,7 +24,7 @@ import re
import sys
import warnings
-from factory import containers
+from . import containers
# Strategies
BUILD_STRATEGY = 'build'
diff --git a/factory/compat.py b/factory/compat.py
new file mode 100644
index 0000000..a924de0
--- /dev/null
+++ b/factory/compat.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2010 Mark Sandstrom
+# Copyright (c) 2011-2013 Raphaƫl Barrois
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+
+"""Compatibility tools"""
+
+import sys
+
+is_python2 = (sys.version_info[0] == 2)
+
+if is_python2:
+ string_types = (str, unicode)
+else:
+ string_types = (str,)
diff --git a/factory/containers.py b/factory/containers.py
index 31ee58b..0859a10 100644
--- a/factory/containers.py
+++ b/factory/containers.py
@@ -21,8 +21,8 @@
# THE SOFTWARE.
-from factory import declarations
-from factory import utils
+from . import declarations
+from . import utils
class CyclicDefinitionError(Exception):
diff --git a/factory/declarations.py b/factory/declarations.py
index b491bfb..2b1fc05 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -25,7 +25,8 @@ import collections
import itertools
import warnings
-from factory import utils
+from . import compat
+from . import utils
class OrderedDeclaration(object):
@@ -294,7 +295,7 @@ class SubFactory(ParameteredAttribute):
self.factory_module = self.factory_name = ''
else:
# Must be a string
- if not isinstance(factory, basestring) or '.' not in factory:
+ if not isinstance(factory, compat.string_types) or '.' not in factory:
raise ValueError(
"The argument of a SubFactory must be either a class "
"or the fully qualified path to a Factory class; got "
@@ -393,7 +394,7 @@ class RelatedFactory(PostGenerationDeclaration):
self.factory_module = self.factory_name = ''
else:
# Must be a string
- if not isinstance(factory, basestring) or '.' not in factory:
+ if not isinstance(factory, compat.string_types) or '.' not in factory:
raise ValueError(
"The argument of a SubFactory must be either a class "
"or the fully qualified path to a Factory class; got "
diff --git a/factory/utils.py b/factory/utils.py
index 90fdfc3..fb8cfef 100644
--- a/factory/utils.py
+++ b/factory/utils.py
@@ -43,7 +43,8 @@ def extract_dict(prefix, kwargs, pop=True, exclude=()):
"""
prefix = prefix + ATTR_SPLITTER
extracted = {}
- for key in kwargs.keys():
+
+ for key in list(kwargs):
if key in exclude:
continue
diff --git a/setup.py b/setup.py
index ef3da96..1cb2e91 100755
--- a/setup.py
+++ b/setup.py
@@ -87,6 +87,9 @@ setup(
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
+ 'Programming Language :: Python :: 3.3',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Libraries :: Python Modules'
],
diff --git a/tests/compat.py b/tests/compat.py
index 769ffd4..6a1eb80 100644
--- a/tests/compat.py
+++ b/tests/compat.py
@@ -30,7 +30,7 @@ try:
except ImportError:
import unittest
-if is_python2:
+if sys.version_info[0:2] < (3, 3):
import mock
else:
from unittest import mock