Skip to content

Commit 4d304c0

Browse files
committed
Use skipTest instead of returns, add some TODOs for myself etc.
1 parent a728f84 commit 4d304c0

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

splunklib/results.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ def __init__(self, stream):
309309
# JSON documents, each containing a result, as opposed to one
310310
# results element containing lots of results.
311311
stream = BufferedReader(stream)
312-
self.is_preview = None
312+
# Removed in Splunk 10
313+
self.is_preview = False
313314
self._gen = self._parse_results(stream)
314315

315316
def __iter__(self):

tests/searchcommands/test_csc_apps.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
from tests import testlib
2323

2424

25+
# FIXME: Flaky. Splunk sometimes crashes, thus tests fail with timeouts,
26+
# reset/refused connection errors etc. Doesn't seem to be our fault.
2527
@pytest.mark.smoke
2628
class TestCSC(testlib.SDKTestCase):
27-
# FIXME: Flaky - Splunk sometimes crashes, thus the test fails.
28-
# Not sure whose fault it is yet.
2929
def test_eventing_app(self):
3030
app_name = "eventing_app"
31-
3231
self.assertTrue(
33-
app_name in self.service.apps, msg="%s is not installed." % app_name
32+
app_name in self.service.apps, msg=f"{app_name} is not installed."
3433
)
3534

3635
# Fetch the app
@@ -67,27 +66,26 @@ def test_eventing_app(self):
6766
self.assertEqual(state.title, "eventing_app")
6867

6968
jobs = self.service.jobs
69+
# TODO: Add debug logging for query waiting time
7070
stream = jobs.oneshot(
7171
'search index="_internal" | head 4000 | eventingcsc status=200 | head 10',
7272
output_mode="json",
7373
)
7474
result = results.JSONResultsReader(stream)
75-
ds = list(result)
75+
msgs = list(result)
7676

77+
# TODO: Why is this assert here?
7778
if self.service.splunk_version < (10,):
7879
self.assertEqual(result.is_preview, False)
7980

80-
self.assertTrue(isinstance(ds[0], (dict, results.Message)))
81-
nonmessages = [d for d in ds if isinstance(d, dict)]
81+
self.assertTrue(isinstance(msgs[0], (dict, results.Message)))
82+
nonmessages = [msg for msg in msgs if isinstance(msg, dict)]
8283
self.assertTrue(len(nonmessages) <= 10)
8384

84-
# FIXME: Flaky - Splunk sometimes crashes, thus the test fails.
85-
# Not sure whose fault it is yet.
8685
def test_generating_app(self):
8786
app_name = "generating_app"
88-
8987
self.assertTrue(
90-
app_name in self.service.apps, msg="%s is not installed." % app_name
88+
app_name in self.service.apps, msg=f"{app_name} is not installed."
9189
)
9290

9391
# Fetch the app
@@ -133,9 +131,8 @@ def test_generating_app(self):
133131

134132
def test_reporting_app(self):
135133
app_name = "reporting_app"
136-
137134
self.assertTrue(
138-
app_name in self.service.apps, msg="%s is not installed." % app_name
135+
app_name in self.service.apps, msg=f"{app_name} is not installed."
139136
)
140137

141138
# Fetch the app

tests/test_job.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_oneshot(self):
5959
ds = list(result)
6060

6161
if self.service.splunk_version < (10,):
62+
# TODO: Why is this assert here?
6263
self.assertEqual(result.is_preview, False)
6364

6465
self.assertTrue(isinstance(ds[0], dict) or isinstance(ds[0], results.Message))
@@ -78,6 +79,7 @@ def test_export(self):
7879
ds = list(result)
7980

8081
if self.service.splunk_version < (10,):
82+
# TODO: Why is this assert here?
8183
self.assertEqual(result.is_preview, False)
8284

8385
self.assertTrue(isinstance(ds[0], dict) or isinstance(ds[0], results.Message))
@@ -101,6 +103,7 @@ def test_export_docstring_sample(self):
101103
pass # print(result)
102104

103105
if self.service.splunk_version < (10,):
106+
# TODO: Why is this assert here?
104107
self.assertFalse(rr.is_preview)
105108

106109
def test_results_docstring_sample(self):
@@ -120,11 +123,11 @@ def test_results_docstring_sample(self):
120123
pass # print(result)
121124

122125
if self.service.splunk_version < (10,):
126+
# TODO: Why is this assert here?
123127
self.assertFalse(rr.is_preview)
124128

125129
def test_preview_docstring_sample(self):
126-
from splunklib import client
127-
from splunklib import results
130+
from splunklib import client, results
128131

129132
service = self.service # cheat
130133
job = service.jobs.create("search * | head 5")
@@ -137,12 +140,6 @@ def test_preview_docstring_sample(self):
137140
# Normal events are returned as dicts
138141
pass # print(result)
139142

140-
if self.service.splunk_version < (10,):
141-
if rr.is_preview:
142-
pass # print("Preview of a running search job.")
143-
else:
144-
pass # print("Job is finished. Results are final.")
145-
146143
def test_oneshot_docstring_sample(self):
147144
from splunklib import results
148145

@@ -159,6 +156,7 @@ def test_oneshot_docstring_sample(self):
159156
pass # print(result)
160157

161158
if self.service.splunk_version < (10,):
159+
# TODO: Why is this assert here?
162160
self.assertFalse(rr.is_preview)
163161

164162
def test_normal_job_with_garbage_fails(self):

tests/test_modular_input_kinds.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# under the License.
1616

1717
import pytest
18-
18+
import unittest
1919
from tests import testlib
2020

2121
from splunklib import client
@@ -31,8 +31,7 @@ def test_list_arguments(self):
3131
self.install_app_from_collection("modular_inputs")
3232

3333
if self.service.splunk_version[0] < 5:
34-
# Not implemented before 5.0
35-
return
34+
self.skipTest("Not implemented before 5.0")
3635

3736
test1 = self.service.modular_input_kinds["test1"]
3837

@@ -59,8 +58,7 @@ def test_update_raises_exception(self):
5958
self.install_app_from_collection("modular_inputs")
6059

6160
if self.service.splunk_version[0] < 5:
62-
# Not implemented before 5.0
63-
return
61+
self.skipTest("Not implemented before 5.0")
6462

6563
test1 = self.service.modular_input_kinds["test1"]
6664
self.assertRaises(client.IllegalOperationException, test1.update, a="b")
@@ -78,8 +76,7 @@ def test_list_modular_inputs(self):
7876
self.install_app_from_collection("modular_inputs")
7977

8078
if self.service.splunk_version[0] < 5:
81-
# Not implemented before 5.0
82-
return
79+
self.skipTest("Not implemented before 5.0")
8380

8481
for m in self.service.modular_input_kinds:
8582
self.check_modular_input_kind(m)

0 commit comments

Comments
 (0)