diff options
author | Marcel Hellkamp <marc@gsites.de> | 2011-04-28 01:10:14 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2011-04-28 01:10:14 +0200 |
commit | 823f5b16fde937b5e1f82e4791ba82818cab39d4 (patch) | |
tree | 3cf31a8d11d03bc0fd0e3e92e31ee7184b43e311 | |
parent | b06f0659d762741a1aed4c41014fac890d06516d (diff) | |
download | bottle-823f5b16fde937b5e1f82e4791ba82818cab39d4.tar.gz |
Added tests for bottle.ext import hooks.
-rw-r--r-- | test/test_importhook.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/test_importhook.py b/test/test_importhook.py new file mode 100644 index 0000000..b6ff7a5 --- /dev/null +++ b/test/test_importhook.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +import unittest +import sys +import imp + + +class TestImportHooks(unittest.TestCase): + server = 'wsgiref' + + def make_module(self, name, **args): + mod = sys.modules.setdefault(name, imp.new_module(name)) + mod.__file__ = '<virtual %s>' % name + mod.__dict__.update(**args) + return mod + + def test_direkt_import(self): + mod = self.make_module('bottle_test') + import bottle.ext.test + self.assertEqual(bottle.ext.test, mod) + + def test_from_import(self): + mod = self.make_module('bottle_test') + from bottle.ext import test + self.assertEqual(test, mod) + + def test_data_import(self): + mod = self.make_module('bottle_test', item='value') + from bottle.ext.test import item + self.assertEqual(item, 'value') + + def test_import_fail(self): + ''' Test a simple static page with this server adapter. ''' + def test(): + import bottle.ext.doesnotexist + self.assertRaises(ImportError, test) + +if __name__ == '__main__': #pragma: no cover + unittest.main() |