Ejemplo n.º 1
0
def container_registry(application, test_containers_provider,
                       plugin_registry: PluginRegistry):
    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-definitioncontainer",
                 comment="Uranium Definition Container",
                 suffixes=["def.json"]))

    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-instancecontainer",
                 comment="Uranium Instance Container",
                 suffixes=["inst.cfg"]))

    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-containerstack",
                 comment="Uranium Container Stack",
                 suffixes=["stack.cfg"]))

    ContainerRegistry._ContainerRegistry__instance = None  # Reset the private instance variable every time
    registry = ContainerRegistry(application)

    #We need to mock the "priority" plug-in metadata field, but preferably without mocking an entire plug-in.
    with unittest.mock.patch(
            "UM.PluginRegistry.PluginRegistry.getMetaData",
            unittest.mock.MagicMock(return_value={"container_provider": {}})):
        registry.addProvider(test_containers_provider)

    UM.Settings.ContainerStack.setContainerRegistry(registry)
    UM.Settings.InstanceContainer.setContainerRegistry(registry)
    return registry
Ejemplo n.º 2
0
def container_registry(application, test_containers_provider,
                       plugin_registry: PluginRegistry):
    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-definitioncontainer",
                 comment="Uranium Definition Container",
                 suffixes=["def.json"]))

    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-instancecontainer",
                 comment="Uranium Instance Container",
                 suffixes=["inst.cfg"]))

    MimeTypeDatabase.addMimeType(
        MimeType(name="application/x-uranium-containerstack",
                 comment="Uranium Container Stack",
                 suffixes=["stack.cfg"]))

    ContainerRegistry._ContainerRegistry__instance = None  # Reset the private instance variable every time
    registry = ContainerRegistry(application)

    #We need to mock the "priority" plug-in metadata field, but preferably without mocking an entire plug-in.
    with unittest.mock.patch(
            "UM.PluginRegistry.PluginRegistry.getMetaData",
            unittest.mock.MagicMock(return_value={"container_provider": {}})):
        registry.addProvider(test_containers_provider)

    # Make sure that a new database connection is used.
    db_path = os.path.join(Resources.getCacheStoragePath(), "containers.db")
    if os.path.exists(db_path):
        os.remove(db_path)

    container_registry._db_connection = None

    UM.Settings.ContainerStack.setContainerRegistry(registry)
    UM.Settings.InstanceContainer.setContainerRegistry(registry)
    return registry