11import unittest
22
3- from _colorize import ANSIColors
4- from _pyrepl .fancycompleter import Completer , DefaultConfig , commonprefix
5-
6-
7- class ConfigForTest (DefaultConfig ):
8- use_colors = False
9-
10- class ColorConfig (DefaultConfig ):
11- use_colors = True
3+ from _colorize import ANSIColors , get_theme
4+ from _pyrepl .fancycompleter import Completer , commonprefix
125
136class MockPatch :
147 def __init__ (self ):
@@ -41,7 +34,7 @@ def test_commonprefix(self):
4134 self .assertEqual (commonprefix (['aaa' , 'bbb' ], base = 'x' ), '' )
4235
4336 def test_complete_attribute (self ):
44- compl = Completer ({'a' : None }, ConfigForTest )
37+ compl = Completer ({'a' : None }, use_colors = False )
4538 self .assertEqual (compl .attr_matches ('a.' ), ['a.__' ])
4639 matches = compl .attr_matches ('a.__' )
4740 self .assertNotIn ('a.__class__' , matches )
@@ -53,23 +46,23 @@ class C(object):
5346 attr = 1
5447 _attr = 2
5548 __attr__attr = 3
56- compl = Completer ({'a' : C }, ConfigForTest )
49+ compl = Completer ({'a' : C }, use_colors = False )
5750 self .assertEqual (compl .attr_matches ('a.' ), ['attr' , 'mro' ])
5851 self .assertEqual (compl .attr_matches ('a._' ), ['_C__attr__attr' , '_attr' , ' ' ])
5952 matches = compl .attr_matches ('a.__' )
6053 self .assertNotIn ('a.__class__' , matches )
6154 self .assertIn ('__class__' , matches )
6255 self .assertEqual (compl .attr_matches ('a.__class' ), ['a.__class__' ])
6356
64- compl = Completer ({'a' : None }, ConfigForTest )
57+ compl = Completer ({'a' : None }, use_colors = False )
6558 self .assertEqual (compl .attr_matches ('a._' ), ['a.__' ])
6659
6760 def test_complete_attribute_colored (self ):
68- compl = Completer ({'a' : 42 }, ColorConfig )
61+ theme = get_theme ()
62+ compl = Completer ({'a' : 42 }, use_colors = True )
6963 matches = compl .attr_matches ('a.__' )
7064 self .assertGreater (len (matches ), 2 )
71- expected_color = compl .config .color_by_type .get (type (compl .__class__ ))
72- self .assertEqual (expected_color , ANSIColors .BOLD_MAGENTA )
65+ expected_color = theme .fancycompleter .type
7366 expected_part = f'{ expected_color } __class__{ ANSIColors .RESET } '
7467 for match in matches :
7568 if expected_part in match :
@@ -80,28 +73,28 @@ def test_complete_attribute_colored(self):
8073
8174 def test_complete_colored_single_match (self ):
8275 """No coloring, via commonprefix."""
83- compl = Completer ({'foobar' : 42 }, ColorConfig )
76+ compl = Completer ({'foobar' : 42 }, use_colors = True )
8477 matches = compl .global_matches ('foob' )
8578 self .assertEqual (matches , ['foobar' ])
8679
8780 def test_does_not_color_single_match (self ):
8881 class obj :
8982 msgs = []
9083
91- compl = Completer ({'obj' : obj }, ColorConfig )
84+ compl = Completer ({'obj' : obj }, use_colors = True )
9285 matches = compl .attr_matches ('obj.msgs' )
9386 self .assertEqual (matches , ['obj.msgs' ])
9487
9588 def test_complete_global (self ):
96- compl = Completer ({'foobar' : 1 , 'foobazzz' : 2 }, ConfigForTest )
89+ compl = Completer ({'foobar' : 1 , 'foobazzz' : 2 }, use_colors = False )
9790 self .assertEqual (compl .global_matches ('foo' ), ['fooba' ])
9891 matches = compl .global_matches ('fooba' )
9992 self .assertEqual (set (matches ), set (['foobar' , 'foobazzz' ]))
10093 self .assertEqual (compl .global_matches ('foobaz' ), ['foobazzz' ])
10194 self .assertEqual (compl .global_matches ('nothing' ), [])
10295
10396 def test_complete_global_colored (self ):
104- compl = Completer ({'foobar' : 1 , 'foobazzz' : 2 }, ColorConfig )
97+ compl = Completer ({'foobar' : 1 , 'foobazzz' : 2 }, use_colors = True )
10598 self .assertEqual (compl .global_matches ('foo' ), ['fooba' ])
10699 matches = compl .global_matches ('fooba' )
107100
@@ -119,7 +112,7 @@ def test_complete_global_colored(self):
119112 self .assertEqual (compl .global_matches ('nothing' ), [])
120113
121114 def test_complete_global_colored_exception (self ):
122- compl = Completer ({'tryme' : 42 }, ColorConfig )
115+ compl = Completer ({'tryme' : 42 }, use_colors = True )
123116 N0 = f"\x1b [000;00m"
124117 N1 = f"\x1b [001;00m"
125118 self .assertEqual (compl .global_matches ('try' ), [
@@ -129,7 +122,7 @@ def test_complete_global_colored_exception(self):
129122 ])
130123
131124 def test_complete_with_indexer (self ):
132- compl = Completer ({'lst' : [None , 2 , 3 ]}, ConfigForTest )
125+ compl = Completer ({'lst' : [None , 2 , 3 ]}, use_colors = False )
133126 self .assertEqual (compl .attr_matches ('lst[0].' ), ['lst[0].__' ])
134127 matches = compl .attr_matches ('lst[0].__' )
135128 self .assertNotIn ('lst[0].__class__' , matches )
@@ -143,7 +136,7 @@ class A:
143136 abc_2 = None
144137 abc_3 = None
145138 bbb = None
146- compl = Completer ({'A' : A }, ConfigForTest )
139+ compl = Completer ({'A' : A }, use_colors = False )
147140 #
148141 # In this case, we want to display all attributes which start with
149142 # 'a'. Moreover, we also include a space to prevent readline to
@@ -164,23 +157,23 @@ class A:
164157 self .assertEqual (sorted (matches ), [' ' , 'abc_1' , 'abc_2' , 'abc_3' ])
165158
166159 def test_complete_exception (self ):
167- compl = Completer ({}, ConfigForTest )
160+ compl = Completer ({}, use_colors = False )
168161 self .assertEqual (compl .attr_matches ('xxx.' ), [])
169162
170163 def test_complete_invalid_attr (self ):
171- compl = Completer ({'str' : str }, ConfigForTest )
164+ compl = Completer ({'str' : str }, use_colors = False )
172165 self .assertEqual (compl .attr_matches ('str.xx' ), [])
173166
174167 def test_complete_function_skipped (self ):
175- compl = Completer ({'str' : str }, ConfigForTest )
168+ compl = Completer ({'str' : str }, use_colors = False )
176169 self .assertEqual (compl .attr_matches ('str.split().' ), [])
177170
178171 def test_unicode_in___dir__ (self ):
179172 class Foo (object ):
180173 def __dir__ (self ):
181174 return ['hello' , 'world' ]
182175
183- compl = Completer ({'a' : Foo ()}, ConfigForTest )
176+ compl = Completer ({'a' : Foo ()}, use_colors = False )
184177 matches = compl .attr_matches ('a.' )
185178 self .assertEqual (matches , ['hello' , 'world' ])
186179 self .assertIs (type (matches [0 ]), str )
0 commit comments