~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/util/_tests/test_pysupport.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
import py
13
13
 
14
 
from MoinMoin.util import pysupport, random_string
15
 
from MoinMoin import wikiutil
 
14
from MoinMoin.util import pysupport
16
15
 
17
16
 
18
17
class TestImportNameFromMoin(object):
48
47
        """ Check for valid plugin package """
49
48
        self.pluginDirectory = os.path.join(self.request.cfg.data_dir, 'plugin', 'parser')
50
49
        self.checkPackage(self.pluginDirectory)
 
50
        self.pluginModule = (self.request.cfg.siteid + '.plugin.parser.' + self.plugin)
51
51
 
52
52
    def checkPackage(self, path):
53
53
        for item in (path, os.path.join(path, '__init__.py')):
62
62
        return os.path.join(self.pluginDirectory, self.plugin + suffix)
63
63
 
64
64
 
65
 
class TestImportNonExisting(TestImportNameFromPlugin):
 
65
class TestImportNonExisiting(TestImportNameFromPlugin):
66
66
 
67
67
    plugin = 'NonExistingWikiPlugin'
68
68
 
69
 
    def testNonExisting(self):
 
69
    def testNonEsisting(self):
70
70
        """ pysupport: import nonexistent wiki plugin fail """
71
71
        if self.pluginExists():
72
72
            py.test.skip('plugin exists: %s' % self.plugin)
73
 
        py.test.raises(wikiutil.PluginMissingError,
74
 
                       wikiutil.importWikiPlugin,
75
 
                           self.request.cfg, 'parser',
76
 
                           self.plugin, 'Parser')
 
73
        py.test.raises(ImportError, pysupport.importName,
 
74
                       self.pluginModule, self.name)
77
75
 
78
76
 
79
77
class TestImportExisting(TestImportNameFromPlugin):
92
90
        """
93
91
        try:
94
92
            self.createTestPlugin()
95
 
            # clear the plugin cache...
96
 
            self.request.cfg._site_plugin_lists = {}
97
 
            parser = wikiutil.importWikiPlugin(self.request.cfg, 'parser',
98
 
                                               self.plugin, 'Parser')
99
 
            assert getattr(parser, '__name__', None) == 'Parser'
100
 
            assert parser.key == self.key
 
93
            plugin = pysupport.importName(self.pluginModule, self.name)
 
94
            assert getattr(plugin, '__name__', None) == self.name
101
95
        finally:
102
96
            self.deleteTestPlugin()
103
97
 
105
99
        """ Create test plugin, skiping if plugin exists """
106
100
        if self.pluginExists():
107
101
            self.shouldDeleteTestPlugin = False
108
 
            py.test.skip("Won't overwrite existing plugin: %s" % self.plugin)
109
 
        self.key = random_string(32, 'abcdefg')
 
102
            py.test.skip("Won't overwrite exiting plugin: %s" % self.plugin)
110
103
        data = '''
111
104
# If you find this file in your wiki plugin directory, you can safely
112
105
# delete it.
113
106
import sys, os
114
107
 
115
108
class Parser:
116
 
    key = '%s'
117
 
''' % self.key
 
109
    pass
 
110
'''
118
111
        try:
119
112
            file(self.pluginFilePath('.py'), 'w').write(data)
120
113
        except Exception, err: