<div dir="ltr"><div><div><div><div>Hi Jay,<br><br>(I havent checked your link yet)<br>But just to get some more clarification.. I haven't understood yet, why you think its not called w/ the expected args ?<br></div>I expect it to get called with the expected args bcos ...<br>
<br>_load_shares_config is mocked to <tt>_fake_load_shares_config<br></tt></div><tt>which sets self._driver.shares dict as my 'expected' share key:value pair<br><br></tt></div><tt>Hence i expect my ensure_share_unmounted to get called with the above share key:value pair that i set using<br>
</tt><tt>_fake_load_shares_config.. and thats not happening. <br><br></tt></div><tt>Your reponse doesn't address this, does it ?<br><br>thanx,<br>deepak<br></tt></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Apr 28, 2014 at 11:38 PM, Jay Pipes <span dir="ltr"><<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 04/28/2014 02:00 PM, Deepak Shetty wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was writing this in test_glusterfs.py<br>
<br>
     def test_ensure_shares_unmounted_<u></u>1share(self):<br>
         with contextlib.nested(<br>
             mock.patch.object(self._<u></u>driver, '_load_shares_config'),<br>
             mock.patch.object(self._<u></u>driver, '_ensure_share_unmounted')<br>
         ) as (self._fake_load_shares_<u></u>config, mock_ensure_share_unmounted):<br>
<br>
             #mock_shares = {'127.7.7.7:/gluster1': None}<br>
             #mock_load_shares_config.<u></u>return_value = mock_shares<br>
             #self._driver.shares = mock_load_shares_config.<u></u>return_value<br>
<br>
             self._driver._ensure_shares_<u></u>unmounted()<br>
<br>
             mock_ensure_share_unmounted.<u></u>assert_called_once()<br>
             mock_ensure_share_unmounted.<u></u>assert_called_once_with(<br>
                 '127.7.7.7:/gluster1')<br>
<br>
for my patch @ <a href="https://review.openstack.org/#/c/86888/6" target="_blank">https://review.openstack.org/#<u></u>/c/86888/6</a><br>
<br>
and i get the output as ..<br>
<br>
==============================<u></u>==============================<u></u>==========<br>
FAIL:<br>
cinder.tests.test_glusterfs.<u></u>GlusterFsDriverTestCase.test_<u></u>ensure_shares_unmounted_1share<br>
------------------------------<u></u>------------------------------<u></u>----------<br>
...<br>
...<br>
<br>
stderr: {{{<br>
cinder/tests/test_glusterfs.<u></u>py:736: DeprecationWarning: With-statements<br>
now directly support multiple context managers<br>
   mock.patch.object(self._<u></u>driver, '_ensure_share_unmounted')<br>
}}}<br>
<br>
Traceback (most recent call last):<br>
   File "cinder/tests/test_glusterfs.<u></u>py", line 747, in<br>
test_ensure_shares_unmounted_<u></u>1share<br>
     '127.7.7.7:/gluster1')<br>
   File "/usr/lib/python2.7/site-<u></u>packages/mock.py", line 845, in<br>
assert_called_once_with<br>
     raise AssertionError(msg)<br>
AssertionError: Expected to be called once. Called 0 times.<br>
<br>
<br>
Can you help with why<br>
'mock_ensure_share_unmounted.<u></u>assert_called_once()' check passes<br>
but<br>
'mock_ensure_share_unmounted.<u></u>assert_called_once_with('127.<u></u>7.7.7:/gluster1')<br>
check fails ?<br>
</blockquote>
<br></div></div>
Sure. This is because assert_called_once() is not a method of mock.Mock() and therefore is "magic-mocked" to return a mock.MagicMock() itself.<br>
<br>
assert_called_once_with(), however, *is* an actual method of the mock.Mock() object and therefore is failing because the mock_unsure_share_unmounted mock was not called once with the expected arguments.<br>
<br>
The way to avoid the above problem is to use something called autospec'ing.<br>
<br>
You can read more about this intricacy of mock here:<br>
<br>
<a href="http://www.voidspace.org.uk/python/mock/helpers.html#autospeccing" target="_blank">http://www.voidspace.org.uk/<u></u>python/mock/helpers.html#<u></u>autospeccing</a><br>
<br>
Best,<br>
-jay<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
In glusterfs.py ...<br>
<br>
     def _ensure_shares_unmounted(self)<u></u>:<br>
self._load_shares_config(self.<u></u>configuration.glusterfs_<u></u>shares_config)<br>
         for share in self.shares.keys():<br>
             try:<br>
                 self._ensure_share_unmounted(<u></u>share)<br>
             except Exception as exc:<br>
                 LOG.warning(_('Exception during unmounting %s') % (exc,))<br>
<br>
<br>
thanx,<br>
deepak<br>
<br>
<br>
<br></div>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</blockquote></div><br></div>