FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
textual/tests/test_parser.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
/
test_parser.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (42 loc) · 1.74 KB
Breadcrumbs
textual
/
tests
/
test_parser.py
Copy path
File metadata and controls
53 lines (42 loc) · 1.74 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
from
textual
.
_parser
import
Parser
def
test_read1
():
class
TestParser
(
Parser
[
str
]):
"""A simple parser that reads a byte at a time from a stream."""
def
parse
(
self
,
on_token
):
while
True
:
data
=
yield
self
.
read1
()
if
not
data
:
break
on_token
(
data
)
test_parser
=
TestParser
()
test_data
=
"Where there is a Will there is a way!"
for
size
in
range
(
1
,
len
(
test_data
)
+
1
):
# Feed the parser in pieces, first 1 character at a time, then 2, etc
data
=
[]
for
offset
in
range
(
0
,
len
(
test_data
),
size
):
for
chunk
in
test_parser
.
feed
(
test_data
[
offset
:
offset
+
size
]):
data
.
append
(
chunk
)
# Check we have received all the data in characters, no matter the fee dsize
assert
len
(
data
)
==
len
(
test_data
)
assert
""
.
join
(
data
)
==
test_data
def
test_read
():
class
TestParser
(
Parser
[
str
]):
"""A parser that reads chunks of a given size from the stream."""
def
__init__
(
self
,
size
):
self
.
size
=
size
super
().
__init__
()
def
parse
(
self
,
on_token
):
while
True
:
data
=
yield
self
.
read1
()
if
not
data
:
break
on_token
(
data
)
test_data
=
"Where there is a Will there is a way!"
for
read_size
in
range
(
1
,
len
(
test_data
)
+
1
):
for
size
in
range
(
1
,
len
(
test_data
)
+
1
):
test_parser
=
TestParser
(
read_size
)
data
=
[]
for
offset
in
range
(
0
,
len
(
test_data
),
size
):
for
chunk
in
test_parser
.
feed
(
test_data
[
offset
:
offset
+
size
]):
data
.
append
(
chunk
)
assert
""
.
join
(
data
)
==
test_data
Back
|
FazBrowse Home
|
New Git URL