FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_history.py at master · flyingfishfuse/bpython · GitHub
flyingfishfuse
/
bpython
Public
forked from
bpython/bpython
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
bpython
/
bpython
/
test
/
test_history.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
134 lines (97 loc) · 3.95 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_history.py
Copy path
File metadata and controls
134 lines (97 loc) · 3.95 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# encoding: utf-8
import
io
import
os
from
six
.
moves
import
range
from
bpython
.
config
import
getpreferredencoding
from
bpython
.
history
import
History
from
bpython
.
test
import
unittest
class
TestHistory
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
history
=
History
(
"#%d"
%
x
for
x
in
range
(
1000
))
def
test_is_at_start
(
self
):
self
.
history
.
first
()
self
.
assertNotEqual
(
self
.
history
.
index
,
0
)
self
.
assertTrue
(
self
.
history
.
is_at_end
)
self
.
history
.
forward
()
self
.
assertFalse
(
self
.
history
.
is_at_end
)
def
test_is_at_end
(
self
):
self
.
history
.
last
()
self
.
assertEqual
(
self
.
history
.
index
,
0
)
self
.
assertTrue
(
self
.
history
.
is_at_start
)
self
.
assertFalse
(
self
.
history
.
is_at_end
)
def
test_first
(
self
):
self
.
history
.
first
()
self
.
assertFalse
(
self
.
history
.
is_at_start
)
self
.
assertTrue
(
self
.
history
.
is_at_end
)
def
test_last
(
self
):
self
.
history
.
last
()
self
.
assertTrue
(
self
.
history
.
is_at_start
)
self
.
assertFalse
(
self
.
history
.
is_at_end
)
def
test_back
(
self
):
self
.
assertEqual
(
self
.
history
.
back
(),
"#999"
)
self
.
assertNotEqual
(
self
.
history
.
back
(),
"#999"
)
self
.
assertEqual
(
self
.
history
.
back
(),
"#997"
)
for
x
in
range
(
997
):
self
.
history
.
back
()
self
.
assertEqual
(
self
.
history
.
back
(),
"#0"
)
def
test_forward
(
self
):
self
.
history
.
first
()
self
.
assertEqual
(
self
.
history
.
forward
(),
"#1"
)
self
.
assertNotEqual
(
self
.
history
.
forward
(),
"#1"
)
self
.
assertEqual
(
self
.
history
.
forward
(),
"#3"
)
# 1000 == entries 4 == len(range(1, 3) ===> '#1000' (so +1)
for
x
in
range
(
1000
-
4
-
1
):
self
.
history
.
forward
()
self
.
assertEqual
(
self
.
history
.
forward
(),
"#999"
)
def
test_append
(
self
):
self
.
history
.
append
(
'print "foo
\n
"
\n
'
)
self
.
history
.
append
(
"
\n
"
)
self
.
assertEqual
(
self
.
history
.
back
(),
'print "foo
\n
"'
)
def
test_enter
(
self
):
self
.
history
.
enter
(
"#lastnumber!"
)
self
.
assertEqual
(
self
.
history
.
back
(),
"#lastnumber!"
)
self
.
assertEqual
(
self
.
history
.
forward
(),
"#lastnumber!"
)
def
test_enter_2
(
self
):
self
.
history
.
enter
(
"#50"
)
self
.
assertEqual
(
self
.
history
.
back
(),
"#509"
)
self
.
assertEqual
(
self
.
history
.
back
(),
"#508"
)
self
.
assertEqual
(
self
.
history
.
forward
(),
"#509"
)
def
test_reset
(
self
):
self
.
history
.
enter
(
"#lastnumber!"
)
self
.
history
.
reset
()
self
.
assertEqual
(
self
.
history
.
back
(),
"#999"
)
self
.
assertEqual
(
self
.
history
.
forward
(),
""
)
class
TestHistoryFileAccess
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
filename
=
"history_temp_file"
self
.
encoding
=
getpreferredencoding
()
with
io
.
open
(
self
.
filename
,
"w"
,
encoding
=
self
.
encoding
,
errors
=
"ignore"
)
as
f
:
f
.
write
(
b"#1
\n
#2
\n
"
.
decode
())
def
test_load
(
self
):
history
=
History
()
history
.
load
(
self
.
filename
,
self
.
encoding
)
self
.
assertEqual
(
history
.
entries
, [
"#1"
,
"#2"
])
def
test_append_reload_and_write
(
self
):
history
=
History
()
history
.
append_reload_and_write
(
"#3"
,
self
.
filename
,
self
.
encoding
)
self
.
assertEqual
(
history
.
entries
, [
"#1"
,
"#2"
,
"#3"
])
history
.
append_reload_and_write
(
"#4"
,
self
.
filename
,
self
.
encoding
)
self
.
assertEqual
(
history
.
entries
, [
"#1"
,
"#2"
,
"#3"
,
"#4"
])
def
test_save
(
self
):
history
=
History
()
history
.
entries
=
[]
for
line
in
[
"#1"
,
"#2"
,
"#3"
,
"#4"
]:
history
.
append_to
(
history
.
entries
,
line
)
# save only last 2 lines
history
.
save
(
self
.
filename
,
self
.
encoding
,
lines
=
2
)
# empty the list of entries and load again from the file
history
.
entries
=
[
""
]
history
.
load
(
self
.
filename
,
self
.
encoding
)
self
.
assertEqual
(
history
.
entries
, [
"#3"
,
"#4"
])
def
tearDown
(
self
):
try
:
os
.
remove
(
self
.
filename
)
except
OSError
:
pass
Back
|
FazBrowse Home
|
New Git URL