Merge pull request #1329 from leonelcamara/test_week11
more tests for languages module
This commit is contained in:
commit
8679ab1777
2 files changed
+77
-26
No files matched your search
@@ -7,25 +7,13 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
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__)
|
||||||
|
|
||||||
#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
|
||||||
MP_WORKING = 0
|
MP_WORKING = 0
|
||||||
@@ -69,7 +57,7 @@ class TestLanguagesParallel(unittest.TestCase):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable')
|
@unittest.skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable')
|
||||||
def test_reads_and_writes(self):
|
def test_reads_and_writes(self):
|
||||||
readwriters = 10
|
readwriters = 10
|
||||||
pool = multiprocessing.Pool(processes=readwriters)
|
pool = multiprocessing.Pool(processes=readwriters)
|
||||||
@@ -77,7 +65,7 @@ class TestLanguagesParallel(unittest.TestCase):
|
|||||||
for result in results:
|
for result in results:
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
@skipIf(MP_WORKING == 1, 'multiprocessing tests available')
|
@unittest.skipIf(MP_WORKING == 1, 'multiprocessing tests available')
|
||||||
def test_reads_and_writes_no_mp(self):
|
def test_reads_and_writes_no_mp(self):
|
||||||
results = []
|
results = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
@@ -123,5 +111,79 @@ class TestTranslations(unittest.TestCase):
|
|||||||
self.assertEqual(str(T('Hello World')),
|
self.assertEqual(str(T('Hello World')),
|
||||||
'Salve Mondo')
|
'Salve Mondo')
|
||||||
|
|
||||||
|
class TestDummyApp(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pjoin = os.path.join
|
||||||
|
self.apppath = os.path.abspath(pjoin(os.path.dirname(os.path.abspath(__file__)), 'dummy'))
|
||||||
|
os.mkdir(self.apppath)
|
||||||
|
os.mkdir(pjoin(self.apppath, 'languages'))
|
||||||
|
os.mkdir(pjoin(self.apppath, 'models'))
|
||||||
|
os.mkdir(pjoin(self.apppath, 'controllers'))
|
||||||
|
os.mkdir(pjoin(self.apppath, 'views'))
|
||||||
|
os.mkdir(pjoin(self.apppath, 'views', 'default'))
|
||||||
|
os.mkdir(pjoin(self.apppath, 'modules'))
|
||||||
|
with open(pjoin(self.apppath, 'languages', 'en.py'), 'w') as testlang:
|
||||||
|
testlang.write(
|
||||||
|
"""
|
||||||
|
{}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with open(pjoin(self.apppath, 'languages', 'pt.py'), 'w') as testlang:
|
||||||
|
testlang.write(
|
||||||
|
"""
|
||||||
|
{}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with open(pjoin(self.apppath, 'modules', 'test.py'), 'w') as testmodule:
|
||||||
|
testmodule.write(
|
||||||
|
"""
|
||||||
|
from gluon import current
|
||||||
|
|
||||||
|
hello = current.T('hello')
|
||||||
|
""" )
|
||||||
|
with open(pjoin(self.apppath, 'models', 'db.py'), 'w') as testmodel:
|
||||||
|
testmodel.write(
|
||||||
|
"""
|
||||||
|
world = T("world")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with open(pjoin(self.apppath, 'controllers', 'default.py'), 'w') as testcontroller:
|
||||||
|
testcontroller.write(
|
||||||
|
"""
|
||||||
|
def index():
|
||||||
|
message = T('%s %%{shop}', 2)
|
||||||
|
return dict(message=message)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with open(pjoin(self.apppath, 'views', 'default', 'index.html'), 'w') as testview:
|
||||||
|
testview.write(
|
||||||
|
"""
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>{{=T('ahoy')}}</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.apppath)
|
||||||
|
|
||||||
|
def test_update_all_languages(self):
|
||||||
|
languages.update_all_languages(self.apppath)
|
||||||
|
en_file = os.path.join(self.apppath, 'languages', 'en.py')
|
||||||
|
pt_file = os.path.join(self.apppath, 'languages', 'pt.py')
|
||||||
|
en_dict = languages.read_dict(en_file)
|
||||||
|
pt_dict = languages.read_dict(pt_file)
|
||||||
|
for key in ['hello', 'world', '%s %%{shop}', 'ahoy']:
|
||||||
|
self.assertTrue(key in en_dict)
|
||||||
|
self.assertTrue(key in pt_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
@@ -31,17 +31,6 @@ class TestValidators(unittest.TestCase):
|
|||||||
self.assertEqual(utc.dst(dt), UTC.ZERO)
|
self.assertEqual(utc.dst(dt), UTC.ZERO)
|
||||||
self.assertEqual(utc.tzname(dt), 'UTC')
|
self.assertEqual(utc.tzname(dt), 'UTC')
|
||||||
|
|
||||||
# port from python 2.7, needed for 2.5 and 2.6 tests
|
|
||||||
def assertRegexpMatches(self, text, expected_regexp, msg=None):
|
|
||||||
"""Fail the test unless the text matches the regular expression."""
|
|
||||||
if isinstance(expected_regexp, basestring):
|
|
||||||
expected_regexp = re.compile(expected_regexp)
|
|
||||||
if not expected_regexp.search(text):
|
|
||||||
msg = msg or "Regexp didn't match"
|
|
||||||
msg = '%s: %r not found in %r' % (
|
|
||||||
msg, expected_regexp.pattern, text)
|
|
||||||
raise self.failureException(msg)
|
|
||||||
|
|
||||||
def test_IS_MATCH(self):
|
def test_IS_MATCH(self):
|
||||||
rtn = IS_MATCH('.+')('hello')
|
rtn = IS_MATCH('.+')('hello')
|
||||||
self.assertEqual(rtn, ('hello', None))
|
self.assertEqual(rtn, ('hello', None))
|
||||||
|
|||||||
Reference in new issue
Block a user