Skip to content

Commit 3af370d

Browse files
committed
test case fix
1 parent 079df7b commit 3af370d

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

splunklib/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,8 @@ def __getitem__(self, key):
17261726
except HTTPError as he:
17271727
if he.status == 404: # No entity matching key
17281728
raise KeyError(key)
1729-
raise
1729+
else:
1730+
raise
17301731

17311732
def __contains__(self, key):
17321733
# configs/conf-{name} never returns a 404. We have to post to properties/{name}
@@ -2248,7 +2249,8 @@ def __getitem__(self, key):
22482249
except HTTPError as he:
22492250
if he.status == 404:
22502251
pass # Just carry on to the next kind.
2251-
raise
2252+
else:
2253+
raise
22522254
if candidate is None:
22532255
raise KeyError(key) # Never found a match.
22542256
return candidate
@@ -2275,7 +2277,8 @@ def __contains__(self, key):
22752277
except HTTPError as he:
22762278
if he.status == 404:
22772279
pass # Just carry on to the next kind.
2278-
raise
2280+
else:
2281+
raise
22792282
return False
22802283

22812284
def create(self, name, kind, **kwargs):
@@ -2559,7 +2562,8 @@ def list(self, *kinds, **kwargs):
25592562
except HTTPError as e:
25602563
if e.status == 404:
25612564
continue # No inputs of this kind
2562-
raise
2565+
else:
2566+
raise
25632567

25642568
entries = _load_atom_entries(response)
25652569
if entries is None: continue # No inputs to process

tests/test_input.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from splunklib import client
2222

2323

24-
2524
def highest_port(service, base_port, *kinds):
2625
"""Find the first port >= base_port not in use by any input in kinds."""
2726
highest_port = base_port
@@ -45,7 +44,7 @@ def tearDown(self):
4544

4645
def create_tcp_input(self, base_port, kind, **options):
4746
port = base_port
48-
while True: # Find the next unbound port
47+
while True: # Find the next unbound port
4948
try:
5049
input = self.service.inputs.create(str(port), kind, **options)
5150
return input
@@ -66,7 +65,7 @@ def test_cannot_create_with_restrictToHost_in_name(self):
6665
)
6766

6867
def test_create_tcp_ports_with_restrictToHost(self):
69-
for kind in ['tcp', 'splunktcp']: # Multiplexed UDP ports are not supported
68+
for kind in ['tcp', 'splunktcp']: # Multiplexed UDP ports are not supported
7069
# Make sure we can create two restricted inputs on the same port
7170
boris = self.service.inputs.create(str(self.base_port), kind, restrictToHost='boris')
7271
natasha = self.service.inputs.create(str(self.base_port), kind, restrictToHost='natasha')
@@ -101,7 +100,7 @@ def test_unrestricted_to_restricted_collision(self):
101100
unrestricted.delete()
102101

103102
def test_update_restrictToHost_fails(self):
104-
for kind in ['tcp', 'splunktcp']: # No UDP, since it's broken in Splunk
103+
for kind in ['tcp', 'splunktcp']: # No UDP, since it's broken in Splunk
105104
boris = self.create_tcp_input(self.base_port, kind, restrictToHost='boris')
106105

107106
self.assertRaises(
@@ -171,21 +170,22 @@ def test_oneshot(self):
171170

172171
def f():
173172
index.refresh()
174-
return int(index['totalEventCount']) == eventCount+4
173+
return int(index['totalEventCount']) == eventCount + 4
174+
175175
self.assertEventuallyTrue(f, timeout=60)
176176

177177
def test_oneshot_on_nonexistant_file(self):
178178
name = testlib.tmpname()
179179
self.assertRaises(HTTPError,
180-
self.service.inputs.oneshot, name)
180+
self.service.inputs.oneshot, name)
181181

182182

183183
class TestInput(testlib.SDKTestCase):
184184
def setUp(self):
185185
super().setUp()
186186
inputs = self.service.inputs
187-
unrestricted_port = str(highest_port(self.service, 10000, 'tcp', 'splunktcp', 'udp')+1)
188-
restricted_port = str(highest_port(self.service, int(unrestricted_port)+1, 'tcp', 'splunktcp')+1)
187+
unrestricted_port = str(highest_port(self.service, 10000, 'tcp', 'splunktcp', 'udp') + 1)
188+
restricted_port = str(highest_port(self.service, int(unrestricted_port) + 1, 'tcp', 'splunktcp') + 1)
189189
test_inputs = [{'kind': 'tcp', 'name': unrestricted_port, 'host': 'sdk-test'},
190190
{'kind': 'udp', 'name': unrestricted_port, 'host': 'sdk-test'},
191191
{'kind': 'tcp', 'name': 'boris:' + restricted_port, 'host': 'sdk-test'}]
@@ -223,7 +223,7 @@ def test_lists_modular_inputs(self):
223223
self.uncheckedRestartSplunk()
224224

225225
inputs = self.service.inputs
226-
if ('abcd','test2') not in inputs:
226+
if ('abcd', 'test2') not in inputs:
227227
inputs.create('abcd', 'test2', field1='boris')
228228

229229
input = inputs['abcd', 'test2']
@@ -268,19 +268,19 @@ def test_update(self):
268268
@pytest.mark.skip('flaky')
269269
def test_delete(self):
270270
inputs = self.service.inputs
271-
remaining = len(self._test_entities)-1
271+
remaining = len(self._test_entities) - 1
272272
for input_entity in self._test_entities.values():
273273
name = input_entity.name
274274
kind = input_entity.kind
275275
self.assertTrue(name in inputs)
276-
self.assertTrue((name,kind) in inputs)
276+
self.assertTrue((name, kind) in inputs)
277277
if remaining == 0:
278278
inputs.delete(name)
279279
self.assertFalse(name in inputs)
280280
else:
281281
if not name.startswith('boris'):
282282
self.assertRaises(client.AmbiguousReferenceException,
283-
inputs.delete, name)
283+
inputs.delete, name)
284284
self.service.inputs.delete(name, kind)
285285
self.assertFalse((name, kind) in inputs)
286286
self.assertRaises(client.HTTPError,
@@ -290,4 +290,5 @@ def test_delete(self):
290290

291291
if __name__ == "__main__":
292292
import unittest
293+
293294
unittest.main()

0 commit comments

Comments
 (0)