~roguescholar/brz-loom/debian

« back to all changes in this revision

Viewing changes to tests/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2019-08-22 19:36:40 UTC
  • Revision ID: jelmer@jelmer.uk-20190822193640-y82m61kqdm5fx13r
Add python3 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        return "Nothing to see."
61
61
 
62
62
 
 
63
class FakeLock(object):
 
64
 
 
65
    def __init__(self, unlock):
 
66
        self.unlock = unlock
 
67
 
 
68
    def __enter__(self):
 
69
        return self
 
70
 
 
71
    def __exit__(self, exc_type, exc_val, exc_tb):
 
72
        self.unlock()
 
73
        return False
 
74
 
 
75
 
63
76
class LockableStub(object):
64
77
 
65
78
    def __init__(self):
68
81
 
69
82
    def lock_write(self):
70
83
        self._calls.append(("write",))
 
84
        return FakeLock(self.unlock)
71
85
 
72
86
    def unlock(self):
73
87
        self._calls.append(("unlock",))
421
435
        # check loom threads
422
436
        threads = target.get_loom_state().get_threads()
423
437
        self.assertEqual(
424
 
            [('a thread', 'empty:', ['empty:'])],
 
438
            [('a thread', b'empty:', [b'empty:'])],
425
439
            threads)
426
440
        # check loom tip was pulled
427
441
        loom_rev_ids = source.branch.loom_parents()
525
539
        tree.branch.revert_loom()
526
540
        # the threads list should be restored
527
541
        self.assertEqual(
528
 
            [(u'foo', 'empty:', [EMPTY_REVISION]),
 
542
            [(u'foo', b'empty:', [EMPTY_REVISION]),
529
543
             (u'bar', last_rev, [last_rev])],
530
544
            tree.branch.get_loom_state().get_threads())
531
545
        self.assertEqual(last_rev, tree.branch.last_revision())
552
566
        tree.branch.revert_loom()
553
567
        # the threads list should be restored
554
568
        self.assertEqual(
555
 
            [('base', 'empty:', [EMPTY_REVISION]),
 
569
            [('base', b'empty:', [EMPTY_REVISION]),
556
570
             ('top', last_rev, [last_rev])],
557
571
            tree.branch.get_loom_state().get_threads())
558
572
        self.assertEqual(last_rev, tree.branch.last_revision())
597
611
        tree.branch._set_nick('bar')
598
612
        tree.branch.remove_thread('foo')
599
613
        state = tree.branch.get_loom_state()
600
 
        self.assertEqual([('bar', 'empty:', [])], state.get_threads())
 
614
        self.assertEqual([('bar', b'empty:', [])], state.get_threads())
601
615
 
602
616
    def test_get_threads_null(self):
603
617
        tree = self.get_tree_with_loom()
613
627
        tree = self.get_tree_with_loom()
614
628
        tree.branch.new_thread('thread1')
615
629
        tree.branch._set_nick('thread1')
616
 
        tree.commit('thread1', rev_id='thread1-id')
 
630
        tree.commit('thread1', rev_id=b'thread1-id')
617
631
        tree.branch.new_thread('thread2', 'thread1')
618
632
        tree.branch._set_nick('thread2')
619
 
        tree.commit('thread2', rev_id='thread2-id')
 
633
        tree.commit('thread2', rev_id=b'thread2-id')
620
634
        return tree
621
635
 
622
636
    def test_export_loom_initial(self):
624
638
        root_transport = tree.branch.controldir.root_transport
625
639
        tree.branch.export_threads(root_transport)
626
640
        thread1 = Branch.open_from_transport(root_transport.clone('thread1'))
627
 
        self.assertEqual('thread1-id', thread1.last_revision())
 
641
        self.assertEqual(b'thread1-id', thread1.last_revision())
628
642
        thread2 = Branch.open_from_transport(root_transport.clone('thread2'))
629
 
        self.assertEqual('thread2-id', thread2.last_revision())
 
643
        self.assertEqual(b'thread2-id', thread2.last_revision())
630
644
 
631
645
    def test_export_loom_update(self):
632
646
        tree = self.get_multi_threaded()
633
647
        root_transport = tree.branch.controldir.root_transport
634
648
        tree.branch.export_threads(root_transport)
635
 
        tree.commit('thread2-2', rev_id='thread2-2-id')
 
649
        tree.commit('thread2-2', rev_id=b'thread2-2-id')
636
650
        tree.branch.export_threads(root_transport)
637
651
        thread1 = Branch.open_from_transport(root_transport.clone('thread1'))
638
 
        self.assertEqual('thread1-id', thread1.last_revision())
 
652
        self.assertEqual(b'thread1-id', thread1.last_revision())
639
653
        thread2 = Branch.open_from_transport(root_transport.clone('thread2'))
640
 
        self.assertEqual('thread2-2-id', thread2.last_revision())
 
654
        self.assertEqual(b'thread2-2-id', thread2.last_revision())
641
655
 
642
656
    def test_export_loom_root_transport(self):
643
657
        tree = self.get_multi_threaded()
646
660
        tree.branch.export_threads(root_transport)
647
661
        thread1 = Branch.open_from_transport(root_transport.clone('thread1'))
648
662
        thread1 = Branch.open_from_transport(root_transport.clone('thread1'))
649
 
        self.assertEqual('thread1-id', thread1.last_revision())
 
663
        self.assertEqual(b'thread1-id', thread1.last_revision())
650
664
        thread2 = Branch.open_from_transport(root_transport.clone('thread2'))
651
 
        self.assertEqual('thread2-id', thread2.last_revision())
 
665
        self.assertEqual(b'thread2-id', thread2.last_revision())
652
666
 
653
667
    def test_export_loom_as_tree(self):
654
668
        tree = self.get_multi_threaded()
656
670
        root_transport = tree.branch.controldir.root_transport.clone('root')
657
671
        tree.branch.export_threads(root_transport)
658
672
        export_tree = WorkingTree.open(root_transport.local_abspath('thread1'))
659
 
        self.assertEqual('thread1-id', export_tree.last_revision())
 
673
        self.assertEqual(b'thread1-id', export_tree.last_revision())
660
674
 
661
675
    def test_export_loom_as_branch(self):
662
676
        tree = self.get_multi_threaded()
670
684
                          root_transport.local_abspath('thread1'))
671
685
        export_branch = Branch.open_from_transport(
672
686
            root_transport.clone('thread1'))
673
 
        self.assertEqual('thread1-id', export_branch.last_revision())
 
687
        self.assertEqual(b'thread1-id', export_branch.last_revision())
674
688
 
675
689
    def test_set_nick_renames_thread(self):
676
690
        tree = self.get_tree_with_loom()