Skip to content

Commit c52fd7a

Browse files
committed
fix it in a different way: just look in the theme to find the expected color. This is both more robust and more correct
1 parent af1d74e commit c52fd7a

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

Lib/test/test_pyrepl/test_fancycompleter.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
import os
3-
from unittest.mock import patch
43

54
from _colorize import ANSIColors, get_theme
65
from _pyrepl.fancycompleter import Completer, commonprefix
@@ -59,7 +58,6 @@ class C(object):
5958
compl = Completer({'a': None}, use_colors=False)
6059
self.assertEqual(compl.attr_matches('a._'), ['a.__'])
6160

62-
@patch.dict(os.environ, {'PYTHON_COLORS': '1'})
6361
def test_complete_attribute_colored(self):
6462
theme = get_theme()
6563
compl = Completer({'a': 42}, use_colors=True)
@@ -96,8 +94,8 @@ def test_complete_global(self):
9694
self.assertEqual(compl.global_matches('foobaz'), ['foobazzz'])
9795
self.assertEqual(compl.global_matches('nothing'), [])
9896

99-
@patch.dict(os.environ, {'PYTHON_COLORS': '1'})
10097
def test_complete_global_colored(self):
98+
theme = get_theme()
10199
compl = Completer({'foobar': 1, 'foobazzz': 2}, use_colors=True)
102100
self.assertEqual(compl.global_matches('foo'), ['fooba'])
103101
matches = compl.global_matches('fooba')
@@ -106,26 +104,15 @@ def test_complete_global_colored(self):
106104
# readline displays the matches in the proper order
107105
N0 = f"\x1b[000;00m"
108106
N1 = f"\x1b[001;00m"
109-
107+
int_color = theme.fancycompleter.int
110108
self.assertEqual(set(matches), {
111109
' ',
112-
f'{N0}{ANSIColors.BOLD_YELLOW}foobar{ANSIColors.RESET}',
113-
f'{N1}{ANSIColors.BOLD_YELLOW}foobazzz{ANSIColors.RESET}',
110+
f'{N0}{int_color}foobar{ANSIColors.RESET}',
111+
f'{N1}{int_color}foobazzz{ANSIColors.RESET}',
114112
})
115113
self.assertEqual(compl.global_matches('foobaz'), ['foobazzz'])
116114
self.assertEqual(compl.global_matches('nothing'), [])
117115

118-
@patch.dict(os.environ, {'PYTHON_COLORS': '1'})
119-
def test_complete_global_colored_exception(self):
120-
compl = Completer({'tryme': 42}, use_colors=True)
121-
N0 = f"\x1b[000;00m"
122-
N1 = f"\x1b[001;00m"
123-
self.assertEqual(compl.global_matches('try'), [
124-
f'{N0}{ANSIColors.GREY}try:{ANSIColors.RESET}',
125-
f'{N1}{ANSIColors.BOLD_YELLOW}tryme{ANSIColors.RESET}',
126-
' '
127-
])
128-
129116
def test_complete_with_indexer(self):
130117
compl = Completer({'lst': [None, 2, 3]}, use_colors=False)
131118
self.assertEqual(compl.attr_matches('lst[0].'), ['lst[0].__'])

0 commit comments

Comments
 (0)