forked from ludwigschwardt/python-gnureadline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
57 lines (43 loc) · 1.8 KB
/
test.py
File metadata and controls
57 lines (43 loc) · 1.8 KB
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
import sys
from os import path
def test_import_new():
"""import gnureadline without touching sys.path"""
import gnureadline
def test_import():
"""A very basic unittest; can we 'import readline'?"""
msg = r'''
readline.so was not installed properly into site-packages.
'import readline' imports %s
sys.path:\n%s'''
# Put site-packages in front of sys.path so we don't end up importing the global
# readline.so
save_sys_path = list(sys.path)
sys.path = (
[p for p in sys.path if 'site-packages' in p] + \
[p for p in sys.path if 'site-packages' not in p])
import readline
try:
assert 'site-packages' in path.dirname(readline.__file__), \
msg % (readline.__file__, '\n'.join(sys.path))
finally:
sys.path = save_sys_path
import gnureadline
assert readline.parse_and_bind is gnureadline.parse_and_bind
def test_history_manipulation():
"""Basic readline functionality checks taken from Lib/test/test_readline.py."""
import gnureadline
gnureadline.clear_history()
gnureadline.add_history("first line")
gnureadline.add_history("second line")
assert gnureadline.get_history_item(0) is None
assert gnureadline.get_history_item(1) == "first line"
assert gnureadline.get_history_item(2) == "second line"
gnureadline.replace_history_item(0, "replaced line")
assert gnureadline.get_history_item(0) is None
assert gnureadline.get_history_item(1) == "replaced line"
assert gnureadline.get_history_item(2) == "second line"
assert gnureadline.get_current_history_length() == 2
gnureadline.remove_history_item(0)
assert gnureadline.get_history_item(0) is None
assert gnureadline.get_history_item(1) == "second line"
assert gnureadline.get_current_history_length() == 1