Skip to content

Commit 3e085fd

Browse files
authored
Merge pull request #326 from python-cmd2/fix_unit_tests_gnureadline
Fix unit tests on macOS when gnureadline is installed
2 parents 4cea62a + a1c7244 commit 3e085fd

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

tests/test_argparse.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import argparse
66
import functools
77
import pytest
8-
import readline
98
import sys
109

1110
import cmd2
@@ -14,6 +13,18 @@
1413

1514
from conftest import run_cmd, StdOut
1615

16+
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
17+
try:
18+
import gnureadline as readline
19+
except ImportError:
20+
# Try to import readline, but allow failure for convenience in Windows unit testing
21+
# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
22+
try:
23+
# noinspection PyUnresolvedReferences
24+
import readline
25+
except ImportError:
26+
pass
27+
1728

1829
class ArgparseApp(cmd2.Cmd):
1930
def __init__(self):

tests/test_completion.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111
import argparse
1212
import os
13-
import readline
1413
import sys
1514

1615
import cmd2
@@ -19,6 +18,19 @@
1918

2019
from cmd2 import path_complete, basic_complete, flag_based_complete, index_based_complete
2120

21+
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
22+
try:
23+
import gnureadline as readline
24+
except ImportError:
25+
# Try to import readline, but allow failure for convenience in Windows unit testing
26+
# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
27+
try:
28+
# noinspection PyUnresolvedReferences
29+
import readline
30+
except ImportError:
31+
pass
32+
33+
2234
@pytest.fixture
2335
def cmd2_app():
2436
c = cmd2.Cmd()

0 commit comments

Comments
 (0)