Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_reload_plugins_removes_one_adds_one(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)
            self.assertNotIn("c", subcommands_available)

        with pip_install(self.project_c_fixtures_root, "c"):
            available_plugins = set(discover_plugins())
            self.assertSetEqual({"allennlp_plugins.c"}, available_plugins)

            import_plugins()
            subcommands_available = Subcommand.list_available()
            self.assertNotIn("a", subcommands_available)
            self.assertIn("c", subcommands_available)
Esempio n. 4
0
    def test_subcommand_plugin_is_available(self):
        plugins_root = self.FIXTURES_ROOT / "plugins"
        allennlp_server_fixtures_root = plugins_root / "allennlp_server"

        sys.argv = ["allennlp"]

        with pip_install(
            allennlp_server_fixtures_root, "allennlp_server"
        ), io.StringIO() as buf, redirect_stdout(buf):
            main()
            output = buf.getvalue()

        self.assertIn("    serve", output)
Esempio n. 5
0
    def test_namespace_plugin_loaded(self):
        plugins_root = self.FIXTURES_ROOT / "plugins"
        # "a" sets a "global" namespace plugin, because it's gonna be installed with pip.
        project_a_fixtures_root = plugins_root / "project_a"

        sys.argv = ["allennlp"]

        available_plugins = set(discover_plugins())
        self.assertSetEqual(set(), available_plugins)

        with pip_install(project_a_fixtures_root, "a"):
            main()

        subcommands_available = Subcommand.list_available()
        self.assertIn("a", subcommands_available)