Esempio n. 1
0
    def test_load_external_py_file(self):
        self.assertFalse(plugnplay.normalize_path(self.full_path) + '.someplugin' in sys.modules)

        plugnplay.set_plugin_dirs(self.full_path)
        plugnplay.load_plugins()

        self.assertTrue(plugnplay.normalize_path(self.full_path) + '.someplugin' in sys.modules)
        import someplugin  # Test de importing of the new plugin
        self.assertTrue(someplugin.SomePlugin is not None)
        p = someplugin.SomePlugin()
        self.assertTrue(isinstance(p, someplugin.SomePlugin))
Esempio n. 2
0
    def test_load_same_name_different_folders(self):
        import sys
        dir1 = join(self.basepath, 'plugin/dir1')
        dir2 = join(self.basepath, 'plugin/dir2')
        plugnplay.set_plugin_dirs(dir1, dir2)
        plugnplay.load_plugins()

        dir1_norm = plugnplay.normalize_path(dir1)
        dir2_norm = plugnplay.normalize_path(dir2)

        self.assertTrue(dir1_norm + '.otherplugin' in sys.modules)
        self.assertTrue(dir2_norm + '.otherplugin' in sys.modules)

        mod1 = sys.modules[dir1_norm + '.otherplugin']
        self.assertTrue(mod1.MyPlugin.dir1)

        mod2 = sys.modules[dir2_norm + '.otherplugin']
        self.assertTrue(mod2.MyPlugin.dir2)
Esempio n. 3
0
 def test_load_plugin_with_error(self):
     import sys
     plugindir = join(self.basepath, 'wrong-plugins/')
     plugnplay.set_plugin_dirs(plugindir)
     mock_logger = Mock()
     plugnplay.load_plugins(logger=mock_logger)
     self.assertEquals(1, mock_logger.debug.call_count)
     call_args = mock_logger.debug.call_args
     self.assertEquals("Error loading plugin: myplugin",  call_args[0][0])
     self.assertTrue('exc_info' in call_args[1])
     self.assertTrue(call_args[1]['exc_info'] is not None)
     self.assertTrue('myplugin' not in sys.modules)
     self.assertTrue(plugnplay.normalize_path(plugindir) + '.otherplug' in sys.modules)
Esempio n. 4
0
 def test_normalize_path_complex(self):
     self.assertEquals("pnp.some.module.path", normalize_path("/some/module/path"))
     self.assertEquals("pnp.other.module.path", normalize_path("./other/module/path"))
     self.assertEquals("pnp.some.module.path", normalize_path("../..//some//module/path"))
     self.assertEquals("pnp.some.module.path", normalize_path("/some/../module/path/"))
Esempio n. 5
0
 def test_normalize_path(self):
     assert "pnp.tmp.a.c.b" == normalize_path("/tmp/a/c/b")
     assert None == normalize_path(None)
Esempio n. 6
0
 def test_normalize_path_complex(self):
     self.assertEquals('pnp.some.module.path', normalize_path('/some/module/path'))
     self.assertEquals('pnp.other.module.path', normalize_path('./other/module/path'))
     self.assertEquals('pnp.some.module.path', normalize_path('../..//some//module/path'))
     self.assertEquals('pnp.some.module.path', normalize_path('/some/../module/path/'))
Esempio n. 7
0
 def test_normalize_path(self):
     assert "pnp.tmp.a.c.b" == normalize_path('/tmp/a/c/b')
     assert None == normalize_path(None)