FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_curtsies.py at 0.23-release · bpython/bpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
bpython
/
bpython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
252
Star
2.8k
Code
Issues
144
Pull requests
5
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bpython
/
bpython
/
test
/
test_curtsies.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
89 lines (73 loc) · 2.87 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_curtsies.py
Copy path
File metadata and controls
89 lines (73 loc) · 2.87 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
80
81
82
83
84
85
86
87
88
89
import
unittest
from
collections
import
namedtuple
from
bpython
.
curtsies
import
combined_events
from
bpython
.
test
import
FixLanguageTestCase
as
TestCase
import
curtsies
.
events
ScheduledEvent
=
namedtuple
(
"ScheduledEvent"
, [
"when"
,
"event"
])
class
EventGenerator
:
def
__init__
(
self
,
initial_events
=
(),
scheduled_events
=
()):
self
.
_events
=
[]
self
.
_current_tick
=
0
for
e
in
initial_events
:
self
.
schedule_event
(
e
,
0
)
for
e
,
w
in
scheduled_events
:
self
.
schedule_event
(
e
,
w
)
def
schedule_event
(
self
,
event
,
when
):
self
.
_events
.
append
(
ScheduledEvent
(
when
,
event
))
self
.
_events
.
sort
()
def
send
(
self
,
timeout
=
None
):
if
timeout
not
in
[
None
,
0
]:
raise
ValueError
(
"timeout value %r not supported"
%
timeout
)
if
not
self
.
_events
:
return
None
if
self
.
_events
[
0
].
when
<=
self
.
_current_tick
:
return
self
.
_events
.
pop
(
0
).
event
if
timeout
==
0
:
return
None
elif
timeout
is
None
:
e
=
self
.
_events
.
pop
(
0
)
self
.
_current_tick
=
e
.
when
return
e
.
event
else
:
raise
ValueError
(
"timeout value %r not supported"
%
timeout
)
def
tick
(
self
,
dt
=
1
):
self
.
_current_tick
+=
dt
return
self
.
_current_tick
class
TestCurtsiesPasteDetection
(
TestCase
):
def
test_paste_threshold
(
self
):
eg
=
EventGenerator
(
list
(
"abc"
))
cb
=
combined_events
(
eg
,
paste_threshold
=
3
)
e
=
next
(
cb
)
self
.
assertIsInstance
(
e
,
curtsies
.
events
.
PasteEvent
)
self
.
assertEqual
(
e
.
events
,
list
(
"abc"
))
self
.
assertEqual
(
next
(
cb
),
None
)
eg
=
EventGenerator
(
list
(
"abc"
))
cb
=
combined_events
(
eg
,
paste_threshold
=
4
)
self
.
assertEqual
(
next
(
cb
),
"a"
)
self
.
assertEqual
(
next
(
cb
),
"b"
)
self
.
assertEqual
(
next
(
cb
),
"c"
)
self
.
assertEqual
(
next
(
cb
),
None
)
def
test_set_timeout
(
self
):
eg
=
EventGenerator
(
"a"
,
zip
(
"bcdefg"
, [
1
,
2
,
3
,
3
,
3
,
4
]))
eg
.
schedule_event
(
curtsies
.
events
.
SigIntEvent
(),
5
)
eg
.
schedule_event
(
"h"
,
6
)
cb
=
combined_events
(
eg
,
paste_threshold
=
3
)
self
.
assertEqual
(
next
(
cb
),
"a"
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
self
.
assertEqual
(
next
(
cb
),
"b"
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
eg
.
tick
()
self
.
assertEqual
(
cb
.
send
(
0
),
"c"
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
eg
.
tick
()
self
.
assertIsInstance
(
cb
.
send
(
0
),
curtsies
.
events
.
PasteEvent
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
self
.
assertEqual
(
cb
.
send
(
None
),
"g"
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
eg
.
tick
(
1
)
self
.
assertIsInstance
(
cb
.
send
(
0
),
curtsies
.
events
.
SigIntEvent
)
self
.
assertEqual
(
cb
.
send
(
0
),
None
)
self
.
assertEqual
(
cb
.
send
(
None
),
"h"
)
self
.
assertEqual
(
cb
.
send
(
None
),
None
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL