Exemplo n.º 1
0
 def test_import_and_register_success(self, mock_warning, mock_import,
                                      mock_register):
     """Test import_and_register() on a valid package."""
     return_value = package_registrar.import_and_register("valid-package")
     self.assertTrue(return_value)
     mock_warning.assert_not_called()
     mock_import.assert_called_once_with("valid-package")
     mock_register.assert_called_once()
Exemplo n.º 2
0
 def test_import_and_register_import_failure(self, mock_warning,
                                             mock_import, mock_register):
     """Test import_and_register() on a nonexistent package."""
     return_value = package_registrar.import_and_register(
         "nonexistent-package", include_cli_instructions=True)
     self.assertFalse(return_value)
     self.assertEqual(mock_warning.call_count, 2)
     mock_import.assert_called_once_with("nonexistent-package")
     mock_register.assert_not_called()
Exemplo n.º 3
0
    def register(self, package_name: str) -> None:
        """Registers the given package with GDM CLI.

    Args:
      package_name: Name of the package to register. For example,
        "foo_extension_package" or "my_package.bar_devices".

    Note that this only registers the package for CLI usage. Tests and Python
    interpreter users must use package_registrar.register() instead.
    """
        registered_cli_packages = self.config.get("cli_extension_packages", [])
        if package_name not in registered_cli_packages:
            if package_registrar.import_and_register(
                    package_name, include_cli_instructions=True):
                self._set_config_prop("cli_extension_packages",
                                      registered_cli_packages + [package_name])
                logger.info(
                    f"Registered package {package_name!r} with GDM CLI.")
        else:
            logger.info(
                f"Package {package_name!r} is already registered with GDM CLI."
            )