|
19 | 19 | # Skip tests if there is no readline module |
20 | 20 | readline = import_module('readline') |
21 | 21 |
|
22 | | -if hasattr(readline, "_READLINE_LIBRARY_VERSION"): |
23 | | - is_editline = ("EditLine wrapper" in readline._READLINE_LIBRARY_VERSION) |
24 | | -else: |
25 | | - is_editline = readline.backend == "editline" |
| 22 | +is_editline = readline.backend == "editline" |
26 | 23 |
|
27 | 24 |
|
28 | 25 | def setUpModule(): |
29 | 26 | if verbose: |
30 | | - # Python implementations other than CPython may not have |
31 | | - # these private attributes |
32 | | - if hasattr(readline, "_READLINE_VERSION"): |
33 | | - print(f"readline version: {readline._READLINE_VERSION:#x}") |
34 | | - print(f"readline runtime version: {readline._READLINE_RUNTIME_VERSION:#x}") |
35 | | - if hasattr(readline, "_READLINE_LIBRARY_VERSION"): |
36 | | - print(f"readline library version: {readline._READLINE_LIBRARY_VERSION!r}") |
| 27 | + print(f"readline version: {readline.READLINE_VERSION_INFO}") |
| 28 | + print(f"readline runtime version: {readline.readline_version_info}") |
| 29 | + print(f"readline library version: {readline.readline_version!r}") |
37 | 30 | print(f"use libedit emulation? {is_editline}") |
38 | 31 |
|
39 | 32 |
|
@@ -210,7 +203,36 @@ def test_append_limited_history(self): |
210 | 203 |
|
211 | 204 | class TestReadline(unittest.TestCase): |
212 | 205 |
|
213 | | - @unittest.skipIf(readline._READLINE_VERSION < 0x0601 and not is_editline, |
| 206 | + def _test_readline_version(self, v): |
| 207 | + self.assertIsInstance(v[:], tuple) |
| 208 | + self.assertEqual(len(v), 2) |
| 209 | + self.assertIsInstance(v[0], int) |
| 210 | + self.assertIsInstance(v[1], int) |
| 211 | + self.assertIsInstance(v.major, int) |
| 212 | + self.assertIsInstance(v.minor, int) |
| 213 | + self.assertEqual(v[0], v.major) |
| 214 | + self.assertEqual(v[1], v.minor) |
| 215 | + self.assertGreaterEqual(v.major, 4) |
| 216 | + self.assertGreaterEqual(v.minor, 0) |
| 217 | + |
| 218 | + def test_readline_version(self): |
| 219 | + self._test_readline_version(readline.READLINE_VERSION_INFO) |
| 220 | + self._test_readline_version(readline.readline_version_info) |
| 221 | + self.assertIsInstance(readline.readline_version, str) |
| 222 | + if not is_editline: |
| 223 | + self.assertEqual(readline.readline_version, |
| 224 | + '%d.%d' % readline.readline_version_info) |
| 225 | + # Private names kept for backward compatibility. |
| 226 | + self.assertEqual(readline._READLINE_VERSION, |
| 227 | + readline.READLINE_VERSION_INFO.major << 8 | |
| 228 | + readline.READLINE_VERSION_INFO.minor) |
| 229 | + self.assertEqual(readline._READLINE_RUNTIME_VERSION, |
| 230 | + readline.readline_version_info.major << 8 | |
| 231 | + readline.readline_version_info.minor) |
| 232 | + self.assertIs(readline._READLINE_LIBRARY_VERSION, |
| 233 | + readline.readline_version) |
| 234 | + |
| 235 | + @unittest.skipIf(readline.READLINE_VERSION_INFO < (6, 1) and not is_editline, |
214 | 236 | "not supported in this library version") |
215 | 237 | def test_init(self): |
216 | 238 | # Issue #19884: Ensure that the ANSI sequence "\033[1034h" is not |
@@ -366,7 +388,7 @@ def display(substitution, matches, longest_match_length): |
366 | 388 | # See https://cnswww.cns.cwru.edu/php/chet/readline/CHANGES |
367 | 389 | # - editline: history size is broken on OS X 10.11.6. |
368 | 390 | # Newer versions were not tested yet. |
369 | | - @unittest.skipIf(readline._READLINE_VERSION < 0x600, |
| 391 | + @unittest.skipIf(readline.READLINE_VERSION_INFO < (6, 0), |
370 | 392 | "this readline version does not support history-size") |
371 | 393 | @unittest.skipIf(is_editline, |
372 | 394 | "editline history size configuration is broken") |
|
0 commit comments