@@ -97,13 +97,12 @@ def test1(self):
9797 self .repository .delete (key50 )
9898 self .assert_raises (Repository .ObjectNotFound , lambda : self .repository .get (key50 ))
9999 self .repository .commit (compact = False )
100- self .repository .close ()
101- with self .open () as repository2 :
102- self .assert_raises (Repository .ObjectNotFound , lambda : repository2 .get (key50 ))
103- for x in range (100 ):
104- if x == 50 :
105- continue
106- self .assert_equal (pdchunk (repository2 .get (H (x ))), b"SOMEDATA" )
100+ self .reopen ()
101+ self .assert_raises (Repository .ObjectNotFound , lambda : self .repository .get (key50 ))
102+ for x in range (100 ):
103+ if x == 50 :
104+ continue
105+ self .assert_equal (pdchunk (self .repository .get (H (x ))), b"SOMEDATA" )
107106
108107 def test2 (self ):
109108 """Test multiple sequential transactions"""
@@ -158,17 +157,14 @@ def test_single_kind_transactions(self):
158157 # put
159158 self .repository .put (H (0 ), fchunk (b"foo" ))
160159 self .repository .commit (compact = False )
161- self .repository . close ()
160+ self .reopen ()
162161 # replace
163- self .repository = self .open ()
164- with self .repository :
165- self .repository .put (H (0 ), fchunk (b"bar" ))
166- self .repository .commit (compact = False )
162+ self .repository .put (H (0 ), fchunk (b"bar" ))
163+ self .repository .commit (compact = False )
164+ self .reopen ()
167165 # delete
168- self .repository = self .open ()
169- with self .repository :
170- self .repository .delete (H (0 ))
171- self .repository .commit (compact = False )
166+ self .repository .delete (H (0 ))
167+ self .repository .commit (compact = False )
172168
173169 def test_list (self ):
174170 for x in range (100 ):
@@ -275,14 +271,11 @@ def test_flags_persistence(self):
275271 # we do not set flags for H(0), so we can later check their default state.
276272 self .repository .flags (H (1 ), mask = 0x00000007 , value = 0x00000006 )
277273 self .repository .commit (compact = False )
278- self .repository .close ()
279-
280- self .repository = self .open ()
281- with self .repository :
282- # we query all flags to check if the initial flags were all zero and
283- # only the ones we explicitly set to one are as expected.
284- self .assert_equal (self .repository .flags (H (0 ), mask = 0xFFFFFFFF ), 0x00000000 )
285- self .assert_equal (self .repository .flags (H (1 ), mask = 0xFFFFFFFF ), 0x00000006 )
274+ self .reopen ()
275+ # we query all flags to check if the initial flags were all zero and
276+ # only the ones we explicitly set to one are as expected.
277+ self .assert_equal (self .repository .flags (H (0 ), mask = 0xFFFFFFFF ), 0x00000000 )
278+ self .assert_equal (self .repository .flags (H (1 ), mask = 0xFFFFFFFF ), 0x00000006 )
286279
287280
288281class LocalRepositoryTestCase (RepositoryTestCaseBase ):
@@ -336,12 +329,10 @@ def test_uncommitted_garbage(self):
336329 last_segment = self .repository .io .get_latest_segment ()
337330 with open (self .repository .io .segment_filename (last_segment + 1 ), "wb" ) as f :
338331 f .write (MAGIC + b"crapcrapcrap" )
339- self .repository . close ()
332+ self .reopen ()
340333 # usually, opening the repo and starting a transaction should trigger a cleanup.
341- self .repository = self .open ()
342- with self .repository :
343- self .repository .put (H (0 ), fchunk (b"bar" )) # this may trigger compact_segments()
344- self .repository .commit (compact = True )
334+ self .repository .put (H (0 ), fchunk (b"bar" )) # this may trigger compact_segments()
335+ self .repository .commit (compact = True )
345336 # the point here is that nothing blows up with an exception.
346337
347338
@@ -384,11 +375,10 @@ def test_replay_lock_upgrade_old(self):
384375 os .unlink (os .path .join (self .repository .path , name ))
385376 with patch .object (Lock , "upgrade" , side_effect = LockFailed ) as upgrade :
386377 self .reopen (exclusive = None ) # simulate old client that always does lock upgrades
387- with self .repository :
388- # the repo is only locked by a shared read lock, but to replay segments,
389- # we need an exclusive write lock - check if the lock gets upgraded.
390- self .assert_raises (LockFailed , lambda : len (self .repository ))
391- upgrade .assert_called_once_with ()
378+ # the repo is only locked by a shared read lock, but to replay segments,
379+ # we need an exclusive write lock - check if the lock gets upgraded.
380+ self .assert_raises (LockFailed , lambda : len (self .repository ))
381+ upgrade .assert_called_once_with ()
392382
393383 def test_replay_lock_upgrade (self ):
394384 self .add_keys ()
@@ -397,11 +387,10 @@ def test_replay_lock_upgrade(self):
397387 os .unlink (os .path .join (self .repository .path , name ))
398388 with patch .object (Lock , "upgrade" , side_effect = LockFailed ) as upgrade :
399389 self .reopen (exclusive = False ) # current client usually does not do lock upgrade, except for replay
400- with self .repository :
401- # the repo is only locked by a shared read lock, but to replay segments,
402- # we need an exclusive write lock - check if the lock gets upgraded.
403- self .assert_raises (LockFailed , lambda : len (self .repository ))
404- upgrade .assert_called_once_with ()
390+ # the repo is only locked by a shared read lock, but to replay segments,
391+ # we need an exclusive write lock - check if the lock gets upgraded.
392+ self .assert_raises (LockFailed , lambda : len (self .repository ))
393+ upgrade .assert_called_once_with ()
405394
406395 def test_crash_before_deleting_compacted_segments (self ):
407396 self .add_keys ()
@@ -931,7 +920,7 @@ def test_hints_behaviour(self):
931920class RemoteRepositoryTestCase (RepositoryTestCase ):
932921 repository = None # type: RemoteRepository
933922
934- def open (self , create = False ):
923+ def open (self , create = False , exclusive = UNSPECIFIED ):
935924 return RemoteRepository (
936925 Location ("ssh://__testsuite__" + os .path .join (self .tmppath , "repository" )), exclusive = True , create = create
937926 )
0 commit comments