Skip to content

Commit 350a8ad

Browse files
committed
Improve config test.
Add step to clean config file. Now exercises both the AWSShell attributes and the configobj itself.
1 parent dca3384 commit 350a8ad

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

tests/integration/test_config.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,51 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
import mock
14+
import os
1315
import unittest
1416

1517
from awsshell.app import AWSShell
1618
from awsshell.config import Config
19+
from awsshell.utils import build_config_file_path
1720

1821

1922
class ConfigTest(unittest.TestCase):
2023

21-
def setUp(self):
22-
self.load_config()
23-
24-
def load_config(self):
25-
config = Config()
26-
self.config_obj = config.load('awsshellrc', 'test-awsshellrc')
27-
self.config_section = self.config_obj['aws-shell']
28-
2924
def test_config_off(self):
30-
self.config_section['match_fuzzy'] = False
31-
self.config_section['enable_vi_bindings'] = False
32-
self.config_section['show_completion_columns'] = False
33-
self.config_section['show_help'] = False
34-
self.config_section['theme'] = 'none'
35-
self.config_obj.write()
36-
self.load_config()
37-
assert self.config_section.as_bool('match_fuzzy') == False
38-
assert self.config_section.as_bool('enable_vi_bindings') == False
39-
assert self.config_section.as_bool('show_completion_columns') == False
40-
assert self.config_section.as_bool('show_help') == False
41-
assert self.config_section['theme'] == 'none'
25+
try:
26+
os.remove(build_config_file_path('test-awsshellrc'))
27+
except OSError:
28+
pass
29+
self.aws_shell = AWSShell(None, mock.Mock(),
30+
None, mock.Mock())
31+
self.aws_shell.model_completer.match_fuzzy = False
32+
self.aws_shell.enable_vi_bindings = False
33+
self.aws_shell.show_completion_columns = False
34+
self.aws_shell.show_help = False
35+
self.aws_shell.theme = 'none'
36+
self.aws_shell.save_config()
37+
self.aws_shell.load_config()
38+
assert self.aws_shell.model_completer.match_fuzzy == False
39+
assert self.aws_shell.enable_vi_bindings == False
40+
assert self.aws_shell.show_completion_columns == False
41+
assert self.aws_shell.show_help == False
42+
assert self.aws_shell.theme == 'none'
4243

4344
def test_config_on(self):
44-
self.config_section['match_fuzzy'] = True
45-
self.config_section['enable_vi_bindings'] = True
46-
self.config_section['show_completion_columns'] = True
47-
self.config_section['show_help'] = True
48-
self.config_section['theme'] = 'vim'
49-
self.config_obj.write()
50-
self.load_config()
51-
assert self.config_section.as_bool('match_fuzzy') == True
52-
assert self.config_section.as_bool('enable_vi_bindings') == True
53-
assert self.config_section.as_bool('show_completion_columns') == True
54-
assert self.config_section.as_bool('show_help') == True
55-
assert self.config_section['theme'] == 'vim'
45+
self.aws_shell = AWSShell(None, mock.Mock(),
46+
None, mock.Mock())
47+
self.aws_shell.model_completer.match_fuzzy = True
48+
self.aws_shell.enable_vi_bindings = True
49+
self.aws_shell.show_completion_columns = True
50+
self.aws_shell.show_help = True
51+
self.aws_shell.theme = 'vim'
52+
self.aws_shell.save_config()
53+
self.aws_shell.load_config()
54+
assert self.aws_shell.config_section.as_bool('match_fuzzy') == True
55+
assert self.aws_shell.config_section.as_bool(
56+
'enable_vi_bindings') == True
57+
assert self.aws_shell.config_section.as_bool(
58+
'show_completion_columns') == True
59+
assert self.aws_shell.config_section.as_bool('show_help') == True
60+
assert self.aws_shell.config_section['theme'] == 'vim'

0 commit comments

Comments
 (0)