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( +""" + +
+ + +