summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2018-09-10 23:50:38 +0200
committermathieui <mathieui@mathieui.net>2018-09-10 23:50:38 +0200
commit12700fdaee46a979478d061d5039190afd3d0963 (patch)
treecbf5b05e0b4b026ff56b5c78092dc396f960d5f8
parent2a755897476a382dedee9f34debc6f64005f46cb (diff)
parent65649e91c4f2130143645a6901bfb029e44e2993 (diff)
downloadpoezio-12700fdaee46a979478d061d5039190afd3d0963.tar.gz
poezio-12700fdaee46a979478d061d5039190afd3d0963.tar.bz2
poezio-12700fdaee46a979478d061d5039190afd3d0963.tar.xz
poezio-12700fdaee46a979478d061d5039190afd3d0963.zip
Merge branch 'tabs-slice' into 'master'
Allow Tabs object to be sliced See merge request poezio/poezio!11
-rw-r--r--poezio/core/tabs.py8
-rw-r--r--test/test_tabs.py11
2 files changed, 15 insertions, 4 deletions
diff --git a/poezio/core/tabs.py b/poezio/core/tabs.py
index bcf6dd41..3ced7a7e 100644
--- a/poezio/core/tabs.py
+++ b/poezio/core/tabs.py
@@ -67,10 +67,10 @@ class Tabs:
def __iter__(self):
return iter(self._tabs)
- def __getitem__(self, index: Union[int, str]):
- if isinstance(index, int):
- return self._tabs[index]
- return self.by_name(index)
+ def __getitem__(self, index: Union[int, str, slice]):
+ if isinstance(index, str):
+ return self.by_name(index)
+ return self._tabs[index]
def first(self) -> tabs.Tab:
"""Return the Roster tab"""
diff --git a/test/test_tabs.py b/test/test_tabs.py
index aab4f0d0..0a6930d4 100644
--- a/test/test_tabs.py
+++ b/test/test_tabs.py
@@ -172,3 +172,14 @@ def test_set_current():
tabs.set_current_tab(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