Merge pull request #93 from ThomasWaldmann/mockfix

Mockfix
This commit is contained in:
TW 2015-07-12 23:38:54 +02:00
commit dda78d1abd
3 changed files with 21 additions and 12 deletions

View File

@ -1,5 +1,14 @@
try:
# Only available in python 3.3+
from unittest.mock import *
except ImportError:
from mock import *
"""
Mocking
Note: unittest.mock is broken on at least python 3.3.6 and 3.4.0.
it silently ignores mistyped method names starting with assert_...,
does nothing and just succeeds.
The issue was fixed in the separately distributed "mock" lib, you
get an AttributeError there. So, always use that one!
Details:
http://engineeringblog.yelp.com/2015/02/assert_called_once-threat-or-menace.html
"""
from mock import *

View File

@ -159,7 +159,7 @@ class RepositoryCommitTestCase(RepositoryTestCaseBase):
with patch.object(UpgradableLock, 'upgrade', side_effect=UpgradableLock.WriteLockFailed) as upgrade:
self.reopen()
self.assert_raises(UpgradableLock.WriteLockFailed, lambda: len(self.repository))
upgrade.assert_called_once()
upgrade.assert_called_once_with()
def test_crash_before_write_index(self):
self.add_keys()
@ -309,7 +309,7 @@ class RepositoryCheckTestCase(RepositoryTestCaseBase):
# Simulate a crash before compact
with patch.object(Repository, 'compact_segments') as compact:
self.repository.commit()
compact.assert_called_once()
compact.assert_called_once_with()
self.reopen()
self.check(repair=True)
self.assert_equal(self.repository.get(bytes(32)), b'data2')
@ -328,3 +328,7 @@ class RemoteRepositoryCheckTestCase(RepositoryCheckTestCase):
def open(self, create=False):
return RemoteRepository(Location('__testsuite__:' + os.path.join(self.tmppath, 'repository')), create=create)
def test_crash_before_compact(self):
# skip this test, we can't mock-patch a Repository class in another process!
pass

View File

@ -6,10 +6,6 @@ envlist = py32, py33, py34
changedir = {envdir}
deps =
pytest
mock
commands = py.test
passenv = * # fakeroot -u needs some env vars
[testenv:py32]
deps =
pytest
mock