diff --git a/gluon/tests/test_languages.py b/gluon/tests/test_languages.py index 60172fe9..98d430df 100644 --- a/gluon/tests/test_languages.py +++ b/gluon/tests/test_languages.py @@ -7,25 +7,13 @@ import sys import os +import shutil import tempfile import unittest from fix_path import fix_sys_path 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 MP_WORKING = 0 @@ -69,7 +57,7 @@ class TestLanguagesParallel(unittest.TestCase): except: pass - @skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable') + @unittest.skipIf(MP_WORKING == 0, 'multiprocessing tests unavailable') def test_reads_and_writes(self): readwriters = 10 pool = multiprocessing.Pool(processes=readwriters) @@ -77,7 +65,7 @@ class TestLanguagesParallel(unittest.TestCase): for result in results: 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): results = [] for i in range(10): @@ -123,5 +111,79 @@ class TestTranslations(unittest.TestCase): self.assertEqual(str(T('Hello World')), '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( +""" + + + + +

{{=T('ahoy')}}

+ + +""" + ) + + 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__': unittest.main() diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index 57f63762..6f7034db 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -31,17 +31,6 @@ class TestValidators(unittest.TestCase): self.assertEqual(utc.dst(dt), UTC.ZERO) 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): rtn = IS_MATCH('.+')('hello') self.assertEqual(rtn, ('hello', None))