Skip to content

Commit f5e21ef

Browse files
committed
Merge remote-tracking branch 'origin/smoke-tests' into use_output_redirect_for_modinput_tests
2 parents 67499bd + 91a638a commit f5e21ef

File tree

16 files changed

+93
-62
lines changed

16 files changed

+93
-62
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ before_install:
2929
- export SPLUNK_HOME=`pwd`/splunk_home
3030
- mkdir -p $SPLUNK_HOME/var/log/splunk
3131

32+
language: python
33+
3234
env:
33-
- SPLUNK_VERSION=7.0-sdk
34-
- SPLUNK_VERSION=7.2-sdk
35+
- SPLUNK_VERSION=7.3-sdk
3536
- SPLUNK_VERSION=8.0-sdk
3637

37-
language: python
38-
3938
python:
4039
- "2.7"
41-
- "3.5"
40+
- "3.7"
4241

43-
install: "pip install unittest2"
42+
install: pip install tox-travis
4443

4544
before_script: python setup.py build dist
4645

47-
script: python setup.py test
46+
script: tox

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ COMMITHASH := `git rev-parse --short HEAD 2>/dev/null`
1616
DATE := `date "+%FT%T%z"`
1717

1818
.PHONY: all
19-
all: test
19+
all: build_app test
2020

2121
init:
2222
@echo "$(ATTN_COLOR)==> init $(NO_COLOR)"
2323

24+
.PHONY: build_app
25+
build_app:
26+
@echo "$(ATTN_COLOR)==> build_app $(NO_COLOR)"
27+
@python setup.py build dist
28+
2429
.PHONY: test
2530
test:
2631
@echo "$(ATTN_COLOR)==> test $(NO_COLOR)"

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ To get help for an example, use the `--help` argument with an example:
161161
The Splunk SDK for Python contains a collection of unit tests. To run them, open a
162162
command prompt in the **/splunk-sdk-python** directory and enter:
163163

164-
make test
164+
make
165165

166166
You can also run individual test files, which are located in
167167
**/splunk-sdk-python/tests**. The following command explains how to run
@@ -172,7 +172,9 @@ a specific test:
172172
The test suite uses Python's standard library, the built-in `unittest`
173173
library, `pytest`, and `tox`.
174174

175-
**Important Note:** The test run will fail unless the
175+
**Important Notes:**
176+
177+
The test run will fail unless the
176178
[SDK App Collection](https://github.com/splunk/sdk-app-collection) is installed.
177179

178180
You can exclude app-specific tests with the following command:
@@ -182,6 +184,10 @@ You can exclude app-specific tests with the following command:
182184
You can read more about our testing framework on
183185
[GitHub](https://github.com/splunk/splunk-sdk-python/tree/master/tests).
184186

187+
In addition, the test run requires the searchcommands app to be built. The `make`
188+
command runs the tasks to do this, but more complex testing may require you to
189+
rebuild using `make build_app`.
190+
185191
## Repository
186192

187193
<table>

examples/async/async.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# based systems like Eventlet.
2020

2121
#### Main Code
22-
2322
from __future__ import absolute_import
2423
from __future__ import print_function
2524
import sys, os, datetime
@@ -67,10 +66,10 @@ def main(argv):
6766
# of `urllib2`. Otherwise, import the stdlib version of `urllib2`.
6867
#
6968
# The reason for the funky import syntax is that Python imports
70-
# are scoped to functions, and we need to make it global.
69+
# are scoped to functions, and we need to make it global.
7170
# In a real application, you would only import one of these.
7271
if is_async:
73-
urllib2 = __import__('eventlet.green', globals(), locals(),
72+
urllib2 = __import__('eventlet.green', globals(), locals(),
7473
['urllib2'], -1).urllib2
7574
else:
7675
urllib2 = __import__("urllib2", globals(), locals(), [], -1)
@@ -143,12 +142,12 @@ def do_search(query):
143142
# and we can also ignore the result.
144143
for query in queries:
145144
do_search(query)
146-
145+
147146
# Record the current time at the end of the benchmark,
148147
# and print the delta elapsed time.
149148
newtime = datetime.datetime.now()
150149
print("Elapsed Time: %s" % (newtime - oldtime))
151-
150+
152151

153152
##### Custom `urllib2`-based HTTP handler
154153

@@ -158,21 +157,21 @@ def request(url, message, **kwargs):
158157
body = message.get("body", "")
159158

160159
# Setup the default headers.
161-
head = {
160+
head = {
162161
"Content-Length": str(len(body)),
163162
"Host": host,
164163
"User-Agent": "http.py/1.0",
165164
"Accept": "*/*",
166165
}
167166

168167
# Add in the passed in headers.
169-
for key, value in message["headers"]:
168+
for key, value in message["headers"]:
170169
head[key] = value
171170

172171
# Note the HTTP method we're using, defaulting
173172
# to `GET`.
174173
method = message.get("method", "GET")
175-
174+
176175
# Note that we do not support proxies in this example
177176
# If running Python 2.7.9+, disable SSL certificate validation
178177
if sys.version_info >= (2, 7, 9):
@@ -181,7 +180,7 @@ def request(url, message, **kwargs):
181180
else:
182181
opener = urllib2.build_opener()
183182

184-
# Unfortunately, we need to use the hack of
183+
# Unfortunately, we need to use the hack of
185184
# "overriding" `request.get_method` to specify
186185
# a method other than `GET` or `POST`.
187186
request = urllib2.Request(url, body, head)
@@ -194,10 +193,10 @@ def request(url, message, **kwargs):
194193
except Exception as e:
195194
response = e
196195

197-
# Normalize the response to something the SDK expects, and
196+
# Normalize the response to something the SDK expects, and
198197
# return it.
199198
return {
200-
'status': response.code,
199+
'status': response.code,
201200
'reason': response.msg,
202201
'headers': response.info().dict,
203202
'body': binding.ResponseReader(response)

examples/searchcommands_app/package/bin/countmatches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def stream(self, records):
6767
for record in records:
6868
count = 0
6969
for fieldname in self.fieldnames:
70-
matches = pattern.findall(six.text_type(record[fieldname].decode("utf-8")))
70+
matches = pattern.findall(six.text_type(six.ensure_binary(record[fieldname]).decode("utf-8")))
7171
count += len(matches)
7272
record[self.fieldname] = count
7373
yield record

examples/searchcommands_app/package/default/logging.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ propagate = 0
7171
keys = app, splunklib, stderr
7272

7373
[handler_app]
74-
# Select this handler to log events to $SPLUNK_HOME/var/log/splunk/searchcommands_app.log
74+
# Select this handler to log events to searchcommands_app.log
7575
class = logging.handlers.RotatingFileHandler
7676
level = NOTSET
77-
args = ('%(SPLUNK_HOME)s/var/log/splunk/searchcommands_app.log', 'a', 524288000, 9, 'utf-8', True)
77+
args = ('searchcommands_app.log', 'a', 524288000, 9, 'utf-8', True)
7878
formatter = searchcommands
7979

8080
[handler_splunklib]
81-
# Select this handler to log events to $SPLUNK_HOME/var/log/splunk/splunklib.log
81+
# Select this handler to log events to splunklib.log
8282
class = logging.handlers.RotatingFileHandler
83-
args = ('%(SPLUNK_HOME)s/var/log/splunk/splunklib.log', 'a', 524288000, 9, 'utf-8', True)
83+
args = ('splunklib.log', 'a', 524288000, 9, 'utf-8', True)
8484
level = NOTSET
8585
formatter = searchcommands
8686

splunklib/searchcommands/reporting_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def fix_up(cls, command):
253253
cls._requires_preop = False
254254
return
255255

256-
f = vars(command)[b'map'] # Function backing the map method
256+
f = vars(command)['map'] # Function backing the map method
257257

258258
# EXPLANATION OF PREVIOUS STATEMENT: There is no way to add custom attributes to methods. See [Why does
259259
# setattr fail on a method](http://stackoverflow.com/questions/7891277/why-does-setattr-fail-on-a-bound-method) for a discussion of this issue.
@@ -266,7 +266,7 @@ def fix_up(cls, command):
266266

267267
# Create new StreamingCommand.ConfigurationSettings class
268268

269-
module = command.__module__ + b'.' + command.__name__ + b'.map'
269+
module = command.__module__ + '.' + command.__name__ + '.map'
270270
name = b'ConfigurationSettings'
271271
bases = (StreamingCommand.ConfigurationSettings,)
272272

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO: Flesh this out
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
total,__mv_total
3+
2147943.07810599,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
total,__mv_total
3+
2147943.07811,

0 commit comments

Comments
 (0)