Merge pull request #41859 from DSRCorporation/bugs/py3_tests_2017.7

Py3 etcd unit test fix.
This commit is contained in:
Mike Place 2017-06-21 10:33:15 -05:00 committed by GitHub
commit ccd81ed047
2 changed files with 14 additions and 6 deletions

View File

@ -164,6 +164,9 @@ class EtcdClient(object):
except ValueError:
return {}
if result is None:
return {}
if recurse:
ret['key'] = getattr(result, 'key', None)
ret['value'] = getattr(result, 'value', None)

View File

@ -88,10 +88,11 @@ class EtcdUtilTestCase(TestCase):
self.assertEqual(client.get('salt', recurse=True), 'stack')
mock.assert_called_with('salt', recursive=True)
mock.side_effect = etcd.EtcdKeyNotFound()
# iter(list(Exception)) works correctly with both mock<1.1 and mock>=1.1
mock.side_effect = iter([etcd.EtcdKeyNotFound()])
self.assertEqual(client.get('not-found'), None)
mock.side_effect = etcd.EtcdConnectionFailed()
mock.side_effect = iter([etcd.EtcdConnectionFailed()])
self.assertEqual(client.get('watching'), None)
# python 2.6 test
@ -126,7 +127,8 @@ class EtcdUtilTestCase(TestCase):
mock.assert_any_call('/x')
mock.assert_any_call('/x/c')
mock.side_effect = etcd.EtcdKeyNotFound()
# iter(list(Exception)) works correctly with both mock<1.1 and mock>=1.1
mock.side_effect = iter([etcd.EtcdKeyNotFound()])
self.assertEqual(client.tree('not-found'), None)
mock.side_effect = ValueError
@ -149,7 +151,8 @@ class EtcdUtilTestCase(TestCase):
self.assertEqual(client.ls('/x'), {'/x': {'/x/a': '1', '/x/b': '2', '/x/c/': {}}})
mock.assert_called_with('/x')
mock.side_effect = etcd.EtcdKeyNotFound()
# iter(list(Exception)) works correctly with both mock<1.1 and mock>=1.1
mock.side_effect = iter([etcd.EtcdKeyNotFound()])
self.assertEqual(client.ls('/not-found'), {})
mock.side_effect = Exception
@ -327,11 +330,13 @@ class EtcdUtilTestCase(TestCase):
{'value': 'stack', 'key': '/some-key', 'mIndex': 1, 'changed': True, 'dir': True})
mock.assert_called_with('/some-dir', wait=True, recursive=True, timeout=5, waitIndex=10)
mock.side_effect = MaxRetryError(None, None)
# iter(list(Exception)) works correctly with both mock<1.1 and mock>=1.1
mock.side_effect = iter([MaxRetryError(None, None)])
self.assertEqual(client.watch('/some-key'), {})
mock.side_effect = etcd.EtcdConnectionFailed()
mock.side_effect = iter([etcd.EtcdConnectionFailed()])
self.assertEqual(client.watch('/some-key'), {})
mock.side_effect = None
mock.return_value = None
self.assertEqual(client.watch('/some-key'), {})