mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-09 00:32:37 -04:00
remove usage of evil / broken unittest.mock, use mock from pypi
see testsuite.mock docstring for more details. one test shows brokenness right now that was hidden / silent until now.
This commit is contained in:
parent
f6ba79d801
commit
414dba3de7
3 changed files with 17 additions and 12 deletions
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
6
tox.ini
6
tox.ini
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue