Compare commits
8 Commits
field-choi
...
container-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1178ae262b | ||
|
|
4c629e46ce | ||
|
|
2d429e3703 | ||
|
|
06cb866f82 | ||
|
|
e9caaa916c | ||
|
|
4e91c4f5bc | ||
|
|
4068a6b36b | ||
|
|
d096d2ec38 |
54
.travis.yml
54
.travis.yml
@@ -1,3 +1,6 @@
|
|||||||
|
# Use a container-based environment
|
||||||
|
sudo: false
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
python:
|
python:
|
||||||
@@ -8,26 +11,41 @@ python:
|
|||||||
- pypy
|
- pypy
|
||||||
- pypy3
|
- pypy3
|
||||||
|
|
||||||
|
# Test on PyMongo v2.7.x, v2.8.x, and v3.x
|
||||||
env:
|
env:
|
||||||
- PYMONGO=2.7
|
- PYMONGO=2.7
|
||||||
- PYMONGO=2.8
|
- PYMONGO=2.8
|
||||||
- PYMONGO=3.0
|
- PYMONGO=3.0
|
||||||
- PYMONGO=dev
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
before_install:
|
services:
|
||||||
- travis_retry sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
|
- mongodb
|
||||||
- echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' |
|
|
||||||
sudo tee /etc/apt/sources.list.d/mongodb.list
|
addons:
|
||||||
- travis_retry sudo apt-get update
|
apt:
|
||||||
- travis_retry sudo apt-get install mongodb-org-server
|
sources:
|
||||||
|
- mongodb-upstart
|
||||||
|
packages:
|
||||||
|
- mongodb-org-server=2.6.9
|
||||||
|
|
||||||
|
# Optional dependencies for the ImageField and others
|
||||||
|
- python-dev
|
||||||
|
- python3-dev
|
||||||
|
- libopenjpeg-dev
|
||||||
|
- zlib1g-dev
|
||||||
|
- libjpeg-turbo8-dev
|
||||||
|
- libtiff4-dev
|
||||||
|
- libjpeg8-dev
|
||||||
|
- libfreetype6-dev
|
||||||
|
- liblcms2-dev
|
||||||
|
- libwebp-dev
|
||||||
|
- tcl8.5-dev
|
||||||
|
- tk8.5-dev
|
||||||
|
- python-tk
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- sudo apt-get install python-dev python3-dev libopenjpeg-dev zlib1g-dev libjpeg-turbo8-dev
|
|
||||||
libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev
|
|
||||||
python-tk
|
|
||||||
- travis_retry pip install --upgrade pip
|
- travis_retry pip install --upgrade pip
|
||||||
- travis_retry pip install coveralls
|
- travis_retry pip install coveralls
|
||||||
- travis_retry pip install flake8
|
- travis_retry pip install flake8
|
||||||
@@ -35,6 +53,9 @@ install:
|
|||||||
- travis_retry pip install "virtualenv<14.0.0" # virtualenv>=14.0.0 has dropped Python 3.2 support (and pypy3 is based on py32)
|
- travis_retry pip install "virtualenv<14.0.0" # virtualenv>=14.0.0 has dropped Python 3.2 support (and pypy3 is based on py32)
|
||||||
- travis_retry tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -e test
|
- travis_retry tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -e test
|
||||||
|
|
||||||
|
# Cache dependencies installed via pip
|
||||||
|
cache: pip
|
||||||
|
|
||||||
# Run flake8 for py27
|
# Run flake8 for py27
|
||||||
before_script:
|
before_script:
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then tox -e flake8; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then tox -e flake8; fi
|
||||||
@@ -45,7 +66,7 @@ script:
|
|||||||
# For now only submit coveralls for Python v2.7. Python v3.x currently shows
|
# For now only submit coveralls for Python v2.7. Python v3.x currently shows
|
||||||
# 0% coverage. That's caused by 'use_2to3', which builds the py3-compatible
|
# 0% coverage. That's caused by 'use_2to3', which builds the py3-compatible
|
||||||
# code in a separate dir and runs tests on that.
|
# code in a separate dir and runs tests on that.
|
||||||
after_script:
|
after_success:
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then coveralls --verbose; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then coveralls --verbose; fi
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
@@ -56,11 +77,22 @@ branches:
|
|||||||
- master
|
- master
|
||||||
- /^v.*$/
|
- /^v.*$/
|
||||||
|
|
||||||
|
# Whenever a new release is created via GitHub, publish it on PyPI.
|
||||||
deploy:
|
deploy:
|
||||||
provider: pypi
|
provider: pypi
|
||||||
user: the_drow
|
user: the_drow
|
||||||
password:
|
password:
|
||||||
secure: QMyatmWBnC6ZN3XLW2+fTBDU4LQcp1m/LjR2/0uamyeUzWKdlOoh/Wx5elOgLwt/8N9ppdPeG83ose1jOz69l5G0MUMjv8n/RIcMFSpCT59tGYqn3kh55b0cIZXFT9ar+5cxlif6a5rS72IHm5li7QQyxexJIII6Uxp0kpvUmek=
|
secure: QMyatmWBnC6ZN3XLW2+fTBDU4LQcp1m/LjR2/0uamyeUzWKdlOoh/Wx5elOgLwt/8N9ppdPeG83ose1jOz69l5G0MUMjv8n/RIcMFSpCT59tGYqn3kh55b0cIZXFT9ar+5cxlif6a5rS72IHm5li7QQyxexJIII6Uxp0kpvUmek=
|
||||||
|
|
||||||
|
# create a source distribution and a pure python wheel for faster installs
|
||||||
|
distributions: "sdist bdist_wheel"
|
||||||
|
|
||||||
|
# only deploy on tagged commits (aka GitHub releases) and only for the
|
||||||
|
# parent repo's builds running Python 2.7 along with dev PyMongo (we run
|
||||||
|
# Travis against many different Python and PyMongo versions and we don't
|
||||||
|
# want the deploy to occur multiple times).
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
repo: MongoEngine/mongoengine
|
repo: MongoEngine/mongoengine
|
||||||
|
condition: "$PYMONGO = 3.0"
|
||||||
|
python: 2.7
|
||||||
|
|||||||
@@ -189,18 +189,14 @@ class BaseField(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _validate_choices(self, value):
|
def _validate_choices(self, value):
|
||||||
"""Validate that value is a valid choice for this field."""
|
|
||||||
Document = _import_class('Document')
|
Document = _import_class('Document')
|
||||||
EmbeddedDocument = _import_class('EmbeddedDocument')
|
EmbeddedDocument = _import_class('EmbeddedDocument')
|
||||||
|
|
||||||
# Field choices can be given as an iterable (e.g. tuple/list/set) of
|
|
||||||
# values or an iterable of value-label pairs, e.g. ('XS', 'Extra Small').
|
|
||||||
# It the latter case, extract just the values for comparison.
|
|
||||||
choice_list = self.choices
|
choice_list = self.choices
|
||||||
if isinstance(next(iter(choice_list)), (list, tuple)):
|
if isinstance(choice_list[0], (list, tuple)):
|
||||||
choice_list = [val for val, label in choice_list]
|
choice_list = [k for k, _ in choice_list]
|
||||||
|
|
||||||
# Validate Document/EmbeddedDocument choices
|
# Choices which are other types of Documents
|
||||||
if isinstance(value, (Document, EmbeddedDocument)):
|
if isinstance(value, (Document, EmbeddedDocument)):
|
||||||
if not any(isinstance(value, c) for c in choice_list):
|
if not any(isinstance(value, c) for c in choice_list):
|
||||||
self.error(
|
self.error(
|
||||||
@@ -208,8 +204,7 @@ class BaseField(object):
|
|||||||
six.text_type(choice_list)
|
six.text_type(choice_list)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# Choices which are types other than Documents
|
||||||
# Validate any other type of choices
|
|
||||||
elif value not in choice_list:
|
elif value not in choice_list:
|
||||||
self.error('Value must be one of %s' % six.text_type(choice_list))
|
self.error('Value must be one of %s' % six.text_type(choice_list))
|
||||||
|
|
||||||
|
|||||||
@@ -3205,22 +3205,8 @@ class FieldTest(unittest.TestCase):
|
|||||||
shirt.size = "XS"
|
shirt.size = "XS"
|
||||||
self.assertRaises(ValidationError, shirt.validate)
|
self.assertRaises(ValidationError, shirt.validate)
|
||||||
|
|
||||||
def test_choices_as_set(self):
|
|
||||||
"""Ensure that sets can be used as field choices"""
|
|
||||||
class Shirt(Document):
|
|
||||||
size = StringField(choices={'S', 'M', 'L', 'XL', 'XXL'})
|
|
||||||
|
|
||||||
Shirt.drop_collection()
|
Shirt.drop_collection()
|
||||||
|
|
||||||
shirt = Shirt()
|
|
||||||
shirt.validate()
|
|
||||||
|
|
||||||
shirt.size = "S"
|
|
||||||
shirt.validate()
|
|
||||||
|
|
||||||
shirt.size = "XS"
|
|
||||||
self.assertRaises(ValidationError, shirt.validate)
|
|
||||||
|
|
||||||
def test_choices_validation_documents(self):
|
def test_choices_validation_documents(self):
|
||||||
"""
|
"""
|
||||||
Ensure fields with document choices validate given a valid choice.
|
Ensure fields with document choices validate given a valid choice.
|
||||||
|
|||||||
6
tox.ini
6
tox.ini
@@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = {py26,py27,py33,py34,py35,pypy,pypy3}-{mg27,mg28},flake8
|
envlist = {py27,py33,py34,py35,pypy,pypy3}-{mg27,mg28,mg30},flake8
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands =
|
commands =
|
||||||
@@ -7,12 +7,10 @@ commands =
|
|||||||
deps =
|
deps =
|
||||||
nose
|
nose
|
||||||
mg27: PyMongo<2.8
|
mg27: PyMongo<2.8
|
||||||
mg28: PyMongo>=2.8,<3.0
|
mg28: PyMongo>=2.8,<2.9
|
||||||
mg30: PyMongo>=3.0
|
mg30: PyMongo>=3.0
|
||||||
mgdev: https://github.com/mongodb/mongo-python-driver/tarball/master
|
|
||||||
setenv =
|
setenv =
|
||||||
PYTHON_EGG_CACHE = {envdir}/python-eggs
|
PYTHON_EGG_CACHE = {envdir}/python-eggs
|
||||||
passenv = windir
|
|
||||||
|
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
deps =
|
deps =
|
||||||
|
|||||||
Reference in New Issue
Block a user