Mercurial > hg
diff tests/test-lock.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | b58d608ec6a0 |
children | 888bd39ed555 |
line wrap: on
line diff
--- a/tests/test-lock.py Sat Oct 05 10:29:34 2019 -0400 +++ b/tests/test-lock.py Sun Oct 06 09:45:02 2019 -0400 @@ -19,19 +19,24 @@ # work around http://bugs.python.org/issue1515 if types.MethodType not in copy._deepcopy_dispatch: + def _deepcopy_method(x, memo): return type(x)(x.__func__, copy.deepcopy(x.__self__, memo), x.im_class) + copy._deepcopy_dispatch[types.MethodType] = _deepcopy_method + class lockwrapper(lock.lock): def __init__(self, pidoffset, *args, **kwargs): # lock.lock.__init__() calls lock(), so the pidoffset assignment needs # to be earlier self._pidoffset = pidoffset super(lockwrapper, self).__init__(*args, **kwargs) + def _getpid(self): return super(lockwrapper, self)._getpid() + self._pidoffset + class teststate(object): def __init__(self, testcase, dir, pidoffset=0): self._testcase = testcase @@ -42,9 +47,15 @@ self._pidoffset = pidoffset def makelock(self, *args, **kwargs): - l = lockwrapper(self._pidoffset, self.vfs, testlockname, - releasefn=self.releasefn, acquirefn=self.acquirefn, - *args, **kwargs) + l = lockwrapper( + self._pidoffset, + self.vfs, + testlockname, + releasefn=self.releasefn, + acquirefn=self.acquirefn, + *args, + **kwargs + ) l.postrelease.append(self.postreleasefn) return l @@ -59,39 +70,42 @@ def assertacquirecalled(self, called): self._testcase.assertEqual( - self._acquirecalled, called, - 'expected acquire to be %s but was actually %s' % ( - self._tocalled(called), - self._tocalled(self._acquirecalled), - )) + self._acquirecalled, + called, + 'expected acquire to be %s but was actually %s' + % (self._tocalled(called), self._tocalled(self._acquirecalled),), + ) def resetacquirefn(self): self._acquirecalled = False def assertreleasecalled(self, called): self._testcase.assertEqual( - self._releasecalled, called, - 'expected release to be %s but was actually %s' % ( - self._tocalled(called), - self._tocalled(self._releasecalled), - )) + self._releasecalled, + called, + 'expected release to be %s but was actually %s' + % (self._tocalled(called), self._tocalled(self._releasecalled),), + ) def assertpostreleasecalled(self, called): self._testcase.assertEqual( - self._postreleasecalled, called, - 'expected postrelease to be %s but was actually %s' % ( + self._postreleasecalled, + called, + 'expected postrelease to be %s but was actually %s' + % ( self._tocalled(called), self._tocalled(self._postreleasecalled), - )) + ), + ) def assertlockexists(self, exists): actual = self.vfs.lexists(testlockname) self._testcase.assertEqual( - actual, exists, - 'expected lock to %s but actually did %s' % ( - self._toexists(exists), - self._toexists(actual), - )) + actual, + exists, + 'expected lock to %s but actually did %s' + % (self._toexists(exists), self._toexists(actual),), + ) def _tocalled(self, called): if called: @@ -105,6 +119,7 @@ else: return 'not exist' + class testlock(unittest.TestCase): def testlock(self): state = teststate(self, tempfile.mkdtemp(dir=encoding.getcwd())) @@ -125,12 +140,12 @@ # recursive lock should not call acquirefn again state.assertacquirecalled(False) - lock.release() # brings lock refcount down from 2 to 1 + lock.release() # brings lock refcount down from 2 to 1 state.assertreleasecalled(False) state.assertpostreleasecalled(False) state.assertlockexists(True) - lock.release() # releases the lock + lock.release() # releases the lock state.assertreleasecalled(True) state.assertpostreleasecalled(True) state.assertlockexists(False) @@ -256,8 +271,10 @@ def testinheritcheck(self): d = tempfile.mkdtemp(dir=encoding.getcwd()) state = teststate(self, d) + def check(): raise error.LockInheritanceContractViolation('check failed') + lock = state.makelock(inheritchecker=check) state.assertacquirecalled(True) @@ -279,6 +296,7 @@ def emulatefrequentlock(*args): raise OSError(errno.EEXIST, "File exists") + def emulatefrequentunlock(*args): raise OSError(errno.ENOENT, "No such file or directory") @@ -293,5 +311,6 @@ self.assertTrue(why.locker == b"") state.assertlockexists(False) + if __name__ == '__main__': silenttestrunner.main(__name__)