summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Gedminas <marius@gedmin.as>2015-09-03 09:43:10 +0300
committerMarius Gedminas <marius@gedmin.as>2015-09-03 09:44:44 +0300
commita32bf1ec1818825744ca3d4cbd61b72493cfb4fc (patch)
tree433f48a5ee345ced48e1e1c2d1ebf488125ba206
parentce978745238bcab915ff409113861bad7bc7dfd3 (diff)
downloadansible-a32bf1ec1818825744ca3d4cbd61b72493cfb4fc.tar.gz
Simplify FactCache.copy()
Also fix the bug (missing from six import iteritems) I introduced in 823677b490d3ddc3bcfe8fa2f215d9d9c2167b14.
-rw-r--r--lib/ansible/plugins/cache/__init__.py2
-rw-r--r--test/units/plugins/cache/test_cache.py17
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/ansible/plugins/cache/__init__.py b/lib/ansible/plugins/cache/__init__.py
index f0fbcd0a3e..0938e0983e 100644
--- a/lib/ansible/plugins/cache/__init__.py
+++ b/lib/ansible/plugins/cache/__init__.py
@@ -60,7 +60,7 @@ class FactCache(MutableMapping):
def copy(self):
""" Return a primitive copy of the keys and values from the cache. """
- return dict([(k, v) for (k, v) in iteritems(self)])
+ return dict(self)
def keys(self):
return self._plugin.keys()
diff --git a/test/units/plugins/cache/test_cache.py b/test/units/plugins/cache/test_cache.py
index f3cfe6a38c..af1d924910 100644
--- a/test/units/plugins/cache/test_cache.py
+++ b/test/units/plugins/cache/test_cache.py
@@ -19,7 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-from ansible.compat.tests import unittest
+from ansible.compat.tests import unittest, mock
+from ansible.plugins.cache import FactCache
from ansible.plugins.cache.base import BaseCacheModule
from ansible.plugins.cache.memory import CacheModule as MemoryCache
@@ -42,6 +43,20 @@ else:
from ansible.plugins.cache.redis import CacheModule as RedisCache
+class TestFactCache(unittest.TestCase):
+
+ def setUp(self):
+ with mock.patch('ansible.constants.CACHE_PLUGIN', 'memory'):
+ self.cache = FactCache()
+
+ def test_copy(self):
+ self.cache['avocado'] = 'fruit'
+ self.cache['daisy'] = 'flower'
+ a_copy = self.cache.copy()
+ self.assertEqual(type(a_copy), dict)
+ self.assertEqual(a_copy, dict(avocado='fruit', daisy='flower'))
+
+
class TestAbstractClass(unittest.TestCase):
def setUp(self):