fix for StorageList and tests added

gluon/storage.py
StorageList had a recursion error (please check the implementation before committing)

gluon/tests*
added the fix_path module to avoid those ugly lines at the beginning of each test file
added tests for gluon.contenttype and test_fileutils
added tests for missing Storage methods
This commit is contained in:
niphlod
2014-09-21 08:26:38 +02:00
parent bb199ad533
commit 34a417cfa0
19 changed files with 218 additions and 441 deletions
+8 -39
View File
@@ -7,38 +7,11 @@
import sys
import os
import unittest
import tempfile
import threading
import logging
import unittest
from fix_path import fix_sys_path
def fix_sys_path():
"""
logic to have always the correct sys.path
'', web2py/gluon, web2py/site-packages, web2py/ ...
"""
def add_path_first(path):
sys.path = [path] + [p for p in sys.path if (
not p == path and not p == (path + '/'))]
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, '..'))
paths = [path,
os.path.abspath(os.path.join(path, 'site-packages')),
os.path.abspath(os.path.join(path, 'gluon')),
'']
[add_path_first(path) for path in paths]
fix_sys_path()
fix_sys_path(__file__)
#support skipif also in python 2.6
def _skipIf(cond, message=''):
@@ -55,7 +28,6 @@ else:
skipIf = _skipIf
import languages
from storage import Storage
MP_WORKING = 0
try:
import multiprocessing
@@ -63,10 +35,6 @@ try:
#due to http://bugs.python.org/issue10845, testing multiprocessing in python is impossible
if sys.platform.startswith('win'):
MP_WORKING = 0
#multiprocessing is also not available on GAE. Since tests randomly
#fail, let's not make them on it too
if 'datastore' in os.getenv('DB', ''):
MP_WORKING = 0
except ImportError:
pass
@@ -80,6 +48,7 @@ def read_write(args):
languages.write_dict(filename, content)
return True
class TestLanguagesParallel(unittest.TestCase):
def setUp(self):
@@ -95,7 +64,7 @@ class TestLanguagesParallel(unittest.TestCase):
os.remove(self.filename)
except:
pass
@skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable')
def test_reads_and_writes(self):
readwriters = 10
@@ -103,7 +72,7 @@ class TestLanguagesParallel(unittest.TestCase):
results = pool.map(read_write, [[self.filename, 10]] * readwriters)
for result in results:
self.assertTrue(result)
@skipIf(MP_WORKING == 1, 'multiprocessing tests available')
def test_reads_and_writes_no_mp(self):
results = []
@@ -112,6 +81,7 @@ class TestLanguagesParallel(unittest.TestCase):
for result in results:
self.assertTrue(result)
class TestTranslations(unittest.TestCase):
def setUp(self):
@@ -148,7 +118,6 @@ class TestTranslations(unittest.TestCase):
T.force('it')
self.assertEqual(str(T('Hello World')),
'Salve Mondo')
if __name__ == '__main__':
unittest.main()