From 881a78ca6622640d6449586e358f37506b82f589 Mon Sep 17 00:00:00 2001 From: Thibauld Nion Date: Sat, 31 May 2014 23:52:05 +0200 Subject: [PATCH] patch a few holes in the test harness --- .../test/plugins/simpleplugin.yapsy-plugin | 1 + package/test/test_ConfigPlugin.py | 3 + package/test/test_PluginFileLocator.py | 77 ++++++++++++++++++- package/test/test_PluginInfo.py | 1 - package/test/test_SimplePlugin.py | 27 +++++-- 5 files changed, 100 insertions(+), 9 deletions(-) diff --git a/package/test/plugins/simpleplugin.yapsy-plugin b/package/test/plugins/simpleplugin.yapsy-plugin index 02afc57..79f9040 100644 --- a/package/test/plugins/simpleplugin.yapsy-plugin +++ b/package/test/plugins/simpleplugin.yapsy-plugin @@ -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 diff --git a/package/test/test_ConfigPlugin.py b/package/test/test_ConfigPlugin.py index 248e089..1690ef6 100644 --- a/package/test/test_ConfigPlugin.py +++ b/package/test/test_ConfigPlugin.py @@ -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 diff --git a/package/test/test_PluginFileLocator.py b/package/test/test_PluginFileLocator.py index fcaee9d..bf9ce65 100644 --- a/package/test/test_PluginFileLocator.py +++ b/package/test/test_PluginFileLocator.py @@ -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 @@ -44,7 +46,7 @@ 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): @@ -52,7 +54,52 @@ def test_isValid_WithMultiExtensions(self): 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. @@ -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]) @@ -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]) @@ -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), diff --git a/package/test/test_PluginInfo.py b/package/test/test_PluginInfo.py index 4fcd938..342bd69 100644 --- a/package/test/test_PluginInfo.py +++ b/package/test/test_PluginInfo.py @@ -4,7 +4,6 @@ import test_settings from ConfigParser import ConfigParser import unittest -import os from yapsy.PluginInfo import PluginInfo diff --git a/package/test/test_SimplePlugin.py b/package/test/test_SimplePlugin.py index ce116a1..c6c9d95 100644 --- a/package/test/test_SimplePlugin.py +++ b/package/test/test_SimplePlugin.py @@ -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. @@ -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 @@ -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 @@ -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), ])