Merge branch 'tabs-slice' into 'master'

Allow Tabs object to be sliced

See merge request poezio/poezio!11
This commit is contained in:
mathieui 2018-09-10 23:50:38 +02:00
commit 12700fdaee
2 changed files with 15 additions and 4 deletions

View file

@ -67,10 +67,10 @@ class Tabs:
def __iter__(self): def __iter__(self):
return iter(self._tabs) return iter(self._tabs)
def __getitem__(self, index: Union[int, str]): def __getitem__(self, index: Union[int, str, slice]):
if isinstance(index, int): if isinstance(index, str):
return self._tabs[index] return self.by_name(index)
return self.by_name(index) return self._tabs[index]
def first(self) -> tabs.Tab: def first(self) -> tabs.Tab:
"""Return the Roster tab""" """Return the Roster tab"""

View file

@ -172,3 +172,14 @@ def test_set_current():
tabs.set_current_tab(dummy2) tabs.set_current_tab(dummy2)
assert tabs.current_tab is dummy2 assert tabs.current_tab is dummy2
def test_slice():
DummyTab.reset()
tabs = Tabs(h)
dummy = DummyTab()
dummy2 = DummyTab()
dummy3 = DummyTab()
tabs.append(dummy)
tabs.append(dummy2)
tabs.append(dummy3)
assert tabs[1:2][0] is dummy2