11import os
22import unittest
33import tempfile
4+ import textwrap
45
56from bpython import config
67
78TEST_THEME_PATH = os .path .join (os .path .dirname (__file__ ), "test.theme" )
89
910class TestConfig (unittest .TestCase ):
11+ def load_temp_config (self , content , struct = None ):
12+ """Write config to a temporary file and load it."""
13+
14+ if struct is None :
15+ struct = config .Struct ()
16+
17+ with tempfile .NamedTemporaryFile () as f :
18+ f .write (content .encode ('utf8' ))
19+ f .flush ()
20+
21+ config .loadini (struct , f .name )
22+
23+ return struct
24+
1025 def test_load_theme (self ):
1126 struct = config .Struct ()
1227 struct .color_scheme = dict ()
@@ -19,13 +34,30 @@ def test_load_theme(self):
1934 config .load_theme (struct , TEST_THEME_PATH , struct .color_scheme , defaults )
2035 self .assertEquals (struct .color_scheme , expected )
2136
22- def test_load_config (self ):
23- struct = config .Struct ()
24- with tempfile .NamedTemporaryFile () as f :
25- f .write ('' .encode ('utf8' ))
26- f .write ('[keyboard]\n help = C-h\n ' .encode ('utf8' ))
27- f .flush ()
28- config .loadini (struct , f .name )
37+ def test_keybindings_use_default (self ):
38+ struct = self .load_temp_config (textwrap .dedent ("""
39+ [keyboard]
40+ help = F1
41+ """ ))
42+
43+ self .assertEqual (struct .help_key , 'F1' )
44+
45+ def test_keybindings_use_other_default (self ):
46+ struct = self .load_temp_config (textwrap .dedent ("""
47+ [keyboard]
48+ help = C-h
49+ """ ))
50+
2951 self .assertEqual (struct .help_key , 'C-h' )
3052 self .assertEqual (struct .backspace_key , '' )
3153
54+ def test_keybindings_use_other_default_issue_447 (self ):
55+ struct = self .load_temp_config (textwrap .dedent ("""
56+ [keyboard]
57+ help = F2
58+ show_source = F9
59+ """ ))
60+
61+ self .assertEqual (struct .help_key , 'F2' )
62+ self .assertEqual (struct .show_source_key , 'F9' )
63+
0 commit comments