diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..03f5bf1 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +# Test coverage configuration. +# Usage: +# pip install coverage +# coverage erase # clears previous data if any +# coverage run -m unittest2 +# coverage html # creates ./htmlcov/*.html (check index.html) +[run] +branch = true +source = extras_mongoengine diff --git a/.gitignore b/.gitignore index 1bbfde7..afa178a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.pyc build/ venv/ + +# Coverage +/htmlcov +/.coverage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a8a32fe --- /dev/null +++ b/.travis.yml @@ -0,0 +1,48 @@ +language: python +python: +- '2.6' +- '2.7' +- '3.2' +- '3.3' +- '3.4' +- pypy +- pypy3 +env: +- PYMONGO=2.7 +- PYMONGO=2.8 +- PYMONGO=3.0 +- PYMONGO=dev +matrix: + fast_finish: true +before_install: +# Install MongoDB +- travis_retry sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 +- echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | + sudo tee /etc/apt/sources.list.d/mongodb.list +- travis_retry sudo apt-get update +- travis_retry sudo apt-get install mongodb-org-server +install: +# 1. Install Python +- sudo apt-get install python-dev python3-dev +# 2. Install general requirements (Python packages) +- pip install -r requirements.txt +# 3. Enums in Python only became available in 3.4. +# The package `enum34` listed in `requirements-python<3.4.txt` is a backport. +- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install -r 'requirements-python<3.4.txt'; fi +- if [[ $TRAVIS_PYTHON_VERSION == 3.2* ]]; then pip install -r 'requirements-python<3.4.txt'; fi +- if [[ $TRAVIS_PYTHON_VERSION == 3.3* ]]; then pip install -r 'requirements-python<3.4.txt'; fi +- if [[ $TRAVIS_PYTHON_VERSION == pypy* ]]; then pip install -r 'requirements-python<3.4.txt'; fi +# Coverage 4.0 doesn't support Python 3.2. Install an older version +# before coveralls tries to install the latest. (pypy3 is really Python 3.2) +- if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then travis_retry pip install 'coverage<4.0'; fi +- if [[ $TRAVIS_PYTHON_VERSION == 'pypy3' ]]; then travis_retry pip install 'coverage<4.0'; fi +- travis_retry pip install tox>=1.9 coveralls +#- travis_retry tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -e test +script: +#- tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- --with-coverage +# Run tests with coverage (similar to `python -m unittest2` +# or `unit2` on Python 2.6. +- coverage run -m unittest2 +after_script: +# Submit coverage to coverall.io +- coveralls --verbose diff --git a/extras_mongoengine/__init__.py b/extras_mongoengine/__init__.py index 6a87ac0..8dc97e9 100644 --- a/extras_mongoengine/__init__.py +++ b/extras_mongoengine/__init__.py @@ -1,3 +1,7 @@ -import fields +try: + import fields +except ImportError: + # Python 3 + from . import fields __all__ = ('fields') diff --git a/extras_mongoengine/fields.py b/extras_mongoengine/fields.py index 5871ddf..e94b61e 100644 --- a/extras_mongoengine/fields.py +++ b/extras_mongoengine/fields.py @@ -12,7 +12,7 @@ class TimedeltaField(BaseField): """ def validate(self, value): if not isinstance(value, (timedelta, int, float)): - self.error(u'cannot parse timedelta "%r"' % value) + self.error(unicode('cannot parse timedelta "%r"' % value)) def to_mongo(self, value): return self.prepare_query_value(None, value) diff --git a/requirements-python<3.4.txt b/requirements-python<3.4.txt new file mode 100644 index 0000000..dc3292c --- /dev/null +++ b/requirements-python<3.4.txt @@ -0,0 +1 @@ +enum34