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

This commit is contained in:
niphlod
2016-08-31 01:47:42 +02:00
parent 8370791b83
commit a1e1bf3500
7 changed files with 44 additions and 32 deletions
+4
View File
@@ -4,6 +4,10 @@
- py3.5 syntax compatible (see #1353 for details) - py3.5 syntax compatible (see #1353 for details)
- dropped web shell from admin - dropped web shell from admin
- scheduler new feature: you can now specify intervals with cron - 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 - 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 python -m unittest -v gluon.tests on the root dir
+7 -2
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 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) folder = apath(app, request)
try: try:
failed_views = compile_application(folder, skip_failed_views) failed_views = compile_application(folder, skip_failed_views)
@@ -442,9 +442,14 @@ def create_missing_folders():
path = abspath(path, gluon=True) path = abspath(path, gluon=True)
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) os.mkdir(path)
"""
OLD sys.path dance
paths = (global_settings.gluon_parent, abspath( paths = (global_settings.gluon_parent, abspath(
'site-packages', gluon=True), abspath('gluon', gluon=True), '') '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): def create_missing_app_folders(request):
+1 -1
View File
@@ -19,7 +19,7 @@ import sched
import re import re
import datetime import datetime
import platform import platform
import fileutils import gluon.fileutils
from functools import reduce from functools import reduce
try: try:
import cPickle as pickle import cPickle as pickle
+7 -2
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 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 import IS_INT_IN_RANGE, IS_DATETIME, IS_IN_DB
from gluon.utils import web2py_uuid 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 from gluon.storage import Storage
USAGE = """ USAGE = """
@@ -245,7 +245,8 @@ class CronParser(object):
elif period == 'hr': elif period == 'hr':
check = all(0 <= i <= 23 for i in values) check = all(0 <= i <= 23 for i in values)
elif period == 'dom': 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': elif period == 'mon':
check = all(1 <= i <= 12 for i in values) check = all(1 <= i <= 12 for i in values)
elif period == 'dow': elif period == 'dow':
@@ -412,6 +413,8 @@ class CronParser(object):
def _decode_list(lst): def _decode_list(lst):
if not PY2:
return lst
newlist = [] newlist = []
for i in lst: for i in lst:
if isinstance(i, unicode): if isinstance(i, unicode):
@@ -423,6 +426,8 @@ def _decode_list(lst):
def _decode_dict(dct): def _decode_dict(dct):
if not PY2:
return dct
newdict = {} newdict = {}
for k, v in iteritems(dct): for k, v in iteritems(dct):
if isinstance(k, unicode): if isinstance(k, unicode):
+1 -2
View File
@@ -1,4 +1,3 @@
import sys
from .test_http import * from .test_http import *
from .test_contenttype import * from .test_contenttype import *
@@ -22,8 +21,8 @@ from .test_compileapp import *
from .test_appadmin import * from .test_appadmin import *
from .test_web import * from .test_web import *
from .test_sqlhtml import * from .test_sqlhtml import *
from .test_scheduler import *
if sys.version[:3] == '2.7': if sys.version[:3] == '2.7':
from .test_is_url import * from .test_is_url import *
from .test_scheduler import *
from .test_old_doctests import * from .test_old_doctests import *
+4 -5
View File
@@ -4,22 +4,21 @@
""" Unit tests for old doctests in utf8.py, html.py, markmin2html.py. """ Unit tests for old doctests in utf8.py, html.py, markmin2html.py.
Don't abuse doctests, web2py > 2.4.5 will accept only unittests Don't abuse doctests, web2py > 2.4.5 will accept only unittests
""" """
import sys
import os
import doctest import doctest
import unittest import unittest
def load_tests(loader, tests, ignore): def load_tests(loader, tests, ignore):
tests.addTests( tests.addTests(
doctest.DocTestSuite('html') doctest.DocTestSuite('gluon.html')
) )
tests.addTests( tests.addTests(
doctest.DocTestSuite('utf8') doctest.DocTestSuite('gluon.utf8')
) )
tests.addTests( tests.addTests(
doctest.DocTestSuite('contrib.markmin.markmin2html', doctest.DocTestSuite('gluon.contrib.markmin.markmin2html',
) )
) )
+20 -20
View File
@@ -25,6 +25,7 @@ import logging
import getpass import getpass
from gluon import main, newcron from gluon import main, newcron
from gluon.fileutils import read_file, write_file, create_welcome_w2p from gluon.fileutils import read_file, write_file, create_welcome_w2p
from gluon.settings import global_settings from gluon.settings import global_settings
from gluon.shell import run, test from gluon.shell import run, test
@@ -40,8 +41,8 @@ ProgramInfo = '''%s
%s %s
%s''' % (ProgramName, ProgramAuthor, ProgramVersion) %s''' % (ProgramName, ProgramAuthor, ProgramVersion)
if not sys.version[:3] in ['2.7']: if sys.version_info < (2, 7) and (3, 0) < sys.version_info < (3, 5):
msg = 'Warning: web2py requires Python 2.7 but you are running:\n%s' msg = 'Warning: web2py requires at least Python 2.7/3.5 but you are running:\n%s'
msg = msg % sys.version msg = msg % sys.version
sys.stderr.write(msg) sys.stderr.write(msg)
@@ -56,28 +57,27 @@ def run_system_tests(options):
major_version = sys.version_info[0] major_version = sys.version_info[0]
minor_version = sys.version_info[1] minor_version = sys.version_info[1]
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests'] call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
if major_version == 2: if options.with_coverage:
if minor_version in (7,): has_coverage = False
if options.with_coverage: coverage_exec = 'coverage2' if major_version == 2 else 'coverage3'
try: try:
import coverage import coverage
coverage_config = os.environ.get( has_coverage = True
"COVERAGE_PROCESS_START", except:
os.path.join('gluon', 'tests', 'coverage.ini')) sys.stderr.write('Coverage was not installed, skipping\n')
coverage_config_file = os.path.join('gluon', 'tests', 'coverage.ini')
call_args = ['coverage', 'run', '--rcfile=%s' % coverage_config = os.environ.setdefault("COVERAGE_PROCESS_START",
coverage_config, coverage_config_file)
'-m', 'unittest', '-v', 'gluon.tests'] call_args = [coverage_exec, 'run', '--rcfile=%s' %
except: coverage_config, '-m', 'unittest', '-v', 'gluon.tests']
sys.stderr.write('Coverage was not installed, skipping\n') if major_version == 2:
sys.stderr.write("Python 2.7\n") sys.stderr.write("Python 2.7\n")
else:
sys.stderr.write("Experimental Python 3.x.\n")
if has_coverage:
ret = subprocess.call(call_args) ret = subprocess.call(call_args)
else: else:
sys.stderr.write("unknown python 2.x version\n")
ret = 256 ret = 256
else:
sys.stderr.write("Experimental Python 3.x.\n")
ret = subprocess.call(call_args)
sys.exit(ret and 1) sys.exit(ret and 1)