Skip to content
Permalink
Browse files

Pytest (#67)

* Updated travis configuration to run pytest

* Push coverage to coveralls.io

* Removed nose

* all dependencies of nose was removed, the goal is to migrate to pytest

* adding conftest

* Flake 8 compiliant

* Refactor anyblok_nose, Raise an exception
  • Loading branch information...
jssuzanne committed Jun 21, 2019
1 parent cf2f484 commit 7aa2abb50b226ae82314f88441a0f36525d8f4b6
Showing with 5,605 additions and 4,627 deletions.
  1. +2 −0 .gitignore
  2. +5 −7 .travis.yml
  3. +22 −16 anyblok/bloks/anyblok_core/tests/test_core_base.py
  4. +46 −36 anyblok/bloks/anyblok_core/tests/test_core_query.py
  5. +62 −51 anyblok/bloks/anyblok_core/tests/test_core_sql_base.py
  6. +15 −10 anyblok/bloks/anyblok_core/tests/test_documentation.py
  7. +11 −8 anyblok/bloks/anyblok_core/tests/test_system_blok.py
  8. +44 −35 anyblok/bloks/anyblok_core/tests/test_system_params.py
  9. +43 −34 anyblok/bloks/anyblok_core/tests/test_system_sequence.py
  10. +1 −8 anyblok/config.py
  11. +65 −0 anyblok/conftest.py
  12. +6 −5 anyblok/migration.py
  13. +4 −46 anyblok/registry.py
  14. +9 −42 anyblok/scripts.py
  15. +582 −0 anyblok/testing.py
  16. +1 −22 anyblok/tests/__init__.py
  17. +144 −0 anyblok/tests/conftest.py
  18. +64 −76 anyblok/tests/test_authorization.py
  19. +466 −481 anyblok/tests/test_blok.py
  20. +63 −0 anyblok/tests/test_blok_manager.py
  21. +204 −115 anyblok/tests/test_cache.py
  22. +265 −257 anyblok/tests/test_column.py
  23. +154 −158 anyblok/tests/test_config.py
  24. +24 −18 anyblok/tests/test_core.py
  25. +24 −3 anyblok/tests/test_core_query.py
  26. +554 −479 anyblok/tests/test_core_sqlbase.py
  27. +14 −11 anyblok/tests/test_declaration.py
  28. +16 −15 anyblok/tests/test_environment.py
  29. +72 −48 anyblok/tests/test_event.py
  30. +240 −188 anyblok/tests/test_field.py
  31. +6 −7 anyblok/tests/test_graphviz.py
  32. +26 −12 anyblok/tests/test_hybrid_method.py
  33. +41 −41 anyblok/tests/test_imp.py
  34. +34 −24 anyblok/tests/test_inherit.py
  35. +43 −20 anyblok/tests/test_instrumented_list.py
  36. +168 −141 anyblok/tests/test_many2many.py
  37. +163 −140 anyblok/tests/test_many2one.py
  38. +175 −145 anyblok/tests/test_mapper.py
  39. +542 −521 anyblok/tests/test_migration.py
  40. +17 −19 anyblok/tests/test_mixin.py
  41. +62 −53 anyblok/tests/test_model.py
  42. +118 −75 anyblok/tests/test_one2many.py
  43. +141 −102 anyblok/tests/test_one2one.py
  44. +262 −138 anyblok/tests/test_polymorphic.py
  45. +121 −87 anyblok/tests/test_registry.py
  46. +22 −21 anyblok/tests/test_registry_core.py
  47. +25 −24 anyblok/tests/test_registry_entry.py
  48. +63 −69 anyblok/tests/test_registry_manager.py
  49. +93 −85 anyblok/tests/test_relationship.py
  50. +20 −21 anyblok/tests/test_version.py
  51. +199 −153 anyblok/tests/test_view.py
  52. +6 −543 anyblok/tests/testcase.py
  53. +14 −0 doc/CHANGES.rst
  54. +8 −10 doc/FRONT.rst
  55. +1 −5 doc/basic_usage.rst
  56. +8 −0 requirements.dev.txt
  57. +2 −2 setup.py
  58. +3 −0 tox.ini
@@ -19,7 +19,9 @@ doc/_build
parts/
bin/
etc/
venv/
develop-eggs/
htmlcov/

gmon.out
.idea
@@ -35,7 +35,6 @@ matrix:
- python: "3.5"
env: ANYBLOK_DATABASE_DRIVER=mysql ANYBLOK_DATABASE_USER=travis SQLSERVER='mysql -e'


virtualenv:
system_site_packages: false

@@ -50,9 +49,9 @@ before_install:
install:
- pip install -U pip
- pip install wheel
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy3.5' ]]; then pip install psycopg2cffi; else pip install psycopg2; fi
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy3.5' ]]; then pip install psycopg2cffi; else pip install psycopg2-binary; fi
- pip install sqlalchemy mysqlclient
- pip install flake8 coverage nose
- pip install -U flake8 coverage pytest pytest-cov
- pip install colour passlib furl phonenumbers pycountry # special columns
- pip install coveralls
- pip install -U cryptography
@@ -63,11 +62,10 @@ script:
- flake8 anyblok --exclude=*/tests/*
- python3 update_env.py
- $SQLSERVER 'create database travis_ci_test;'
- nosetests anyblok/tests -v -s --with-coverage --cover-package=anyblok
- py.test --cov-report= --cov=anyblok anyblok/tests
- $SQLSERVER 'drop database travis_ci_test;'
- anyblok_createdb --install-all-bloks
- if [[ $ANYBLOK_DATABASE_DRIVER == 'postgresql' ]]; then nosetests anyblok/bloks --with-anyblok-bloks -v -s --with-coverage --cover-package=anyblok; fi
- anyblok_nose -- -v -s --with-coverage --cover-package=anyblok # test runner
- py.test --cov-report= --cov=anyblok anyblok/bloks

after_success:
coveralls
coveralls --data_file=.coverage --config_file=.coveragerc
@@ -1,30 +1,36 @@
# This file is a part of the AnyBlok project
#
# Copyright (C) 2014 Jean-Sebastien SUZANNE <jssuzanne@anybox.fr>
# Copyright (C) 2018 Denis VIVIÈS <dvivies@geoblink.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok.tests.testcase import BlokTestCase
from ..exceptions import CoreBaseException
import pytest

from ..exceptions import CoreBaseException

class TestCoreBase(BlokTestCase):

def test_to_primary_keys(self):
with self.assertRaises(CoreBaseException):
test = self.registry.System()
@pytest.mark.usefixtures('rollback_registry')
class TestCoreBaseScope:
def test_to_primary_keys(self, rollback_registry):
registry = rollback_registry
with pytest.raises(CoreBaseException):
test = registry.System()
test.to_primary_keys()

def test_from_primary_keys(self):
with self.assertRaises(CoreBaseException):
self.registry.System.from_primary_keys()
def test_from_primary_keys(self, rollback_registry):
registry = rollback_registry
with pytest.raises(CoreBaseException):
registry.System.from_primary_keys()

def test_get_primary_keys(self):
with self.assertRaises(CoreBaseException):
self.registry.System.get_primary_keys()
def test_get_primary_keys(self, rollback_registry):
registry = rollback_registry
with pytest.raises(CoreBaseException):
registry.System.get_primary_keys()

def test_get_model(self):
M = self.registry.System.Model
M2 = self.registry.System.get_model('Model.System.Model')
self.assertEqual(M, M2)
def test_get_model(self, rollback_registry):
registry = rollback_registry
m = registry.System.Model
m2 = registry.System.get_model('Model.System.Model')
assert m == m2
@@ -1,74 +1,82 @@
# This file is a part of the AnyBlok project
#
# Copyright (C) 2015 Jean-Sebastien SUZANNE <jssuzanne@anybox.fr>
# Copyright (C) 2015 Denis VIVIÈS <dvivies@geoblink.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok.tests.testcase import BlokTestCase
import pytest


class TestQuery(BlokTestCase):

def test_dictone(self):
query = self.registry.System.Model.query().filter_by(
@pytest.mark.usefixtures('rollback_registry')
class TestQueryScope:
def test_dictone(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query().filter_by(
name='Model.System.Blok')
model = query.one()
self.assertEqual(query.dictone(), {
assert query.dictone() == {
'name': model.name,
'table': model.table,
'is_sql_model': model.is_sql_model,
'description': model.description,
})
}

def test_dictone_on_some_column(self):
query = self.registry.System.Model.query('name', 'table').filter_by(
def test_dictone_on_some_column(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query('name', 'table').filter_by(
name='Model.System.Blok')
model = query.one()
self.assertEqual(query.dictone(), {
assert query.dictone() == {
'name': model.name,
'table': model.table,
})
}

def test_dictone_on_some_column_with_label(self):
M = self.registry.System.Model
def test_dictone_on_some_column_with_label(self, rollback_registry):
registry = rollback_registry
M = registry.System.Model
query = M.query(M.name.label('n2'), M.table.label('t2')).filter_by(
name='Model.System.Blok')
model = query.one()
self.assertEqual(query.dictone(), {
assert query.dictone() == {
'n2': model.n2,
't2': model.t2,
})
}

def test_dictfirst(self):
query = self.registry.System.Model.query()
def test_dictfirst(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query()
model = query.first()
self.assertEqual(query.dictfirst(), {
assert query.dictfirst() == {
'name': model.name,
'table': model.table,
'is_sql_model': model.is_sql_model,
'description': model.description,
})
}

def test_dictfirst_on_some_column(self):
query = self.registry.System.Model.query('name', 'table')
def test_dictfirst_on_some_column(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query('name', 'table')
model = query.first()
self.assertEqual(query.dictfirst(), {
assert query.dictfirst() == {
'name': model.name,
'table': model.table,
})
}

def test_dictfirst_on_some_column_with_label(self):
M = self.registry.System.Model
def test_dictfirst_on_some_column_with_label(self, rollback_registry):
registry = rollback_registry
M = registry.System.Model
query = M.query(M.name.label('n2'), M.table.label('t2'))
model = query.first()
self.assertEqual(query.dictfirst(), {
assert query.dictfirst() == {
'n2': model.n2,
't2': model.t2,
})
}

def test_dictall(self):
query = self.registry.System.Model.query().limit(2)
def test_dictall(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query().limit(2)
models = query.all()

def to_dict(model):
@@ -81,10 +89,11 @@ def to_dict(model):

dictall = query.dictall()
for i in range(2):
self.assertIn(to_dict(models[i]), dictall)
assert to_dict(models[i]) in dictall

def test_dictall_on_some_column(self):
query = self.registry.System.Model.query('name', 'table').limit(2)
def test_dictall_on_some_column(self, rollback_registry):
registry = rollback_registry
query = registry.System.Model.query('name', 'table').limit(2)
models = query.all()

def to_dict(model):
@@ -95,10 +104,11 @@ def to_dict(model):

dictall = query.dictall()
for i in range(2):
self.assertIn(to_dict(models[i]), dictall)
assert to_dict(models[i]) in dictall

def test_dictall_on_some_column_with_label(self):
M = self.registry.System.Model
def test_dictall_on_some_column_with_label(self, rollback_registry):
registry = rollback_registry
M = registry.System.Model
query = M.query(M.name.label('n2'), M.table.label('t2')).limit(2)
models = query.all()

@@ -110,4 +120,4 @@ def to_dict(model):

dictall = query.dictall()
for i in range(2):
self.assertIn(to_dict(models[i]), dictall)
assert to_dict(models[i]) in dictall

0 comments on commit 7aa2abb

Please sign in to comment.
You can’t perform that action at this time.