Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
tox improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Jan 3, 2018
1 parent b6385ca commit fbc3023
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 99 deletions.
2 changes: 2 additions & 0 deletions djburger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@


def safe_model_to_dict(model):
if not is_django_installed:
return model
if isinstance(model, Model):
return model_to_dict(model)
return model
Expand Down
35 changes: 22 additions & 13 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import unittest2 as unittest


testing_type = sys.argv[1] if len(sys.argv) > 1 else ''
testing_type = ' '.join(sys.argv) if len(sys.argv) > 1 else ''


if not testing_type or testing_type in ('django', 'djside'):
try:
import django
except ImportError:
pass
else:
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/example')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup()
Expand All @@ -22,17 +25,23 @@
import djburger # noQA


from tests import main
if not testing_type or testing_type == 'django':
from tests import django
if not testing_type or testing_type == 'djside':
from tests import djside
if not testing_type or testing_type == 'rest':
from tests import rest
if not testing_type or testing_type == 'marshmallow':
from tests import marshmallow
if not testing_type or testing_type == 'pyschemes':
from tests import pyschemes
if not testing_type:
from tests.main_tests import *
from tests.django_tests import *
from tests.djside_tests import *
from tests.rest_tests import *
from tests.side_tests import *
else:
if 'main_tests' in testing_type:
from tests import main_tests
if 'django_tests' in testing_type:
from tests import django_tests
if 'djside_tests' in testing_type:
from tests import djside_tests
if 'rest_tests' in testing_type:
from tests import rest_tests
if ' side_tests' in testing_type or testing_type.startswith('side_tests'):
from tests import side_tests


if __name__ == '__main__':
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 0 additions & 36 deletions tests/marshmallow.py

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions tests/pyschemes.py → tests/side_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
# built-in
from __main__ import unittest, djburger
# external
import marshmallow
from pyschemes import Scheme as PySchemes


class MarshmallowValidatorsTest(unittest.TestCase):

def test_base_validator(self):
# BASE
class Base(djburger.v.b.Marshmallow):
name = marshmallow.fields.Str()
mail = marshmallow.fields.Email()
with self.subTest(src_text='base pass'):
data = {'name': 'John Doe', 'mail': 'test@gmail.com'}
v = Base(request=None, data=data)
self.assertTrue(v.is_valid())
with self.subTest(src_text='base not pass'):
data = {'name': 'John Doe', 'mail': 'test.gmail.com'}
v = Base(request=None, data=data)
self.assertFalse(v.is_valid())

def test_wrapper_validator(self):
class Base(marshmallow.Schema):
name = marshmallow.fields.Str()
mail = marshmallow.fields.Email()

Wrapped = djburger.v.w.Marshmallow(Base) # noQA
with self.subTest(src_text='base pass'):
data = {'name': 'John Doe', 'mail': 'test@gmail.com'}
v = Wrapped(request=None, data=data)
self.assertTrue(v.is_valid())
with self.subTest(src_text='base not pass'):
data = {'name': 'John Doe', 'mail': 'test.gmail.com'}
v = Wrapped(request=None, data=data)
self.assertFalse(v.is_valid())


class PySchemesValidatorsTest(unittest.TestCase):

def test_base_validator(self):
Expand Down
70 changes: 20 additions & 50 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,71 +1,41 @@
[tox]
envlist =
# main
py{2,3}-main,
# django
py2-django-django{18,110,111},
py3-django-django{18,110,111,20,master},
# djside
py2-djside-django{18,110,111},
py3-djside-django{18,110,111,20,master},
# side
py2-side-django{18,110,111},
py3-side-django{18,110,111,20,master},
# other
py{2,3}-{MAIN,SIDE},
py2-django{18,110,111}-{DJSIDE,DJANGO},
py3-django{18,110,111,20,master}-{DJSIDE,DJANGO},
flake8,


[testenv:main]
commands = python run_tests.py main
envdir = {toxworkdir}/venvs/{envname}
setenv =
PYTHONDONTWRITEBYTECODE=1
PYTHONWARNINGS=once
deps =
py2: unittest2
-rrequirements/main.txt


[testenv:django]
commands = python run_tests.py django
[testenv]
commands =
MAIN: python run_tests.py main_tests
SIDE: python run_tests.py side_tests
DJANGO: python run_tests.py django_tests
DJSIDE: python run_tests.py djside_tests rest_tests
envdir = {toxworkdir}/venvs/{envname}
setenv =
PYTHONDONTWRITEBYTECODE=1
PYTHONWARNINGS=once
deps =
# required
six
# django
django18: Django>=1.8,<1.9
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
django20: Django>=2.0,<2.1
djangomaster: https://github.com/django/django/archive/master.tar.gz
# testing
py2: unittest2
-rrequirements/main.txt


[testenv:djside]
commands = python run_tests.py djside
envdir = {toxworkdir}/venvs/{envname}
setenv =
PYTHONDONTWRITEBYTECODE=1
PYTHONWARNINGS=once
deps =
# rest
django{110,111,20,master}: djangorestframework
django18: djangorestframework>=3.5,<3.6
# other
DJANGO: bson
{DJANGO,DJSIDE,SIDE}: marshmallow
{DJANGO,DJSIDE,SIDE}: pyschemes
DJANGO: PyYAML
DJANGO: tablib
# testing
py2: unittest2
-rrequirements/testing-side.txt


[testenv:side]
commands = python run_tests.py marshmallow pyschemes
envdir = {toxworkdir}/venvs/{envname}
setenv =
PYTHONDONTWRITEBYTECODE=1
PYTHONWARNINGS=once
deps =
py2: unittest2
-rrequirements/testing-side.txt


[testenv:flake8]
Expand All @@ -74,5 +44,5 @@ skip_install = True
deps =
flake8
commands =
flake8 --exclude=migrations {toxinidir}/djburger
flake8 {toxinidir}/djburger

0 comments on commit fbc3023

Please sign in to comment.