summaryrefslogtreecommitdiff
path: root/test/test_tabs.py
blob: 6db4c2ccc762aa90711a0b7d4dfd882471fa6ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
Tests for the Tabs list module
"""

from poezio.core.tabs import Tabs
from poezio.tabs import GapTab

class DummyTab:
    count = 0

    def __init__(self):
        self.name = 'dummy%s' % self.count
        DummyTab.count += 1

    @staticmethod
    def reset():
        DummyTab.count = 0

def test_append():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    tabs.append(dummy)
    assert tabs[0] is dummy
    assert tabs[0].nb == 0
    assert tabs['dummy0'] is dummy
    assert tabs.by_class(DummyTab) == [dummy]

    dummy2 = DummyTab()
    tabs.append(dummy2)
    assert tabs[1] is dummy2
    assert tabs[1].nb == 1
    assert tabs['dummy1'] is dummy2
    assert tabs.by_class(DummyTab) == [dummy, dummy2]

def test_delete():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)

    tabs.delete(dummy)
    assert tabs[0] is dummy2
    assert tabs.by_class(DummyTab) == [dummy2]
    assert tabs['dummy0'] is None
    assert dummy2.nb == 0


def test_delete_restore_previous():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    dummy4 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)
    tabs.append(dummy4)

    tabs.set_current_tab(dummy4)
    tabs.set_current_tab(dummy2)
    tabs.delete(dummy2)
    assert tabs.current_tab is dummy4
    assert tabs.current_index == 2
    assert dummy.nb == 0
    assert dummy3.nb == 1
    assert dummy4.nb == 2

def test_delete_other_tab():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    dummy4 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)
    tabs.append(dummy4)

    tabs.set_current_tab(dummy4)
    tabs.delete(dummy2)
    assert tabs.current_tab is dummy4
    assert tabs.current_index == 2
    assert dummy.nb == 0
    assert dummy3.nb == 1
    assert dummy4.nb == 2

def test_insert_and_gaps():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)

    tabs.insert_tab(2, 1)
    assert tabs[1] is dummy3
    assert tabs[2] is dummy2

    tabs.insert_tab(1, 100, gaps=True)
    assert isinstance(tabs[1], GapTab)
    assert tabs[3] is dummy3
    assert tabs[3].nb == 3

    tabs.update_gaps(enable_gaps=False)
    assert tabs[1] is dummy2
    assert tabs[1].nb == 1

def test_replace_tabs():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)

    tabs.replace_tabs([dummy3, dummy2, dummy])
    assert tabs[0] is dummy3
    assert tabs[2] is dummy
    assert tabs[2].nb == 2

def test_prev_next():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)

    for idx in range(6):
        assert tabs.current_index == idx % 3
        tabs.next()

    for idx in range(6):
        assert (3 - idx) % 3 == tabs.current_index
        tabs.prev()

    tabs.insert_tab(1, 999, gaps=True)

    assert tabs.current_index == 0
    tabs.next()
    assert tabs.current_index == 2
    tabs.prev()
    assert tabs.current_index == 0

def test_set_current():
    DummyTab.reset()
    tabs = Tabs()
    dummy = DummyTab()
    dummy2 = DummyTab()
    dummy3 = DummyTab()
    tabs.append(dummy)
    tabs.append(dummy2)
    tabs.append(dummy3)

    assert tabs.current_tab is dummy
    tabs.set_current_index(2)
    assert tabs.current_tab is dummy3
    tabs.set_current_tab(dummy2)
    assert tabs.current_tab is dummy2