File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1313import random
1414from .. import Pane , Window , Session
1515from . import t
16- from .helpers import TmuxTestCase
16+ from .helpers import TmuxTestCase , TEST_SESSION_PREFIX
1717
1818import logging
1919
@@ -58,6 +58,21 @@ def test_findWhere(self):
5858 self .assertIsInstance (window .findWhere (
5959 {'pane_id' : pane_id }), Pane )
6060
61+ def test_findWhere_None (self ):
62+ """.findWhere returns None if no results found."""
63+
64+ while True :
65+ nonexistant_session = TEST_SESSION_PREFIX + str (
66+ random .randint (0 , 9999 )
67+ )
68+
69+ if not t .has_session (nonexistant_session ):
70+ break
71+
72+ self .assertIsNone (t .findWhere ({
73+ 'session_name' : nonexistant_session
74+ }))
75+
6176 def test_findWhere_multiple_attrs (self ):
6277 """.findWhere returns objects with multiple attributes."""
6378
Original file line number Diff line number Diff line change @@ -156,7 +156,10 @@ def findWhere(self, attrs):
156156 .. _underscore.js: http://underscorejs.org/
157157
158158 """
159- return self .where (attrs )[0 ] or None
159+ try :
160+ return self .where (attrs )[0 ]
161+ except IndexError :
162+ return None
160163
161164 def where (self , attrs , first = False ):
162165 """Return objects matching child objects properties.
You can’t perform that action at this time.
0 commit comments