fix sys.path dance part #2 and scheduler tests for py3

This commit is contained in:
niphlod
2016-08-31 00:49:37 +02:00
parent 8370791b83
commit a1e1bf3500
7 changed files with 44 additions and 32 deletions

View File

@@ -4,6 +4,10 @@
- py3.5 syntax compatible (see #1353 for details)
- dropped web shell from admin
- scheduler new feature: you can now specify intervals with cron
- gluon/* removed from sys.path. Applications relying on statements like e.g.
"from storage import Storage"
will need to be rewritten with
"from gluon.storage import Storage"
- tests can only be run with the usual web2py.py --run_system_tests OR with
python -m unittest -v gluon.tests on the root dir

View File

@@ -140,7 +140,7 @@ def app_compile(app, request, skip_failed_views=False):
None if everything went ok, traceback text if errors are found
"""
from compileapp import compile_application, remove_compiled_application
from gluon.compileapp import compile_application, remove_compiled_application
folder = apath(app, request)
try:
failed_views = compile_application(folder, skip_failed_views)
@@ -442,9 +442,14 @@ def create_missing_folders():
path = abspath(path, gluon=True)
if not os.path.exists(path):
os.mkdir(path)
"""
OLD sys.path dance
paths = (global_settings.gluon_parent, abspath(
'site-packages', gluon=True), abspath('gluon', gluon=True), '')
[add_path_first(path) for path in paths]
"""
paths = (global_settings.gluon_parent, abspath(
'site-packages', gluon=True), '')
[add_path_first(path) for p in paths]
def create_missing_app_folders(request):

View File

@@ -19,7 +19,7 @@ import sched
import re
import datetime
import platform
import fileutils
import gluon.fileutils
from functools import reduce
try:
import cPickle as pickle

View File

@@ -29,7 +29,7 @@ from json import loads, dumps
from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB, IS_EMPTY_OR
from gluon import IS_INT_IN_RANGE, IS_DATETIME, IS_IN_DB
from gluon.utils import web2py_uuid
from gluon._compat import Queue, long, iteritems
from gluon._compat import Queue, long, iteritems, PY2
from gluon.storage import Storage
USAGE = """
@@ -245,7 +245,8 @@ class CronParser(object):
elif period == 'hr':
check = all(0 <= i <= 23 for i in values)
elif period == 'dom':
check = all(1 <= i <= 31 or i == 'l' for i in values)
domrange = list(range(1, 32)) + ['l']
check = all(i in domrange for i in values)
elif period == 'mon':
check = all(1 <= i <= 12 for i in values)
elif period == 'dow':
@@ -412,6 +413,8 @@ class CronParser(object):
def _decode_list(lst):
if not PY2:
return lst
newlist = []
for i in lst:
if isinstance(i, unicode):
@@ -423,6 +426,8 @@ def _decode_list(lst):
def _decode_dict(dct):
if not PY2:
return dct
newdict = {}
for k, v in iteritems(dct):
if isinstance(k, unicode):

View File

@@ -1,4 +1,3 @@
import sys
from .test_http import *
from .test_contenttype import *
@@ -22,8 +21,8 @@ from .test_compileapp import *
from .test_appadmin import *
from .test_web import *
from .test_sqlhtml import *
from .test_scheduler import *
if sys.version[:3] == '2.7':
from .test_is_url import *
from .test_scheduler import *
from .test_old_doctests import *

View File

@@ -4,22 +4,21 @@
""" Unit tests for old doctests in utf8.py, html.py, markmin2html.py.
Don't abuse doctests, web2py > 2.4.5 will accept only unittests
"""
import sys
import os
import doctest
import unittest
def load_tests(loader, tests, ignore):
tests.addTests(
doctest.DocTestSuite('html')
doctest.DocTestSuite('gluon.html')
)
tests.addTests(
doctest.DocTestSuite('utf8')
doctest.DocTestSuite('gluon.utf8')
)
tests.addTests(
doctest.DocTestSuite('contrib.markmin.markmin2html',
doctest.DocTestSuite('gluon.contrib.markmin.markmin2html',
)
)

View File

@@ -25,6 +25,7 @@ import logging
import getpass
from gluon import main, newcron
from gluon.fileutils import read_file, write_file, create_welcome_w2p
from gluon.settings import global_settings
from gluon.shell import run, test
@@ -40,8 +41,8 @@ ProgramInfo = '''%s
%s
%s''' % (ProgramName, ProgramAuthor, ProgramVersion)
if not sys.version[:3] in ['2.7']:
msg = 'Warning: web2py requires Python 2.7 but you are running:\n%s'
if sys.version_info < (2, 7) and (3, 0) < sys.version_info < (3, 5):
msg = 'Warning: web2py requires at least Python 2.7/3.5 but you are running:\n%s'
msg = msg % sys.version
sys.stderr.write(msg)
@@ -56,28 +57,27 @@ def run_system_tests(options):
major_version = sys.version_info[0]
minor_version = sys.version_info[1]
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
if major_version == 2:
if minor_version in (7,):
if options.with_coverage:
try:
import coverage
coverage_config = os.environ.get(
"COVERAGE_PROCESS_START",
os.path.join('gluon', 'tests', 'coverage.ini'))
call_args = ['coverage', 'run', '--rcfile=%s' %
coverage_config,
'-m', 'unittest', '-v', 'gluon.tests']
except:
sys.stderr.write('Coverage was not installed, skipping\n')
if options.with_coverage:
has_coverage = False
coverage_exec = 'coverage2' if major_version == 2 else 'coverage3'
try:
import coverage
has_coverage = True
except:
sys.stderr.write('Coverage was not installed, skipping\n')
coverage_config_file = os.path.join('gluon', 'tests', 'coverage.ini')
coverage_config = os.environ.setdefault("COVERAGE_PROCESS_START",
coverage_config_file)
call_args = [coverage_exec, 'run', '--rcfile=%s' %
coverage_config, '-m', 'unittest', '-v', 'gluon.tests']
if major_version == 2:
sys.stderr.write("Python 2.7\n")
else:
sys.stderr.write("Experimental Python 3.x.\n")
if has_coverage:
ret = subprocess.call(call_args)
else:
sys.stderr.write("unknown python 2.x version\n")
ret = 256
else:
sys.stderr.write("Experimental Python 3.x.\n")
ret = subprocess.call(call_args)
sys.exit(ret and 1)