Skip to content

Commit

Permalink
feat: add get_app class method to Application (#48)
Browse files Browse the repository at this point in the history
* feat: add get_app

* test: add test
  • Loading branch information
tlambert03 committed Jul 24, 2022
1 parent 6f34971 commit 096096a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app_model/_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Tuple, Type
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Optional, Tuple, Type

import in_n_out as ino
from psygnal import Signal
Expand Down Expand Up @@ -122,6 +122,11 @@ def get_or_create(cls, name: str) -> Application:
"""Get app named `name` or create and return a new one if it doesn't exist."""
return cls._instances[name] if name in cls._instances else cls(name)

@classmethod
def get_app(cls, name: str) -> Optional[Application]:
"""Return app named `name` or None if it doesn't exist."""
return cls._instances.get(name)

@classmethod
def destroy(cls, name: str) -> None:
"""Destroy the `Application` named `name`.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


def test_app_create():
assert Application.get_app("my_app") is None
app = Application("my_app")
assert Application.get_app("my_app") is app

# NOTE: for some strange reason, this test fails if I move this line
# below the error assertion below... I don't know why.
Expand Down

0 comments on commit 096096a

Please sign in to comment.