Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
clive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
clive
Merge requests
!301
Bump textual
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Bump textual
mzebrak/bump-textual
into
develop
Overview
0
Commits
14
Pipelines
17
Changes
1
Merged
Mateusz Żebrak
requested to merge
mzebrak/bump-textual
into
develop
1 year ago
Overview
0
Commits
14
Pipelines
17
Changes
1
Expand
Requires:
!298 (merged)
Edited
1 year ago
by
Mateusz Żebrak
0
0
Merge request reports
Viewing commit
a11aa67b
Show latest version
1 file
+
33
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Verified
a11aa67b
Make get_notification_transaction_id wait some time for the notification toast
· a11aa67b
Mateusz Żebrak
authored
1 year ago
tests/clive-local-tools/clive_local_tools/tui/textual.py
+
33
−
12
Options
from
__future__
import
annotations
import
asyncio
import
re
from
typing
import
TYPE_CHECKING
,
Final
@@ -33,15 +34,35 @@ async def get_notification_transaction_id(pilot: Pilot[int]) -> str:
If no toast notification is found, will raise an AssertionError. If more than one toast notification is found, will
ignore the rest and return the transaction ID from the last one.
"""
toasts
=
pilot
.
app
.
query
(
Toast
)
contents
=
[
str
(
toast
.
render
())
for
toast
in
toasts
]
transaction_id
=
""
for
content
in
contents
:
result
=
TRANSACTION_ID_RE_PAT
.
search
(
content
)
if
result
is
not
None
:
transaction_id
=
result
.
group
(
"
transaction_id
"
)
message
=
f
"
Toast notification containing the transaction ID couldn
'
t be found. Current toasts are:
{
contents
}
"
assert
transaction_id
,
message
return
transaction_id
seconds_to_wait
:
Final
[
float
]
=
3.0
async
def
look_for_transaction_id_in_toasts
()
->
str
:
toasts
=
pilot
.
app
.
query
(
Toast
)
contents
=
[
str
(
toast
.
render
())
for
toast
in
toasts
]
transaction_id
=
""
for
content
in
contents
:
result
=
TRANSACTION_ID_RE_PAT
.
search
(
content
)
if
result
is
not
None
:
transaction_id
=
result
.
group
(
"
transaction_id
"
)
return
transaction_id
async
def
wait_for_transaction_id_to_be_found
()
->
str
:
seconds_already_waited
=
0.0
pool_time
=
0.1
while
True
:
transaction_id
=
await
look_for_transaction_id_in_toasts
()
if
transaction_id
:
return
transaction_id
tt
.
logger
.
info
(
f
"
Didn
'
t find the transaction ID in the toast notification. Already waited
{
seconds_already_waited
}
s
"
)
await
asyncio
.
sleep
(
pool_time
)
seconds_already_waited
+=
pool_time
try
:
return
await
asyncio
.
wait_for
(
wait_for_transaction_id_to_be_found
(),
timeout
=
seconds_to_wait
)
except
asyncio
.
TimeoutError
:
raise
AssertionError
(
f
"
Toast notification containing the transaction ID couldn
'
t be found. Waited
{
seconds_to_wait
}
s
"
)
from
None
Loading