def test_local_and_two_global_namespace_plugins(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) # We make plugins "a" and "c" available as packages, each from other directories, as if they were # separate installed projects ("global" usage of the plugins). # We move to another directory with a different plugin "b", as if it were another separate project # which is not installed ("local" usage of the plugin declared in the namespace). with pip_install(self.project_a_fixtures_root, "a"), pip_install( self.project_c_fixtures_root, "c"), push_python_project(self.project_b_fixtures_root): available_plugins = set(discover_plugins()) self.assertSetEqual( { "allennlp_plugins.a", "allennlp_plugins.b", "allennlp_plugins.c" }, available_plugins, ) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("a", subcommands_available) self.assertIn("b", subcommands_available) self.assertIn("c", subcommands_available)
def test_unload_plugin(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) with pip_install(self.project_a_fixtures_root, "a"): available_plugins = set(discover_plugins()) self.assertSetEqual({"allennlp_plugins.a"}, available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("a", subcommands_available) available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertNotIn("a", subcommands_available)
def test_file_plugin(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) with pushd(self.project_d_fixtures_root): available_plugins = set(discover_plugins()) self.assertSetEqual({"d"}, available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("d", subcommands_available)
def test_local_namespace_plugin(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) with pushd(self.project_b_fixtures_root): available_plugins = set(discover_plugins()) self.assertSetEqual({"allennlp_plugins.b"}, available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("b", subcommands_available)
def test_file_plugin(self): available_plugins = set(discover_plugins()) assert available_plugins == set() with pushd(self.plugins_root): available_plugins = set(discover_plugins()) assert available_plugins == {"d"} import_plugins() subcommands_available = Subcommand.list_available() assert "d" in subcommands_available
def test_two_global_namespace_plugins(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) with pip_install(self.project_a_fixtures_root, "a"), pip_install( self.project_c_fixtures_root, "c" ): available_plugins = set(discover_plugins()) self.assertSetEqual({"allennlp_plugins.a", "allennlp_plugins.c"}, available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("a", subcommands_available) self.assertIn("c", subcommands_available)
def test_local_namespace_plugin_different_path(self): available_plugins = set(discover_plugins()) self.assertSetEqual(set(), available_plugins) with tempfile.TemporaryDirectory() as temp_dir_b: distutils.dir_util.copy_tree(self.project_b_fixtures_root, temp_dir_b) # We move to another directory with a different plugin "b", as if it were another # separate project which is not installed ("local" usage of the plugin declared in # the namespace). with pushd(temp_dir_b): available_plugins = set(discover_plugins()) self.assertSetEqual({"allennlp_plugins.b"}, available_plugins) import_plugins() subcommands_available = Subcommand.list_available() self.assertIn("b", subcommands_available)