This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 11:00 UTC+2 (a few minutes of down time)

repofilterbar_branch_test.py 5.21 KB
Newer Older
Yuya Nishihara's avatar
Yuya Nishihara committed
1 2 3 4 5 6
from __future__ import absolute_import

import mock
import os
import unittest

7 8 9 10
from mercurial import (
    pycompat,
)

Yuya Nishihara's avatar
Yuya Nishihara committed
11 12 13 14 15
from tortoisehg.hgqt import (
    qtlib,
    repofilter,
    thgrepo,
)
16 17 18

import helpers

19
def setup_module():
20 21 22 23
    global _tmpdir
    _tmpdir = helpers.mktmpdir(__name__)

def _listitems(combo):
24 25
    return [pycompat.unicode(combo.itemText(i))
                             for i in pycompat.xrange(combo.count())]
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

class RepoFilterBarBranchTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        hg = helpers.HgClient(os.path.join(_tmpdir, cls.__name__))
        hg.init()
        hg.ftouch('a')
        hg.addremove()
        hg.commit('-m', 'commit to default')
        for name in ('foo', 'bar', 'baz'):
            hg.update('0')
            hg.fappend('a', name + '\n')
            hg.branch(name)
            hg.commit('-m', 'create %s branch' % name)
        hg.commit('--close-branch', '-m', 'close baz branch')
41
        hg.update('foo')  # current branch will be listed first
42 43 44 45 46 47 48 49
        cls.repo = thgrepo.repository(path=hg.path)

    @classmethod
    def tearDownClass(cls):
        del cls.repo

    def setUp(self):
        qtlib.initfontcache(self.repo.ui)
50 51
        repoagent = self.repo._pyqtobj  # TODO
        self.widget = repofilter.RepoFilterBar(repoagent)
52 53 54 55 56 57 58 59 60 61 62 63
        self.branchchanged = mock.Mock()
        self.widget.branchChanged.connect(self.branchchanged)
        # without show(), action.setChecked() sometimes fails with
        # "illegal hardware instruction"
        self.widget.show()

    def tearDown(self):
        del self.widget
        qtlib._fontcache.clear()

    def test_open_branches(self):
        self.assertEqual([self.widget._allBranchesLabel,
64
                          'foo', 'default', 'bar'],
65 66 67 68 69 70 71 72
                         _listitems(self.widget._branchCombo))
        self.assertTrue(self.widget._branchCombo.isEnabled())
        self.assertFalse(self.branchchanged.called)

    def test_only_active_branches(self):
        self.widget._abranchAction.setChecked(False)
        self.widget._abranchAction.trigger()  # checked
        self.assertEqual([self.widget._allBranchesLabel,
73
                          'foo', 'bar'],
74 75 76 77 78 79 80 81
                         _listitems(self.widget._branchCombo))
        self.assertTrue(self.widget._branchCombo.isEnabled())
        self.assertFalse(self.branchchanged.called)

    def test_include_closed_branches(self):
        self.widget._cbranchAction.setChecked(False)
        self.widget._cbranchAction.trigger()  # checked
        self.assertEqual([self.widget._allBranchesLabel,
82
                         'foo',  'default', 'bar', 'baz'],
83 84 85 86 87 88 89 90 91
                         _listitems(self.widget._branchCombo))
        self.assertTrue(self.widget._branchCombo.isEnabled())
        self.assertFalse(self.branchchanged.called)

    def test_change_branch(self):
        self.widget.setBranch('foo')
        self.assertEqual('foo', self.widget.branch())
        self.branchchanged.assert_called_once_with('foo', False)

92 93 94 95
    def test_label_for_all_branches(self):
        self.widget.setBranch('')  # all branches
        self.assertEqual('', self.widget.branch())
        self.assertEqual(self.widget._allBranchesLabel,
96 97
                         pycompat.unicode(
                             self.widget._branchCombo.currentText()))
98

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    def test_selected_inactive_branch_removed_from_list(self):
        self.widget.setBranch('default')
        self.branchchanged.reset_mock()
        self.widget._abranchAction.setChecked(False)
        self.widget._abranchAction.trigger()  # checked
        self.assertEqual('', self.widget.branch())  # fall back
        self.branchchanged.assert_called_once_with('', False)

    def test_selected_closed_branch_removed_from_list(self):
        self.widget._cbranchAction.setChecked(False)
        self.widget._cbranchAction.trigger()  # checked
        self.widget.setBranch('baz')
        self.branchchanged.reset_mock()
        self.widget._cbranchAction.trigger()  # unchecked
        self.assertEqual('', self.widget.branch())  # fall back
        self.branchchanged.assert_called_once_with('', False)

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
class RepoFilterBarEmptyBranchTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        hg = helpers.HgClient(os.path.join(_tmpdir, cls.__name__))
        hg.init()
        hg.ftouch('a')
        hg.addremove()
        hg.commit('-m', 'commit to default')
        hg.commit('--close-branch', '-m', 'close default branch')
        cls.repo = thgrepo.repository(path=hg.path)

    @classmethod
    def tearDownClass(cls):
        del cls.repo

    def setUp(self):
        qtlib.initfontcache(self.repo.ui)
133 134
        repoagent = self.repo._pyqtobj  # TODO
        self.widget = repofilter.RepoFilterBar(repoagent)
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        # without show(), action.setChecked() sometimes fails with
        # "illegal hardware instruction"
        self.widget.show()

    def tearDown(self):
        del self.widget
        qtlib._fontcache.clear()

    def test_empty_branch_combo_is_disabled(self):
        self.assertFalse(self.widget._branchCombo.isEnabled())

    def test_branch_combo_enabled_if_closed_branches_included(self):
        self.widget._cbranchAction.setChecked(False)
        self.widget._cbranchAction.trigger()  # checked
        self.assertTrue(self.widget._branchCombo.isEnabled())