Skip to content

Commit

Permalink
patch a few holes in the test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
tibonihoo committed May 31, 2014
1 parent b2e4da9 commit 881a78c
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 9 deletions.
1 change: 1 addition & 0 deletions package/test/plugins/simpleplugin.yapsy-plugin
Expand Up @@ -7,3 +7,4 @@ Author = Thibauld Nion
Version = 0.1
Website = http://mathbench.sourceforge.net
Description = A simple plugin usefull for basic testing
Copyright = 2014
3 changes: 3 additions & 0 deletions package/test/test_ConfigPlugin.py
Expand Up @@ -63,6 +63,9 @@ def testConfigurationFileExistence(self):
plugin_info_ext="yapsy-config-plugin",
configparser_instance=self.config_parser,
config_change_trigger=self.update_config)
# check that activating the plugin once again, won't cause an error
self.pluginManager.activatePluginByName(self.plugin_info.name,
self.plugin_info.category)
# Will be used later
self.plugin_info = None

Expand Down
77 changes: 74 additions & 3 deletions package/test/test_PluginFileLocator.py
Expand Up @@ -8,7 +8,9 @@
import tempfile
import shutil
from ConfigParser import ConfigParser
from StringIO import StringIO

from yapsy import PLUGIN_NAME_FORBIDEN_STRING
from yapsy.PluginInfo import PluginInfo
from yapsy.PluginFileLocator import PluginFileLocator
from yapsy.PluginFileLocator import PluginFileAnalyzerWithInfoFile
Expand Down Expand Up @@ -44,15 +46,60 @@ def test_getInfosDictFromPlugin(self):
analyzer = PluginFileAnalyzerWithInfoFile("mouf")
info_dict,cf_parser = analyzer.getInfosDictFromPlugin(self.plugin_directory,
os.path.basename(self.yapsy_plugin_path))
self.assertEqual(info_dict,{'website': 'http://mathbench.sourceforge.net', 'description': 'A simple plugin usefull for basic testing', 'author': 'Thibauld Nion', 'version': '0.1', 'path': '%s/SimplePlugin' % self.plugin_directory, 'name': 'Simple Plugin'})
self.assertEqual(info_dict,{'website': 'http://mathbench.sourceforge.net', 'description': 'A simple plugin usefull for basic testing', 'author': 'Thibauld Nion', 'version': '0.1', 'path': '%s/SimplePlugin' % self.plugin_directory, 'name': 'Simple Plugin', 'copyright': '2014'})
self.assertTrue(isinstance(cf_parser,ConfigParser))

def test_isValid_WithMultiExtensions(self):
analyzer = PluginFileAnalyzerWithInfoFile("mouf",("yapsy-plugin","yapsy-filter-plugin"))
self.assertTrue(analyzer.isValidPlugin(self.yapsy_plugin_path))
self.assertFalse(analyzer.isValidPlugin(self.version_plugin_path))
self.assertTrue(analyzer.isValidPlugin(self.yapsy_filter_plugin_path))

def test__extractCorePluginInfo_with_minimal_description(self):
plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
Module = SimplePlugin
""")
analyzer = PluginFileAnalyzerWithInfoFile("mouf",
("yapsy-plugin"))
infos, parser = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
self.assertEqual("Simple Plugin", infos["name"])
self.assertEqual(os.path.join("bla","SimplePlugin"), infos["path"])
self.assertTrue(isinstance(parser,ConfigParser))

def test_getPluginNameAndModuleFromStream_with_invalid_descriptions(self):
plugin_desc_content = StringIO("""\
[Core]
Name = Bla{0}Bli
Module = SimplePlugin
""".format(PLUGIN_NAME_FORBIDEN_STRING))
analyzer = PluginFileAnalyzerWithInfoFile("mouf",
("yapsy-plugin"))
res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
self.assertEqual((None, None), res)
plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
""")
analyzer = PluginFileAnalyzerWithInfoFile("mouf",
("yapsy-plugin"))
res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
self.assertEqual((None, None), res)
plugin_desc_content = StringIO("""\
[Core]
Module = Simple Plugin
""")
res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
self.assertEqual((None, None), res)
plugin_desc_content = StringIO("""\
[Mouf]
Bla = Simple Plugin
""")
res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
self.assertEqual((None, None), res)


class PluginFileAnalyzerMathingRegexTest(unittest.TestCase):
"""
Test that the "regex" analyzer enforces the correct policy.
Expand Down Expand Up @@ -288,6 +335,11 @@ def test_appendAnalyzer(self):
self.assertEqual(num,5)
self.assertEqual(len(candidates),num)

def test_removeAnalyzers_when_analyzer_is_unknown(self):
pl = PluginFileLocator()
pl.setPluginPlaces([self.plugin_directory])
pl.removeAnalyzers("nogo")

def test_removeAnalyzers(self):
pl = PluginFileLocator()
pl.setPluginPlaces([self.plugin_directory])
Expand All @@ -297,7 +349,7 @@ def test_removeAnalyzers(self):
candidates, num = pl.locatePlugins()
self.assertEqual(num,4)
self.assertEqual(len(candidates),num)

def test_removeAllAnalyzers(self):
pl = PluginFileLocator()
pl.setPluginPlaces([self.plugin_directory])
Expand All @@ -306,7 +358,26 @@ def test_removeAllAnalyzers(self):
self.assertEqual(num,0)
self.assertEqual(len(candidates),num)


def test_setPluginInfoClass_for_named_analyzer(self):
class SpecificPluginInfo(PluginInfo):
pass
pl = PluginFileLocator()
pl.setPluginPlaces([self.plugin_directory])
newAnalyzer = PluginFileAnalyzerMathingRegex("mouf",r".*VersionedPlugin\d+\.py$")
pl.appendAnalyzer(newAnalyzer)
pl.setPluginInfoClass(SpecificPluginInfo,"info_ext")
candidates, num = pl.locatePlugins()
self.assertEqual(num,5)
self.assertEqual(len(candidates),num)
versioned_plugins = [c for c in candidates if "VersionedPlugin" in c[0]]
self.assertEqual(4,len(versioned_plugins))
for p in versioned_plugins:
self.assertTrue(isinstance(p[2],PluginInfo))
simple_plugins = [c for c in candidates if "VersionedPlugin" not in c[0]]
self.assertEqual(1,len(simple_plugins))
for p in simple_plugins:
self.assertTrue(isinstance(p[2],SpecificPluginInfo))


suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(PluginFileAnalyzerWithInfoFileTest),
Expand Down
1 change: 0 additions & 1 deletion package/test/test_PluginInfo.py
Expand Up @@ -4,7 +4,6 @@
import test_settings
from ConfigParser import ConfigParser
import unittest
import os

from yapsy.PluginInfo import PluginInfo

Expand Down
27 changes: 22 additions & 5 deletions package/test/test_SimplePlugin.py
Expand Up @@ -8,8 +8,24 @@
from yapsy.PluginManager import PluginManager
from yapsy.IPlugin import IPlugin
from yapsy.PluginFileLocator import PluginFileLocator
from yapsy import NormalizePluginNameForModuleName

class SimpleTestsCase(unittest.TestCase):
class YapsyUtils(unittest.TestCase):

def test_NormalizePluginNameForModuleName_on_ok_name(self):
self.assertEqual("moufGlop2",NormalizePluginNameForModuleName("moufGlop2"))

def test_NormalizePluginNameForModuleName_on_empty_name(self):
self.assertEqual("_",NormalizePluginNameForModuleName(""))

def test_NormalizePluginNameForModuleName_on_name_with_space(self):
self.assertEqual("mouf_glop",NormalizePluginNameForModuleName("mouf glop"))

def test_NormalizePluginNameForModuleName_on_name_with_nonalphanum(self):
self.assertEqual("mouf__glop_a___",NormalizePluginNameForModuleName("mouf+?glop:a/é"))


class SimpleTestCase(unittest.TestCase):
"""
Test the correct loading of a simple plugin as well as basic
commands.
Expand Down Expand Up @@ -228,7 +244,7 @@ def testRecursivePluginlocation(self):
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),2)

def testNonRecursivePluginlocationNotFound(self):
def testDisablingRecursivePluginLocationIsEnforced(self):
"""
Test detection of plugins when the detection is non recursive.
Here we test that it cannot look into subdirectories of the
Expand All @@ -248,8 +264,8 @@ def testNonRecursivePluginlocationNotFound(self):
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),0)


def testNonRecursivePluginlocationNotFound(self):
def testDisablingRecursivePluginLocationAllowsFindingTopLevelPlugins(self):
"""
Test detection of plugins when the detection is non
recursive. Here we test that if we give test/plugin as the
Expand All @@ -272,7 +288,8 @@ def testNonRecursivePluginlocationNotFound(self):


suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(SimpleTestsCase),
unittest.TestLoader().loadTestsFromTestCase(YapsyUtils),
unittest.TestLoader().loadTestsFromTestCase(SimpleTestCase),
unittest.TestLoader().loadTestsFromTestCase(SimplePluginAdvancedManipulationTestsCase),
unittest.TestLoader().loadTestsFromTestCase(SimplePluginDetectionTestsCase),
])

0 comments on commit 881a78c

Please sign in to comment.