FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/src/pythonnative/testing/__init__.py at main · pythonnative/pythonnative · GitHub
pythonnative
/
pythonnative
Public
Notifications
You must be signed in to change notification settings
Fork
23
Star
131
Code
Issues
11
Pull requests
4
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
testing
/
__init__.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (71 loc) · 2.84 KB
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
testing
/
__init__.py
Copy path
File metadata and controls
79 lines (71 loc) · 2.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Test utilities: render components without a device.
```python
import pythonnative as pn
from pythonnative.testing import render, render_hook, wait_for, within
@pn.component
def Counter():
count, set_count = pn.use_state(0)
return pn.Column(
pn.Text(f"Count: {count}"),
pn.Button("+", on_press=lambda: set_count(count + 1)),
)
def test_counter_increments():
result = render(Counter())
result.press(result.get_by_role("button", name="+"))
assert result.get_by_text("Count: 1")
def test_use_state():
hook = render_hook(lambda: pn.use_state("a"))
hook.act(lambda: hook.current[1]("b"))
assert hook.current[0] == "b"
def test_timer(pn_clock):
result = render(Toast()) # hides itself after asyncio.sleep(3)
pn_clock.advance(3.0) # timers fire, no real sleep
assert wait_for(lambda: result.query_by_text("Saved") is None)
```
- [`render`][pythonnative.testing.render] mounts an element into a
[`FakeBackend`][pythonnative.testing.FakeBackend] and returns a
[`RenderResult`][pythonnative.testing.RenderResult] with Testing
Library-style queries (``get_by_text``, ``get_by_test_id``,
``get_by_label``, ``get_by_type``, ``get_by_role``,
``get_by_placeholder_text``, ``get_by_display_value``, each with
``query_by_``, ``get_all_by_``, and ``find_by_`` variants) and event
helpers (``press``, ``fire``, ``change_text``, ``back``, ``act``).
- [`within`][pythonnative.testing.within] scopes the same queries to one
view's subtree; [`wait_for`][pythonnative.testing.wait_for] polls a
predicate while draining the framework loop.
- [`render_hook`][pythonnative.testing.render_hook] runs a hook in a
throwaway component.
- [`settle`][pythonnative.testing.settle] pumps the framework loop so
async work (resources, queries, transitions) completes.
- [`fake_clock`][pythonnative.testing.fake_clock] (and the ``pn_clock``
pytest fixture) installs a [`FakeClock`][pythonnative.testing.FakeClock]
so ``asyncio`` timers run on virtual time.
- [`FakeHost`][pythonnative.testing.FakeHost] stands in for a native
screen host so root stack navigators can be tested.
- ``pythonnative.testing.pytest_plugin`` is registered with pytest
automatically and resets the runtime between tests.
"""
from
.
backend
import
DEFAULT_INTRINSIC
,
IMPLICIT_ROLES
,
FakeBackend
,
FakeView
from
.
clock
import
FakeClock
,
current_fake_clock
,
fake_clock
from
.
harness
import
FakeHost
,
HookResult
,
RenderResult
,
render
,
render_hook
,
settle
from
.
queries
import
Matcher
,
Queries
,
Scope
,
wait_for
,
within
__all__
=
[
"DEFAULT_INTRINSIC"
,
"IMPLICIT_ROLES"
,
"FakeBackend"
,
"FakeClock"
,
"FakeHost"
,
"FakeView"
,
"HookResult"
,
"Matcher"
,
"Queries"
,
"RenderResult"
,
"Scope"
,
"current_fake_clock"
,
"fake_clock"
,
"render"
,
"render_hook"
,
"settle"
,
"wait_for"
,
"within"
,
]
Back
|
FazBrowse Home
|
New Git URL