566
566
self.assertEqual(['lw', 'ul'], branch._calls)
569
class TestBranchTransaction(TestCaseWithBranch):
572
super(TestBranchTransaction, self).setUp()
575
def test_default_get_transaction(self):
576
"""branch.get_transaction on a new branch should give a PassThrough."""
577
self.failUnless(isinstance(self.get_branch().get_transaction(),
578
transactions.PassThroughTransaction))
580
def test__set_new_transaction(self):
581
self.get_branch()._set_transaction(transactions.ReadOnlyTransaction())
583
def test__set_over_existing_transaction_raises(self):
584
self.get_branch()._set_transaction(transactions.ReadOnlyTransaction())
585
self.assertRaises(errors.LockError,
586
self.get_branch()._set_transaction,
587
transactions.ReadOnlyTransaction())
589
def test_finish_no_transaction_raises(self):
590
self.assertRaises(errors.LockError, self.get_branch()._finish_transaction)
592
def test_finish_readonly_transaction_works(self):
593
self.get_branch()._set_transaction(transactions.ReadOnlyTransaction())
594
self.get_branch()._finish_transaction()
595
self.assertEqual(None, self.get_branch().control_files._transaction)
597
def test_unlock_calls_finish(self):
598
self.get_branch().lock_read()
599
transaction = InstrumentedTransaction()
600
self.get_branch().control_files._transaction = transaction
601
self.get_branch().unlock()
602
self.assertEqual(['finish'], transaction.calls)
604
def test_lock_read_acquires_ro_transaction(self):
605
self.get_branch().lock_read()
606
self.failUnless(isinstance(self.get_branch().get_transaction(),
607
transactions.ReadOnlyTransaction))
608
self.get_branch().unlock()
610
def test_lock_write_acquires_write_transaction(self):
611
self.get_branch().lock_write()
612
# cannot use get_transaction as its magic
613
self.failUnless(isinstance(self.get_branch().control_files._transaction,
614
transactions.WriteTransaction))
615
self.get_branch().unlock()
618
569
class TestRevisionHistoryCaching(TestCaseWithBranch):
619
570
"""Tests for the caching of branch revision_history.