FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
textual/tests/input/test_input_replace.py at main · PythonWorkbench/textual · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PythonWorkbench
/
textual
Public
forked from
Textualize/textual
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
textual
/
tests
/
input
/
test_input_replace.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (51 loc) · 2.15 KB
Breadcrumbs
textual
/
tests
/
input
/
test_input_replace.py
Copy path
File metadata and controls
64 lines (51 loc) · 2.15 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
from
__future__
import
annotations
import
pytest
from
textual
.
app
import
App
,
ComposeResult
from
textual
.
widgets
import
Input
_FORWARD_DELETIONS
=
[
((
0
,
0
),
"0123456789"
),
# Delete nothing
((
0
,
10
),
""
),
# Delete all
((
0
,
1
),
"123456789"
),
# Delete first character
((
5
,
10
),
"01234"
),
# Delete last 5 characters
((
3
,
6
),
"0126789"
),
# Delete middle 3 characters
((
5
,
20
),
"01234"
),
# Delete past end results in clamp
]
_REVERSE_DELETIONS
=
[
((
end
,
start
),
value_after
)
for
(
start
,
end
),
value_after
in
_FORWARD_DELETIONS
]
DELETIONS
=
_FORWARD_DELETIONS
+
_REVERSE_DELETIONS
"""The same deletions performed in both forward and reverse directions."""
@
pytest
.
mark
.
parametrize
(
"selection,value_after"
,
DELETIONS
)
async
def
test_input_delete
(
selection
:
tuple
[
int
,
int
],
value_after
:
str
):
class
InputApp
(
App
[
None
]):
TEST_TEXT
=
"0123456789"
def
compose
(
self
)
->
ComposeResult
:
yield
Input
(
self
.
TEST_TEXT
)
async
with
InputApp
().
run_test
()
as
pilot
:
app
=
pilot
.
app
input
=
app
.
query_one
(
Input
)
input
.
delete
(
*
selection
)
assert
input
.
value
==
value_after
_FORWARD_REPLACEMENTS
=
[
((
0
,
0
),
""
,
"0123456789"
),
((
0
,
1
),
"X"
,
"X123456789"
),
# Replace first character with "X"
((
5
,
10
),
"X"
,
"01234X"
),
# Replace last 5 characters with "X"
((
3
,
6
),
"X"
,
"012X6789"
),
# Replace middle 3 characters with "X"
((
5
,
20
),
"X"
,
"01234X"
),
# Replace past end results in clamp
]
_REVERSE_REPLACEMENTS
=
[
((
end
,
start
),
replacement
,
result
)
for
(
start
,
end
),
replacement
,
result
in
_FORWARD_REPLACEMENTS
]
REPLACEMENTS
=
_FORWARD_REPLACEMENTS
+
_REVERSE_REPLACEMENTS
@
pytest
.
mark
.
parametrize
(
"selection,replacement,result"
,
REPLACEMENTS
)
async
def
test_input_replace
(
selection
:
tuple
[
int
,
int
],
replacement
:
str
,
result
:
str
):
class
InputApp
(
App
[
None
]):
TEST_TEXT
=
"0123456789"
def
compose
(
self
)
->
ComposeResult
:
yield
Input
(
self
.
TEST_TEXT
)
async
with
InputApp
().
run_test
()
as
pilot
:
app
=
pilot
.
app
input
=
app
.
query_one
(
Input
)
input
.
replace
(
replacement
,
*
selection
)
assert
input
.
value
==
result
Back
|
FazBrowse Home
|
New Git URL