-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from shiny._namespaces import namespace_context, resolve_id | ||
|
||
|
||
def test_namespaces(): | ||
outer = resolve_id("outer") | ||
assert outer == "outer" | ||
|
||
with namespace_context(outer): | ||
# Check if the namespace_context ("outer") is respected during resolve_id | ||
inner = resolve_id("inner") | ||
assert inner == "outer-inner" | ||
|
||
# You can also use a ResolvedId as a namespace just by calling it with an id str | ||
assert outer("inner") == "outer-inner" | ||
|
||
# If an id is already resolved (based on ResolvedId class), resolving it further | ||
# does nothing | ||
assert resolve_id(outer) == "outer" | ||
|
||
# When namespace contexts are stacked, inner one wins | ||
with namespace_context(inner): | ||
assert resolve_id("inmost") == "outer-inner-inmost" | ||
|
||
# Namespace contexts nest with existing context when string is used | ||
with namespace_context("inner"): | ||
assert resolve_id("inmost") == "outer-inner-inmost" | ||
|
||
# Re-installing the same context as is already in place | ||
with namespace_context(outer): | ||
assert resolve_id("inmost") == "outer-inmost" | ||
|
||
# You can remove the context with None or "" | ||
with namespace_context(None): | ||
assert resolve_id("foo") == "foo" | ||
with namespace_context(""): | ||
assert resolve_id("foo") == "foo" | ||
|
||
# Check that this still works after another context was installed/removed | ||
assert resolve_id("inner") == "outer-inner" |