Run pydal's tests inside web2py using contrib adapters
This commit is contained in:
@@ -18,6 +18,10 @@ before_script:
|
|||||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install --download-cache $HOME/.pip-cache unittest2; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install --download-cache $HOME/.pip-cache unittest2; fi
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache coverage; fi;
|
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache coverage; fi;
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache codecov; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache codecov; fi
|
||||||
|
- mysql -e 'create database pydal;'
|
||||||
|
- psql -c 'create database pydal;' -U postgres
|
||||||
|
- psql -c 'create extension postgis;' -U postgres -d pydal;
|
||||||
|
- psql -c 'SHOW SERVER_VERSION' -U postgres
|
||||||
|
|
||||||
|
|
||||||
script: export COVERAGE_PROCESS_START=gluon/tests/coverage.ini; ./web2py.py --run_system_tests --with_coverage
|
script: export COVERAGE_PROCESS_START=gluon/tests/coverage.ini; ./web2py.py --run_system_tests --with_coverage
|
||||||
@@ -28,3 +32,6 @@ after_success:
|
|||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: true
|
email: true
|
||||||
|
|
||||||
|
addons:
|
||||||
|
postgresql: "9.4"
|
||||||
|
|||||||
+65
-1
@@ -4,15 +4,16 @@
|
|||||||
Unit tests for gluon.dal
|
Unit tests for gluon.dal
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from fix_path import fix_sys_path
|
from fix_path import fix_sys_path
|
||||||
|
|
||||||
fix_sys_path(__file__)
|
fix_sys_path(__file__)
|
||||||
|
|
||||||
|
|
||||||
from gluon.dal import DAL, Field
|
from gluon.dal import DAL, Field
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
try:
|
try:
|
||||||
os.unlink('dummy.db')
|
os.unlink('dummy.db')
|
||||||
@@ -50,6 +51,69 @@ class TestDefaultValidators(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def _prepare_exec_for_file(filename):
|
||||||
|
module = []
|
||||||
|
if filename.endswith('.py'):
|
||||||
|
filename = filename[:-3]
|
||||||
|
elif os.path.split(filename)[1] == '__init__.py':
|
||||||
|
filename = os.path.dirname(filename)
|
||||||
|
else:
|
||||||
|
raise 'The file provided (%s) does is not a valid Python file.'
|
||||||
|
filename = os.path.realpath(filename)
|
||||||
|
dirpath = filename
|
||||||
|
while 1:
|
||||||
|
dirpath, extra = os.path.split(dirpath)
|
||||||
|
module.append(extra)
|
||||||
|
if not os.path.isfile(os.path.join(dirpath, '__init__.py')):
|
||||||
|
break
|
||||||
|
sys.path.insert(0, dirpath)
|
||||||
|
return '.'.join(module[::-1])
|
||||||
|
|
||||||
|
|
||||||
|
def load_pydal_tests_module():
|
||||||
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
if not os.path.isfile(os.path.join(path, 'web2py.py')):
|
||||||
|
i = 0
|
||||||
|
while i < 10:
|
||||||
|
i += 1
|
||||||
|
if os.path.exists(os.path.join(path, 'web2py.py')):
|
||||||
|
break
|
||||||
|
path = os.path.abspath(os.path.join(path, '..'))
|
||||||
|
pydal_test_path = os.path.join(
|
||||||
|
path, "gluon", "packages", "dal", "tests", "__init__.py")
|
||||||
|
mname = _prepare_exec_for_file(pydal_test_path)
|
||||||
|
mod = __import__(mname)
|
||||||
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
def pydal_suite():
|
||||||
|
mod = load_pydal_tests_module()
|
||||||
|
suite = unittest.TestSuite()
|
||||||
|
tlist = [
|
||||||
|
getattr(mod, el) for el in mod.__dict__.keys() if el.startswith("Test")
|
||||||
|
]
|
||||||
|
for t in tlist:
|
||||||
|
suite.addTest(unittest.makeSuite(t))
|
||||||
|
return suite
|
||||||
|
|
||||||
|
|
||||||
|
class TestDALAdapters(unittest.TestCase):
|
||||||
|
def _run_tests(self):
|
||||||
|
suite = pydal_suite()
|
||||||
|
return unittest.TextTestRunner(verbosity=2).run(suite)
|
||||||
|
|
||||||
|
def test_mysql(self):
|
||||||
|
os.environ["DB"] = "mysql://root:@localhost/pydal"
|
||||||
|
result = self._run_tests()
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
def test_pg8000(self):
|
||||||
|
os.environ["DB"] = "postgres:pg8000://postgres:@localhost/pydal"
|
||||||
|
result = self._run_tests()
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
tearDownModule()
|
tearDownModule()
|
||||||
|
|||||||
Reference in New Issue
Block a user