summaryrefslogtreecommitdiff
path: root/tests/test_shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_shell.py')
-rw-r--r--tests/test_shell.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/tests/test_shell.py b/tests/test_shell.py
index ebe77e0..28f6b13 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -105,13 +105,11 @@ class ShellCacheSchemaTest(utils.TestCase):
super(ShellCacheSchemaTest, self).setUp()
self._mock_client_setup()
self._mock_shell_setup()
- os.path.exists = mock.MagicMock()
self.cache_dir = '/dir_for_cached_schema'
self.cache_file = self.cache_dir + '/image_schema.json'
def tearDown(self):
super(ShellCacheSchemaTest, self).tearDown()
- os.path.exists.reset_mock()
def _mock_client_setup(self):
self.schema_dict = {
@@ -137,13 +135,10 @@ class ShellCacheSchemaTest(utils.TestCase):
return Args(args)
@mock.patch('six.moves.builtins.open', new=mock.mock_open(), create=True)
- def test_cache_schema_gets_when_not_exists(self):
- mocked_path_exists_result_lst = [True, False]
- os.path.exists.side_effect = \
- lambda *args: mocked_path_exists_result_lst.pop(0)
-
+ @mock.patch('os.path.exists', return_value=True)
+ def test_cache_schema_gets_when_forced(self, exists_mock):
options = {
- 'get_schema': False
+ 'get_schema': True
}
self.shell._cache_schema(self._make_args(options),
@@ -155,11 +150,10 @@ class ShellCacheSchemaTest(utils.TestCase):
open.mock_calls[2])
@mock.patch('six.moves.builtins.open', new=mock.mock_open(), create=True)
- def test_cache_schema_gets_when_forced(self):
- os.path.exists.return_value = True
-
+ @mock.patch('os.path.exists', side_effect=[True, False])
+ def test_cache_schema_gets_when_not_exists(self, exists_mock):
options = {
- 'get_schema': True
+ 'get_schema': False
}
self.shell._cache_schema(self._make_args(options),
@@ -171,9 +165,8 @@ class ShellCacheSchemaTest(utils.TestCase):
open.mock_calls[2])
@mock.patch('six.moves.builtins.open', new=mock.mock_open(), create=True)
- def test_cache_schema_leaves_when_present_not_forced(self):
- os.path.exists.return_value = True
-
+ @mock.patch('os.path.exists', return_value=True)
+ def test_cache_schema_leaves_when_present_not_forced(self, exists_mock):
options = {
'get_schema': False
}
@@ -183,5 +176,5 @@ class ShellCacheSchemaTest(utils.TestCase):
os.path.exists.assert_any_call(self.cache_dir)
os.path.exists.assert_any_call(self.cache_file)
- self.assertEqual(2, os.path.exists.call_count)
+ self.assertEqual(2, exists_mock.call_count)
self.assertEqual(0, open.mock_calls.__len__())