Attachment 'test_pysupport.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - MoinMoin.util.pysupport Tests
   4 
   5     Module names must start with 'test_' to be included in the tests.
   6 
   7     @copyright: 2004 by Jürgen Hermann <ograf@bitart.de>
   8     @license: GNU GPL, see COPYING for details.
   9 """
  10 
  11 import unittest, tempfile, os
  12 from MoinMoin.util import pysupport
  13 from MoinMoin._tests import request, TestConfig
  14 
  15 
  16 class ImportNameTestCase(unittest.TestCase):
  17     """ Test if importName works correctly
  18     """
  19 
  20     def setUp(self):
  21         """ Create a dummy plugin path with some module inside
  22         """
  23         self.plugin_dir = tempfile.mktemp()
  24         self.parser_dir = os.path.join(self.plugin_dir, 'plugin', 'parser')
  25         os.makedirs(self.parser_dir)
  26         open(os.path.join(self.plugin_dir, 'plugin', '__init__.py'), 'w')
  27         open(os.path.join(self.plugin_dir, 'plugin', 'parser', '__init__.py'), 'w')
  28         f = open(os.path.join(self.parser_dir, 'test.py'), 'w')
  29         f.write('import sys, os\ndef test():\n    pass\n')
  30         f.close()
  31     
  32     def tearDown(self):
  33         """ Remove the plugin dir
  34         """
  35         for file in (os.path.join(self.plugin_dir, 'plugin', '__init__.py'),
  36                      os.path.join(self.plugin_dir, 'plugin', '__init__.pyc'),
  37                      os.path.join(self.plugin_dir, 'plugin', 'parser', '__init__.py'),
  38                      os.path.join(self.plugin_dir, 'plugin', 'parser', '__init__.pyc'),
  39                      os.path.join(self.parser_dir, 'test.py'),
  40                      os.path.join(self.parser_dir, 'test.pyc')):
  41             try:
  42                 os.unlink(file)
  43             except OSError:
  44                 pass
  45         for dir in (os.path.join(self.plugin_dir, 'plugin', 'parser'),
  46                     os.path.join(self.plugin_dir, 'plugin'),
  47                     self.plugin_dir):
  48             os.rmdir(dir)
  49 
  50     def testImportName1(self):
  51         """ pysupport: import wiki parser from moin
  52         
  53         This tests if a module can be imported from the package
  54         MoinMoin. Should never fail, cause importName uses
  55         __import__ to do it."""
  56         self.failUnless(pysupport.importName('MoinMoin.parser.wiki',
  57                                              'Parser'))
  58 
  59     def testImportName2(self):
  60         """ pysupport: import test plugin
  61         
  62         Tests if a module can be importet from an arbitary path
  63         like it is done in moin for plugins. Some strange bug
  64         in the old implementation failed on an import of os,
  65         cause os does a from os.path import that will stumple
  66         over a poisoned sys.modules."""
  67         self.failUnless(pysupport.importName('plugin.parser.test',
  68                                              'test',
  69                                              self.plugin_dir),
  70                         'Failed to import the test plugin!')

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2004-10-18 13:16:08, 0.1 KB) [[attachment:TestTest.txt]]
  • [get | view] (2004-10-19 11:19:14, 3.0 KB) [[attachment:knee-import.diff]]
  • [get | view] (2004-10-18 13:04:42, 0.5 KB) [[attachment:test.py]]
  • [get | view] (2004-10-19 11:19:43, 2.8 KB) [[attachment:test_pysupport.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.