Skip to content

Commit fa8c121

Browse files
author
Frederick Ross
committed
Resolve comments from code review by Brad and Itay.
Add docstring to client.trailing. Replace while …: pass in test_job.py with while …: sleep(1) to avoid wasting cycles.
1 parent d1e5ed7 commit fa8c121

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

splunklib/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ class JobNotReadyException(Exception):
114114
pass
115115

116116
def trailing(template, *targets):
117+
"""Substring of *template* following all *targets*.
118+
119+
Most easily explained by example::
120+
121+
template = "this is a test of the bunnies."
122+
trailing(template, "is", "est", "the") == \
123+
" bunnies"
124+
125+
Each target is matched successively in the string, and the string
126+
remaining after the last target is returned. If one of the targets
127+
fails to match, a ValueError is raised.
128+
129+
:param template: Template to extract a trailing string from.
130+
:type template: string
131+
:param targets: Strings to successively match in *template*.
132+
:type targets: strings
133+
:returns: Trailing string after all targets are matched.
134+
:rtype: string
135+
:raises ValueError: when one of the targets does not match.
136+
"""
117137
s = template
118138
for t in targets:
119139
n = s.find(t)

tests/test_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_results(self):
173173
# here as a caution to future generations:
174174
# self.assertRaises(ValueError, job.results)
175175
while not job.isDone():
176-
pass
176+
sleep(1)
177177
reader = results.ResultsReader(job.results(timeout=60))
178178
job.refresh()
179179
self.assertEqual(job['isDone'], '1')
@@ -187,7 +187,7 @@ def test_results(self):
187187
# Repeat the same thing, but without the .is_preview reference.
188188
job = jobs.create("search index=_internal | head 1 | stats count")
189189
while not job.isDone():
190-
pass
190+
sleep(1)
191191
reader = results.ResultsReader(job.results(timeout=60))
192192
job.refresh()
193193
self.assertEqual(job['isDone'], '1')

0 commit comments

Comments
 (0)