diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2008-10-22 15:20:34 +0200 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2008-10-22 15:20:34 +0200 |
commit | c8390f9ff492cd4338e1479bc8687ec755ace978 (patch) | |
tree | f65f4d9a3842bc723dc3b21bb54fefabe7d37dc8 /test | |
parent | e2e4866df21e258de04d268c58d300372a39f487 (diff) | |
parent | 25b9cdf5f6e72c7c8aec5ef927cf67ee1a0eeda4 (diff) | |
download | logilab-common-c8390f9ff492cd4338e1479bc8687ec755ace978.tar.gz |
import Pierre-Yves David's fixes
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_decorators.py | 74 | ||||
-rw-r--r-- | test/unittest_testlib.py | 74 |
2 files changed, 74 insertions, 74 deletions
diff --git a/test/unittest_decorators.py b/test/unittest_decorators.py deleted file mode 100644 index 855f242..0000000 --- a/test/unittest_decorators.py +++ /dev/null @@ -1,74 +0,0 @@ -import sys -from logilab.common.testlib import TestCase, unittest_main, TestSuite -from logilab.common.decorators import require_version, require_module - -class DecoratorsTC(TestCase): - def test_require_version_good(self): - """ should return the same function - """ - def func() : - pass - sys.version_info = (2, 5, 5, 'final', 4) - current = sys.version_info[:3] - compare = ('2.4', '2.5', '2.5.4', '2.5.5') - for version in compare: - decorator = require_version(version) - self.assertEquals(func, decorator(func), '%s =< %s : function \ - return by the decorator should be the same.' % (version, - '.'.join([str(element) for element in current]))) - - def test_require_version_bad(self): - """ should return a different function : skipping test - """ - def func() : - pass - sys.version_info = (2, 5, 5, 'final', 4) - current = sys.version_info[:3] - compare = ('2.5.6', '2.6', '2.6.5') - for version in compare: - decorator = require_version(version) - self.assertNotEquals(func, decorator(func), '%s >= %s : function \ - return by the decorator should NOT be the same.' - % ('.'.join([str(element) for element in current]), version)) - - def test_require_version_exception(self): - """ should throw a ValueError exception - """ - def func() : - pass - compare = ('2.5.a', '2.a', 'azerty') - for version in compare: - decorator = require_version(version) - self.assertRaises(ValueError, decorator, func) - - def test_require_module_good(self): - """ should return the same function - """ - def func() : - pass - module = 'sys' - decorator = require_module(module) - self.assertEquals(func, decorator(func), 'module %s exists : function \ - return by the decorator should be the same.' % module) - - def test_require_module_bad(self): - """ should return a different function : skipping test - """ - def func() : - pass - modules = ('bla', 'blo', 'bli') - for module in modules: - try: - __import__(module) - pass - except ImportError: - decorator = require_module(module) - self.assertNotEquals(func, decorator(func), 'module %s does \ - not exist : function return by the decorator should \ - NOT be the same.' % module) - return - print 'all modules in %s exist. Could not test %s' % (', '.join(modules), - sys._getframe().f_code.co_name) - -if __name__ == '__main__': - unittest_main() diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py index f7324a1..afdf932 100644 --- a/test/unittest_testlib.py +++ b/test/unittest_testlib.py @@ -24,6 +24,7 @@ from logilab.common.testlib import TestCase, SkipAwareTextTestRunner from logilab.common.testlib import mock_object, NonStrictTestLoader, create_files from logilab.common.testlib import capture_stdout, unittest_main, InnerTest from logilab.common.testlib import with_tempdir, tag +from logilab.common.testlib import require_version, require_module class MockTestCase(TestCase): def __init__(self): @@ -599,6 +600,12 @@ class OutErrCaptureTC(TestCase): bootstrap_print("hello") self.assertEquals(output.restore(), "hello") + def test_exotic_unicode_string(self): + class FooTC(TestCase): + def test_xxx(self): + raise Exception(u'\xe9') + test = FooTC('test_xxx') + result = self.runner.run(test) class DecoratorTC(TestCase): @@ -663,6 +670,73 @@ class DecoratorTC(TestCase): self.assertListEquals(list(os.walk(tempdir)), [(tempdir,[],[])]) + def test_require_version_good(self): + """ should return the same function + """ + def func() : + pass + sys.version_info = (2, 5, 5, 'final', 4) + current = sys.version_info[:3] + compare = ('2.4', '2.5', '2.5.4', '2.5.5') + for version in compare: + decorator = require_version(version) + self.assertEquals(func, decorator(func), '%s =< %s : function \ + return by the decorator should be the same.' % (version, + '.'.join([str(element) for element in current]))) + + def test_require_version_bad(self): + """ should return a different function : skipping test + """ + def func() : + pass + sys.version_info = (2, 5, 5, 'final', 4) + current = sys.version_info[:3] + compare = ('2.5.6', '2.6', '2.6.5') + for version in compare: + decorator = require_version(version) + self.assertNotEquals(func, decorator(func), '%s >= %s : function \ + return by the decorator should NOT be the same.' + % ('.'.join([str(element) for element in current]), version)) + + def test_require_version_exception(self): + """ should throw a ValueError exception + """ + def func() : + pass + compare = ('2.5.a', '2.a', 'azerty') + for version in compare: + decorator = require_version(version) + self.assertRaises(ValueError, decorator, func) + + def test_require_module_good(self): + """ should return the same function + """ + def func() : + pass + module = 'sys' + decorator = require_module(module) + self.assertEquals(func, decorator(func), 'module %s exists : function \ + return by the decorator should be the same.' % module) + + def test_require_module_bad(self): + """ should return a different function : skipping test + """ + def func() : + pass + modules = ('bla', 'blo', 'bli') + for module in modules: + try: + __import__(module) + pass + except ImportError: + decorator = require_module(module) + self.assertNotEquals(func, decorator(func), 'module %s does \ + not exist : function return by the decorator should \ + NOT be the same.' % module) + return + print 'all modules in %s exist. Could not test %s' % (', '.join(modules), + sys._getframe().f_code.co_name) + class TagTC(TestCase): def setUp(self): |