Skip to content

Commit 1881bef

Browse files
authored
bpo-29854: test_readline logs versions (#2619)
* test_readline logs the versions of libreadline when run in verbose mode * Add also readline._READLINE_LIBRARY_VERSION
1 parent fae8f4a commit 1881bef

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Lib/test/test_readline.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99
import sys
1010
import tempfile
1111
import unittest
12-
from test.support import import_module, unlink, temp_dir, TESTFN
12+
from test.support import import_module, unlink, temp_dir, TESTFN, verbose
1313
from test.support.script_helper import assert_python_ok
1414

1515
# Skip tests if there is no readline module
1616
readline = import_module('readline')
1717

18-
is_editline = readline.__doc__ and "libedit" in readline.__doc__
18+
if hasattr(readline, "_READLINE_LIBRARY_VERSION"):
19+
is_editline = ("EditLine wrapper" in readline._READLINE_LIBRARY_VERSION)
20+
else:
21+
is_editline = (readline.__doc__ and "libedit" in readline.__doc__)
22+
23+
24+
def setUpModule():
25+
if verbose:
26+
# Python implementations other than CPython may not have
27+
# these private attributes
28+
if hasattr(readline, "_READLINE_VERSION"):
29+
print(f"readline version: {readline._READLINE_VERSION:#x}")
30+
print(f"readline runtime version: {readline._READLINE_RUNTIME_VERSION:#x}")
31+
if hasattr(readline, "_READLINE_LIBRARY_VERSION"):
32+
print(f"readline library version: {readline._READLINE_LIBRARY_VERSION!r}")
33+
print(f"use libedit emulation? {is_editline}")
34+
1935

2036
@unittest.skipUnless(hasattr(readline, "clear_history"),
2137
"The history update test cannot be run because the "

Modules/readline.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ PyInit_readline(void)
14271427

14281428
PyModule_AddIntConstant(m, "_READLINE_VERSION", RL_READLINE_VERSION);
14291429
PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION", rl_readline_version);
1430+
PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION", rl_library_version);
14301431

14311432
return m;
14321433
}

0 commit comments

Comments
 (0)