Merge branch 'master' of github.com:web2py/web2py
This commit is contained in:
@@ -12,10 +12,6 @@ import tempfile
|
|||||||
import threading
|
import threading
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def is_gae():
|
|
||||||
import httplib
|
|
||||||
return 'appengine' in str(httplib.HTTP)
|
|
||||||
|
|
||||||
def fix_sys_path():
|
def fix_sys_path():
|
||||||
"""
|
"""
|
||||||
logic to have always the correct sys.path
|
logic to have always the correct sys.path
|
||||||
@@ -41,16 +37,37 @@ def fix_sys_path():
|
|||||||
os.path.abspath(os.path.join(path, 'gluon')),
|
os.path.abspath(os.path.join(path, 'gluon')),
|
||||||
'']
|
'']
|
||||||
[add_path_first(path) for path in paths]
|
[add_path_first(path) for path in paths]
|
||||||
|
|
||||||
fix_sys_path()
|
fix_sys_path()
|
||||||
|
|
||||||
|
#support skipif also in python 2.6
|
||||||
|
def _skipIf(cond, message=''):
|
||||||
|
def _decorator(testcase):
|
||||||
|
if cond:
|
||||||
|
return lambda *a, **kw: None
|
||||||
|
else:
|
||||||
|
return testcase
|
||||||
|
return _decorator
|
||||||
|
|
||||||
|
if hasattr(unittest, 'skipIf'):
|
||||||
|
skipIf = unittest.skipIf
|
||||||
|
else:
|
||||||
|
skipIf = _skipIf
|
||||||
|
|
||||||
import languages
|
import languages
|
||||||
from storage import Storage
|
from storage import Storage
|
||||||
|
MP_WORKING = 0
|
||||||
try:
|
try:
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
MP_WORKING = 1
|
||||||
|
#due to http://bugs.python.org/issue10845, testing multiprocessing in python is impossible
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
MP_WORKING = 0
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
def read_write(args):
|
|
||||||
|
def read_write(args):
|
||||||
(filename, iterations) = args
|
(filename, iterations) = args
|
||||||
for i in range(0, iterations):
|
for i in range(0, iterations):
|
||||||
content = languages.read_dict(filename)
|
content = languages.read_dict(filename)
|
||||||
@@ -59,7 +76,7 @@ try:
|
|||||||
languages.write_dict(filename, content)
|
languages.write_dict(filename, content)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class TestLanguagesParallel(unittest.TestCase):
|
class TestLanguagesParallel(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.filename = tempfile.mktemp()
|
self.filename = tempfile.mktemp()
|
||||||
@@ -75,16 +92,23 @@ try:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable')
|
||||||
def test_reads_and_writes(self):
|
def test_reads_and_writes(self):
|
||||||
if is_gae():
|
|
||||||
return # do not check since on GAE not write of filesystem
|
|
||||||
readwriters = 10
|
readwriters = 10
|
||||||
pool = multiprocessing.Pool(processes=readwriters)
|
pool = multiprocessing.Pool(processes=readwriters)
|
||||||
results = pool.map(read_write, [[self.filename, 10]] * readwriters)
|
results = pool.map(read_write, [[self.filename, 10]] * readwriters)
|
||||||
for result in results:
|
for result in results:
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
class TestTranslations(unittest.TestCase):
|
@skipIf(MP_WORKING == 1, 'multiprocessing tests available')
|
||||||
|
def test_reads_and_writes_no_mp(self):
|
||||||
|
results = []
|
||||||
|
for i in range(10):
|
||||||
|
results.append(read_write([self.filename, 10]))
|
||||||
|
for result in results:
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
class TestTranslations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if os.path.isdir('gluon'):
|
if os.path.isdir('gluon'):
|
||||||
@@ -121,8 +145,6 @@ try:
|
|||||||
self.assertEqual(str(T('Hello World')),
|
self.assertEqual(str(T('Hello World')),
|
||||||
'Salve Mondo')
|
'Salve Mondo')
|
||||||
|
|
||||||
except ImportError:
|
|
||||||
logging.warning("Skipped test case, no multiprocessing module.")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
Reference in New Issue
Block a user