commit/galaxy-central: carlfeberhard: Visualizations registry, QA: initial unit tests; Plugin framework unit tests: remove unneeded tests
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/3a15758ba67e/ Changeset: 3a15758ba67e User: carlfeberhard Date: 2013-09-19 16:09:19 Summary: Visualizations registry, QA: initial unit tests; Plugin framework unit tests: remove unneeded tests Affected #: 6 files diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d lib/galaxy/visualization/registry.py --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -82,8 +82,9 @@ :rtype: bool :returns: True if the path contains a plugin """ - # plugin_path must be a directory, have a config dir + # plugin_path must be a directory, have a config dir, and a config file matching the plugin dir name if not os.path.isdir( plugin_path ): + # super won't work here - different criteria return False if not 'config' in os.listdir( plugin_path ): return False @@ -112,6 +113,7 @@ # config file is required, otherwise skip this visualization plugin[ 'config_file' ] = os.path.join( plugin_path, 'config', ( plugin.name + '.xml' ) ) config = self.config_parser.parse_file( plugin.config_file ) + if not config: return None plugin[ 'config' ] = config diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d test/unit/visualizations/registry/test_VisualizationsRegistry.py --- /dev/null +++ b/test/unit/visualizations/registry/test_VisualizationsRegistry.py @@ -0,0 +1,156 @@ +""" +""" +import os +import imp +import unittest + +utility = imp.load_source( 'utility', '../../util/utility.py' ) +log = utility.set_up_filelogger( __name__ + '.log' ) + +relative_test_path = '/test/unit/visualizations/registry' +utility.add_galaxy_lib_to_path( relative_test_path ) + +from galaxy.visualization.registry import VisualizationsRegistry + +base_mock = imp.load_source( 'mock', '../../web/base/mock.py' ) + +# ----------------------------------------------------------------------------- globals +glx_dir = os.getcwd().replace( relative_test_path, '' ) +template_cache_dir = os.path.join( glx_dir, 'database', 'compiled_templates' ) +vis_reg_path = 'config/plugins/visualizations' + +config1 = """\ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE visualization SYSTEM "../../visualization.dtd"> +<visualization name="scatterplot"> + <data_sources> + <data_source> + <model_class>HistoryDatasetAssociation</model_class> + <test type="isinstance" test_attr="datatype" result_type="datatype">tabular.Tabular</test> + <to_param param_attr="id">dataset_id</to_param> + </data_source> + </data_sources> + <params> + <param type="dataset" var_name_in_template="hda" required="true">dataset_id</param> + </params> + <template>scatterplot.mako</template> +</visualization> +""" + +# ----------------------------------------------------------------------------- +class VisualizationsRegistry_TestCase( unittest.TestCase ): + + # ------------------------------------------------------------------------- vis plugin discovery + def test_plugin_load_from_repo( self ): + """should attempt load if criteria met""" + mock_app = base_mock.MockApp( glx_dir ) + plugin_mgr = VisualizationsRegistry( mock_app, + directories_setting=vis_reg_path, + template_cache_dir=template_cache_dir ) + + expected_plugins_path = os.path.join( glx_dir, vis_reg_path ) + expected_plugin_names = [ + 'circster', + 'graphview', + 'phyloviz', + 'scatterplot', + 'sweepster', + 'trackster', + ] + + self.assertEqual( plugin_mgr.base_url, 'visualizations' ) + self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) + self.assertItemsEqual( plugin_mgr.plugins.keys(), expected_plugin_names ) + + scatterplot = plugin_mgr.plugins[ 'scatterplot' ] + self.assertEqual( scatterplot.name, 'scatterplot' ) + self.assertEqual( scatterplot.path, os.path.join( expected_plugins_path, 'scatterplot' ) ) + self.assertEqual( scatterplot.base_url, '/'.join([ plugin_mgr.base_url, scatterplot.name ]) ) + self.assertTrue( scatterplot.serves_static ) + self.assertEqual( scatterplot.static_path, os.path.join( scatterplot.path, 'static' ) ) + self.assertEqual( scatterplot.static_url, '/'.join([ scatterplot.base_url, 'static' ]) ) + self.assertTrue( scatterplot.serves_templates ) + self.assertEqual( scatterplot.template_path, os.path.join( scatterplot.path, 'templates' ) ) + self.assertEqual( scatterplot.template_lookup.__class__.__name__, 'TemplateLookup' ) + + trackster = plugin_mgr.plugins[ 'trackster' ] + self.assertEqual( trackster.name, 'trackster' ) + self.assertEqual( trackster.path, os.path.join( expected_plugins_path, 'trackster' ) ) + self.assertEqual( trackster.base_url, '/'.join([ plugin_mgr.base_url, trackster.name ]) ) + self.assertFalse( trackster.serves_static ) + self.assertFalse( trackster.serves_templates ) + + def test_plugin_load( self ): + """""" + mock_app_dir = base_mock.MockDir({ + 'plugins' : { + 'vis1' : { + 'config' : { + 'vis1.xml' : config1 + }, + 'static' : {}, + 'templates' : {}, + }, + 'vis2' : { + 'config' : { + 'vis2.xml' : config1 + } + }, + 'not_a_vis1' : { + 'config' : { + 'vis1.xml' : 'blerbler' + }, + }, + 'not_a_vis1' : { + # no config + 'static' : {}, + 'templates' : {}, + }, + # empty + 'not_a_vis2' : {}, + 'not_a_vis3' : 'blerbler', + # bad config + 'not_a_vis4' : { + 'config' : { + 'not_a_vis4.xml' : 'blerbler' + } + }, + } + }) + mock_app = base_mock.MockApp( mock_app_dir.root_path ) + plugin_mgr = VisualizationsRegistry( mock_app, + directories_setting='plugins', + template_cache_dir='bler' ) + + expected_plugins_path = os.path.join( mock_app_dir.root_path, 'plugins' ) + expected_plugin_names = [ 'vis1', 'vis2' ] + + self.assertEqual( plugin_mgr.base_url, 'visualizations' ) + self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) + self.assertItemsEqual( plugin_mgr.plugins.keys(), expected_plugin_names ) + + vis1 = plugin_mgr.plugins[ 'vis1' ] + self.assertEqual( vis1.name, 'vis1' ) + self.assertEqual( vis1.path, os.path.join( expected_plugins_path, 'vis1' ) ) + self.assertEqual( vis1.base_url, '/'.join([ plugin_mgr.base_url, vis1.name ]) ) + self.assertTrue( vis1.serves_static ) + self.assertEqual( vis1.static_path, os.path.join( vis1.path, 'static' ) ) + self.assertEqual( vis1.static_url, '/'.join([ vis1.base_url, 'static' ]) ) + self.assertTrue( vis1.serves_templates ) + self.assertEqual( vis1.template_path, os.path.join( vis1.path, 'templates' ) ) + self.assertEqual( vis1.template_lookup.__class__.__name__, 'TemplateLookup' ) + + vis2 = plugin_mgr.plugins[ 'vis2' ] + self.assertEqual( vis2.name, 'vis2' ) + self.assertEqual( vis2.path, os.path.join( expected_plugins_path, 'vis2' ) ) + self.assertEqual( vis2.base_url, '/'.join([ plugin_mgr.base_url, vis2.name ]) ) + self.assertFalse( vis2.serves_static ) + self.assertFalse( vis2.serves_templates ) + + mock_app_dir.remove() + + +#TODO: config parser tests (in separate file) + +if __name__ == '__main__': + unittest.main() diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d test/unit/visualizations/registry/test_plugins.py --- a/test/unit/visualizations/registry/test_plugins.py +++ /dev/null @@ -1,42 +0,0 @@ -from os import makedirs -from os.path import join, dirname, basename -from tempfile import mkdtemp -from shutil import rmtree - -from galaxy.visualization.registry import VisualizationsRegistry - - -def test_visualization_loading(): - visualizations = __default_viz_root() - registry = VisualizationsRegistry(visualizations, 'foo') - assert "VisualizationsRegistry" in str(registry) - assert visualizations in str(registry) - assert registry.name == "visualizations" - __assert_scatterplot_registered(registry) - assert registry._get_template_paths() == [visualizations] - - -def test_multiple_visualization_roots(): - temp_dir = mkdtemp() - try: - makedirs(join(temp_dir, "coolplugin5")) - visualization_dirs = "%s,%s" % (__default_viz_root(), temp_dir) - registry = VisualizationsRegistry(visualization_dirs, 'foo') - __assert_scatterplot_registered(registry) - assert "coolplugin5" in \ - [basename(path) for path in registry.get_plugin_directories()] - assert registry._get_template_paths() == \ - [__default_viz_root(), temp_dir] - finally: - rmtree(temp_dir) - - -def __assert_scatterplot_registered(registry): - assert 'scatterplot' in \ - [basename(path) for path in registry.get_plugin_directories()] - - -def __default_viz_root(): - galaxy_root = join(dirname(__file__), '..', '..') - visualizations = join(galaxy_root, 'config', 'plugins', 'visualizations') - return visualizations diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d test/unit/web/base/test_HookPluginManager.py --- a/test/unit/web/base/test_HookPluginManager.py +++ b/test/unit/web/base/test_HookPluginManager.py @@ -88,7 +88,6 @@ self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1' ] ) - self.assertFalse( plugin_mgr.plugins.get( 'not_a_plugin', False ) ) plugin = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin.name, 'plugin1' ) @@ -249,6 +248,5 @@ mock_app_dir.remove() - if __name__ == '__main__': unittest.main() diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d test/unit/web/base/test_PageServingPluginManager.py --- a/test/unit/web/base/test_PageServingPluginManager.py +++ b/test/unit/web/base/test_PageServingPluginManager.py @@ -45,7 +45,6 @@ self.assertEqual( plugin_mgr.base_url, 'test' ) self.assertItemsEqual( plugin_mgr.directories, [ expected_plugins_path ] ) self.assertItemsEqual( plugin_mgr.plugins.keys(), [ 'plugin1', 'plugin2', 'plugin3' ] ) - self.assertFalse( plugin_mgr.plugins.get( 'not_a_plugin', False ) ) plugin1 = plugin_mgr.plugins[ 'plugin1' ] self.assertEqual( plugin1.name, 'plugin1' ) diff -r 285453d3908440a10c8863fe90f9833df5a5e261 -r 3a15758ba67e2429698184a4300c9608c65ce06d test/unit/web/base/test_PluginManager.py --- a/test/unit/web/base/test_PluginManager.py +++ b/test/unit/web/base/test_PluginManager.py @@ -36,7 +36,6 @@ self.assertEqual( plugin_mgr.plugins[ 'plugin1' ].path, os.path.join( expected_plugins_path, 'plugin1' ) ) self.assertEqual( plugin_mgr.plugins[ 'plugin2' ].name, 'plugin2' ) self.assertEqual( plugin_mgr.plugins[ 'plugin2' ].path, os.path.join( expected_plugins_path, 'plugin2' ) ) - self.assertFalse( plugin_mgr.plugins.get( 'file1', False ) ) mock_app_dir.remove() @@ -60,7 +59,6 @@ self.assertEqual( plugin_mgr.plugins[ 'plugin1' ].path, os.path.join( expected_plugins_path, 'plugin1' ) ) self.assertEqual( plugin_mgr.plugins[ 'plugin2' ].name, 'plugin2' ) self.assertEqual( plugin_mgr.plugins[ 'plugin2' ].path, os.path.join( expected_plugins_path, 'plugin2' ) ) - self.assertFalse( plugin_mgr.plugins.get( 'file1', False ) ) def test_multiple_dirs( self ): """should search in multiple directories""" @@ -94,8 +92,6 @@ self.assertEqual( plugin_mgr.plugins[ 'plugin3' ].path, os.path.join( expected_plugins_abs_path, 'plugin3' ) ) self.assertEqual( plugin_mgr.plugins[ 'plugin4' ].name, 'plugin4' ) self.assertEqual( plugin_mgr.plugins[ 'plugin4' ].path, os.path.join( expected_plugins_abs_path, 'plugin4' ) ) - self.assertFalse( plugin_mgr.plugins.get( 'file1', False ) ) - self.assertFalse( plugin_mgr.plugins.get( 'file2', False ) ) if __name__ == '__main__': Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org