<NME> test_config.py
<BEF> # Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import unittest

from awsshell.app import AWSShell
from awsshell.config import Config


class ConfigTest(unittest.TestCase):

    def setUp(self):
        self.load_config()

    def load_config(self):
        config = Config()
        self.config_obj = config.load('awsshellrc', 'test-awsshellrc')
        self.config_section = self.config_obj['aws-shell']

    def test_config_off(self):
        self.config_section['match_fuzzy'] = False
        self.config_section['enable_vi_bindings'] = False
        self.config_section['show_completion_columns'] = False
        self.config_section['show_help'] = False
        self.config_section['theme'] = 'none'
        self.config_obj.write()
        self.load_config()
        assert self.config_section.as_bool('match_fuzzy') == False
        assert self.config_section.as_bool('enable_vi_bindings') == False
        assert self.config_section.as_bool('show_completion_columns') == False
        assert self.config_section.as_bool('show_help') == False
        assert self.config_section['theme'] == 'none'

    def test_config_on(self):
        self.config_section['match_fuzzy'] = True
        self.config_section['enable_vi_bindings'] = True
        self.config_section['show_completion_columns'] = True
        self.config_section['show_help'] = True
        self.config_section['theme'] = 'vim'
        self.config_obj.write()
        self.load_config()
        assert self.config_section.as_bool('match_fuzzy') == True
        assert self.config_section.as_bool('enable_vi_bindings') == True
        assert self.config_section.as_bool('show_completion_columns') == True
        assert self.config_section.as_bool('show_help') == True
        assert self.config_section['theme'] == 'vim'

<MSG> Merge branch 'improve-config-test'

* improve-config-test:
  Improve config test.

<DFF> @@ -10,46 +10,51 @@
 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 # ANY KIND, either express or implied. See the License for the specific
 # language governing permissions and limitations under the License.
+import mock
+import os
 import unittest
 
 from awsshell.app import AWSShell
 from awsshell.config import Config
+from awsshell.utils import build_config_file_path
 
 
 class ConfigTest(unittest.TestCase):
 
-    def setUp(self):
-        self.load_config()
-
-    def load_config(self):
-        config = Config()
-        self.config_obj = config.load('awsshellrc', 'test-awsshellrc')
-        self.config_section = self.config_obj['aws-shell']
-
     def test_config_off(self):
-        self.config_section['match_fuzzy'] = False
-        self.config_section['enable_vi_bindings'] = False
-        self.config_section['show_completion_columns'] = False
-        self.config_section['show_help'] = False
-        self.config_section['theme'] = 'none'
-        self.config_obj.write()
-        self.load_config()
-        assert self.config_section.as_bool('match_fuzzy') == False
-        assert self.config_section.as_bool('enable_vi_bindings') == False
-        assert self.config_section.as_bool('show_completion_columns') == False
-        assert self.config_section.as_bool('show_help') == False
-        assert self.config_section['theme'] == 'none'
+        try:
+            os.remove(build_config_file_path('test-awsshellrc'))
+        except OSError:
+            pass
+        self.aws_shell = AWSShell(None, mock.Mock(),
+                                  None, mock.Mock())
+        self.aws_shell.model_completer.match_fuzzy = False
+        self.aws_shell.enable_vi_bindings = False
+        self.aws_shell.show_completion_columns = False
+        self.aws_shell.show_help = False
+        self.aws_shell.theme = 'none'
+        self.aws_shell.save_config()
+        self.aws_shell.load_config()
+        assert self.aws_shell.model_completer.match_fuzzy == False
+        assert self.aws_shell.enable_vi_bindings == False
+        assert self.aws_shell.show_completion_columns == False
+        assert self.aws_shell.show_help == False
+        assert self.aws_shell.theme == 'none'
 
     def test_config_on(self):
-        self.config_section['match_fuzzy'] = True
-        self.config_section['enable_vi_bindings'] = True
-        self.config_section['show_completion_columns'] = True
-        self.config_section['show_help'] = True
-        self.config_section['theme'] = 'vim'
-        self.config_obj.write()
-        self.load_config()
-        assert self.config_section.as_bool('match_fuzzy') == True
-        assert self.config_section.as_bool('enable_vi_bindings') == True
-        assert self.config_section.as_bool('show_completion_columns') == True
-        assert self.config_section.as_bool('show_help') == True
-        assert self.config_section['theme'] == 'vim'
+        self.aws_shell = AWSShell(None, mock.Mock(),
+                                  None, mock.Mock())
+        self.aws_shell.model_completer.match_fuzzy = True
+        self.aws_shell.enable_vi_bindings = True
+        self.aws_shell.show_completion_columns = True
+        self.aws_shell.show_help = True
+        self.aws_shell.theme = 'vim'
+        self.aws_shell.save_config()
+        self.aws_shell.load_config()
+        assert self.aws_shell.config_section.as_bool('match_fuzzy') == True
+        assert self.aws_shell.config_section.as_bool(
+            'enable_vi_bindings') == True
+        assert self.aws_shell.config_section.as_bool(
+            'show_completion_columns') == True
+        assert self.aws_shell.config_section.as_bool('show_help') == True
+        assert self.aws_shell.config_section['theme'] == 'vim'

{'commit': 'diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py\nindex d00e677..ced3aa8 100644\n--- a/tests/integration/test_config.py\n+++ b/tests/integration/test_config.py\n@@ -10,46 +10,51 @@\n # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n # ANY KIND, either express or implied. See the License for the specific\n # language governing permissions and limitations under the License.\n+import mock\n+import os\n import unittest\n \n from awsshell.app import AWSShell\n from awsshell.config import Config\n+from awsshell.utils import build_config_file_path\n \n \n class ConfigTest(unittest.TestCase):\n \n-    def setUp(self):\n-        self.load_config()\n-\n-    def load_config(self):\n-        config = Config()\n-        self.config_obj = config.load(\'awsshellrc\', \'test-awsshellrc\')\n-        self.config_section = self.config_obj[\'aws-shell\']\n-\n     def test_config_off(self):\n-        self.config_section[\'match_fuzzy\'] = False\n-        self.config_section[\'enable_vi_bindings\'] = False\n-        self.config_section[\'show_completion_columns\'] = False\n-        self.config_section[\'show_help\'] = False\n-        self.config_section[\'theme\'] = \'none\'\n-        self.config_obj.write()\n-        self.load_config()\n-        assert self.config_section.as_bool(\'match_fuzzy\') == False\n-        assert self.config_section.as_bool(\'enable_vi_bindings\') == False\n-        assert self.config_section.as_bool(\'show_completion_columns\') == False\n-        assert self.config_section.as_bool(\'show_help\') == False\n-        assert self.config_section[\'theme\'] == \'none\'\n+        try:\n+            os.remove(build_config_file_path(\'test-awsshellrc\'))\n+        except OSError:\n+            pass\n+        self.aws_shell = AWSShell(None, mock.Mock(),\n+                                  None, mock.Mock())\n+        self.aws_shell.model_completer.match_fuzzy = False\n+        self.aws_shell.enable_vi_bindings = False\n+        self.aws_shell.show_completion_columns = False\n+        self.aws_shell.show_help = False\n+        self.aws_shell.theme = \'none\'\n+        self.aws_shell.save_config()\n+        self.aws_shell.load_config()\n+        assert self.aws_shell.model_completer.match_fuzzy == False\n+        assert self.aws_shell.enable_vi_bindings == False\n+        assert self.aws_shell.show_completion_columns == False\n+        assert self.aws_shell.show_help == False\n+        assert self.aws_shell.theme == \'none\'\n \n     def test_config_on(self):\n-        self.config_section[\'match_fuzzy\'] = True\n-        self.config_section[\'enable_vi_bindings\'] = True\n-        self.config_section[\'show_completion_columns\'] = True\n-        self.config_section[\'show_help\'] = True\n-        self.config_section[\'theme\'] = \'vim\'\n-        self.config_obj.write()\n-        self.load_config()\n-        assert self.config_section.as_bool(\'match_fuzzy\') == True\n-        assert self.config_section.as_bool(\'enable_vi_bindings\') == True\n-        assert self.config_section.as_bool(\'show_completion_columns\') == True\n-        assert self.config_section.as_bool(\'show_help\') == True\n-        assert self.config_section[\'theme\'] == \'vim\'\n+        self.aws_shell = AWSShell(None, mock.Mock(),\n+                                  None, mock.Mock())\n+        self.aws_shell.model_completer.match_fuzzy = True\n+        self.aws_shell.enable_vi_bindings = True\n+        self.aws_shell.show_completion_columns = True\n+        self.aws_shell.show_help = True\n+        self.aws_shell.theme = \'vim\'\n+        self.aws_shell.save_config()\n+        self.aws_shell.load_config()\n+        assert self.aws_shell.config_section.as_bool(\'match_fuzzy\') == True\n+        assert self.aws_shell.config_section.as_bool(\n+            \'enable_vi_bindings\') == True\n+        assert self.aws_shell.config_section.as_bool(\n+            \'show_completion_columns\') == True\n+        assert self.aws_shell.config_section.as_bool(\'show_help\') == True\n+        assert self.aws_shell.config_section[\'theme\'] == \'vim\'\n', 'commit_subject': "Merge branch 'improve-config-test'", 'repo_name': 'awslabs/aws-shell', 'committer': {'name': 'James Saryerwinnie', 'email': '93f8bb0eb2c659b85694486c41717eaf0fe23cd4@jamesls.com', 'time_sec': '1450204174', 'tz_offset': '-480', 'date': {'seconds': '1450204174'}}, 'commit_tree': '07b1a5714717dde3be656e808704e4fad63d145a', 'commit_message': "Merge branch 'improve-config-test'\n\n* improve-config-test:\n  Improve config test.\n", 'language_name': 'Python', 'license': 'apache-2.0', 'hunks': '@@ -10,46 +10,51 @@\n # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n # ANY KIND, either express or implied. See the License for the specific\n # language governing permissions and limitations under the License.\n+import mock\n+import os\n import unittest\n \n from awsshell.app import AWSShell\n from awsshell.config import Config\n+from awsshell.utils import build_config_file_path\n \n \n class ConfigTest(unittest.TestCase):\n \n-    def setUp(self):\n-        self.load_config()\n-\n-    def load_config(self):\n-        config = Config()\n-        self.config_obj = config.load(\'awsshellrc\', \'test-awsshellrc\')\n-        self.config_section = self.config_obj[\'aws-shell\']\n-\n     def test_config_off(self):\n-        self.config_section[\'match_fuzzy\'] = False\n-        self.config_section[\'enable_vi_bindings\'] = False\n-        self.config_section[\'show_completion_columns\'] = False\n-        self.config_section[\'show_help\'] = False\n-        self.config_section[\'theme\'] = \'none\'\n-        self.config_obj.write()\n-        self.load_config()\n-        assert self.config_section.as_bool(\'match_fuzzy\') == False\n-        assert self.config_section.as_bool(\'enable_vi_bindings\') == False\n-        assert self.config_section.as_bool(\'show_completion_columns\') == False\n-        assert self.config_section.as_bool(\'show_help\') == False\n-        assert self.config_section[\'theme\'] == \'none\'\n+        try:\n+            os.remove(build_config_file_path(\'test-awsshellrc\'))\n+        except OSError:\n+            pass\n+        self.aws_shell = AWSShell(None, mock.Mock(),\n+                                  None, mock.Mock())\n+        self.aws_shell.model_completer.match_fuzzy = False\n+        self.aws_shell.enable_vi_bindings = False\n+        self.aws_shell.show_completion_columns = False\n+        self.aws_shell.show_help = False\n+        self.aws_shell.theme = \'none\'\n+        self.aws_shell.save_config()\n+        self.aws_shell.load_config()\n+        assert self.aws_shell.model_completer.match_fuzzy == False\n+        assert self.aws_shell.enable_vi_bindings == False\n+        assert self.aws_shell.show_completion_columns == False\n+        assert self.aws_shell.show_help == False\n+        assert self.aws_shell.theme == \'none\'\n \n     def test_config_on(self):\n-        self.config_section[\'match_fuzzy\'] = True\n-        self.config_section[\'enable_vi_bindings\'] = True\n-        self.config_section[\'show_completion_columns\'] = True\n-        self.config_section[\'show_help\'] = True\n-        self.config_section[\'theme\'] = \'vim\'\n-        self.config_obj.write()\n-        self.load_config()\n-        assert self.config_section.as_bool(\'match_fuzzy\') == True\n-        assert self.config_section.as_bool(\'enable_vi_bindings\') == True\n-        assert self.config_section.as_bool(\'show_completion_columns\') == True\n-        assert self.config_section.as_bool(\'show_help\') == True\n-        assert self.config_section[\'theme\'] == \'vim\'\n+        self.aws_shell = AWSShell(None, mock.Mock(),\n+                                  None, mock.Mock())\n+        self.aws_shell.model_completer.match_fuzzy = True\n+        self.aws_shell.enable_vi_bindings = True\n+        self.aws_shell.show_completion_columns = True\n+        self.aws_shell.show_help = True\n+        self.aws_shell.theme = \'vim\'\n+        self.aws_shell.save_config()\n+        self.aws_shell.load_config()\n+        assert self.aws_shell.config_section.as_bool(\'match_fuzzy\') == True\n+        assert self.aws_shell.config_section.as_bool(\n+            \'enable_vi_bindings\') == True\n+        assert self.aws_shell.config_section.as_bool(\n+            \'show_completion_columns\') == True\n+        assert self.aws_shell.config_section.as_bool(\'show_help\') == True\n+        assert self.aws_shell.config_section[\'theme\'] == \'vim\'\n', 'addition_count': 37, 'deletion_count': 32, 'src_file': 'a/tests/integration/test_config.py', 'tgt_file': 'b/tests/integration/test_config.py', 'file_extension': '.py', 'before_file': '# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the "License"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the "license" file accompanying this file. This file is\n# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport unittest\n\nfrom awsshell.app import AWSShell\nfrom awsshell.config import Config\n\n\nclass ConfigTest(unittest.TestCase):\n\n    def setUp(self):\n        self.load_config()\n\n    def load_config(self):\n        config = Config()\n        self.config_obj = config.load(\'awsshellrc\', \'test-awsshellrc\')\n        self.config_section = self.config_obj[\'aws-shell\']\n\n    def test_config_off(self):\n        self.config_section[\'match_fuzzy\'] = False\n        self.config_section[\'enable_vi_bindings\'] = False\n        self.config_section[\'show_completion_columns\'] = False\n        self.config_section[\'show_help\'] = False\n        self.config_section[\'theme\'] = \'none\'\n        self.config_obj.write()\n        self.load_config()\n        assert self.config_section.as_bool(\'match_fuzzy\') == False\n        assert self.config_section.as_bool(\'enable_vi_bindings\') == False\n        assert self.config_section.as_bool(\'show_completion_columns\') == False\n        assert self.config_section.as_bool(\'show_help\') == False\n        assert self.config_section[\'theme\'] == \'none\'\n\n    def test_config_on(self):\n        self.config_section[\'match_fuzzy\'] = True\n        self.config_section[\'enable_vi_bindings\'] = True\n        self.config_section[\'show_completion_columns\'] = True\n        self.config_section[\'show_help\'] = True\n        self.config_section[\'theme\'] = \'vim\'\n        self.config_obj.write()\n        self.load_config()\n        assert self.config_section.as_bool(\'match_fuzzy\') == True\n        assert self.config_section.as_bool(\'enable_vi_bindings\') == True\n        assert self.config_section.as_bool(\'show_completion_columns\') == True\n        assert self.config_section.as_bool(\'show_help\') == True\n        assert self.config_section[\'theme\'] == \'vim\'\n', 'message': "Merge branch 'improve-config-test'\n\n* improve-config-test:\n  Improve config test.\n", 'author_name': 'James Saryerwinnie', 'lang': 'py'}