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 13
13
import random
14
14
from .. import Pane , Window , Session
15
15
from . import t
16
- from .helpers import TmuxTestCase
16
+ from .helpers import TmuxTestCase , TEST_SESSION_PREFIX
17
17
18
18
import logging
19
19
@@ -58,6 +58,21 @@ def test_findWhere(self):
58
58
self .assertIsInstance (window .findWhere (
59
59
{'pane_id' : pane_id }), Pane )
60
60
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
+
61
76
def test_findWhere_multiple_attrs (self ):
62
77
""".findWhere returns objects with multiple attributes."""
63
78
Original file line number Diff line number Diff line change @@ -156,7 +156,10 @@ def findWhere(self, attrs):
156
156
.. _underscore.js: http://underscorejs.org/
157
157
158
158
"""
159
- return self .where (attrs )[0 ] or None
159
+ try :
160
+ return self .where (attrs )[0 ]
161
+ except IndexError :
162
+ return None
160
163
161
164
def where (self , attrs , first = False ):
162
165
"""Return objects matching child objects properties.
You can’t perform that action at this time.
0 commit comments