Skip to content

Commit 8574bb5

Browse files
author
Frederick Ross
committed
Finished making all tests pass on Python 2.6.
Also fixed README.md's instructions for running the test suite.
1 parent 0b6f147 commit 8574bb5

6 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,18 @@ away some of the lower level details of the _binding_ layer.
141141
### Unit tests
142142

143143
The SDK contains a small but growing collection of unit tests. Running the
144-
tests is simple and rewarding:
144+
tests is simple and rewarding. If you are using Python 2.7, the test suite
145+
will run using only Python's standard library. If you are using Python 2.6,
146+
you need to install the `unittest2` library, since the test suite depends on
147+
features added to `unittest` in Python 2.7. `unittest2` is only needed for
148+
the running test suite, not for using the SDK.
145149

146-
> cd tests<br>
147-
> python runtests.py
150+
To run the test suite, run the following command in the top level directory
151+
of the SDK repository:
152+
153+
> python setup.py test
154+
155+
You can also run the test_all.py script in the tests/ directory.
148156

149157
Alternatively, you can read more about our testing "framework"
150158
[here](https://github.com/splunk/splunk-sdk-python/tree/master/tests).

‎setup.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import splunklib
2020

2121
def run_test_suite():
22-
import unittest
22+
import unittest2
2323
original_cwd = os.path.abspath(os.getcwd())
2424
os.chdir('tests')
25-
suite = unittest.defaultTestLoader.discover('.')
26-
unittest.TextTestRunner().run(suite)
25+
suite = unittest2.defaultTestLoader.discover('.')
26+
unittest2.TextTestRunner().run(suite)
2727
os.chdir(original_cwd)
2828

2929
class CoverageCommand(Command):

‎splunklib/client.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ def oneshot(self, path, **kwargs):
24722472
self.post('oneshot', name=path, **kwargs)
24732473
except HTTPError as he:
24742474
if he.status == 400:
2475-
raise OperationFailedException(he.message)
2475+
raise OperationFailedException(str(he))
24762476
else:
24772477
raise
24782478

@@ -2848,7 +2848,7 @@ def create(self, query, **kwargs):
28482848
response = self.post(search=query, **kwargs)
28492849
except HTTPError as he:
28502850
if he.status == 400: # Bad request. Raise a TypeError with the reason.
2851-
raise TypeError(he.message)
2851+
raise TypeError(str(he))
28522852
sid = _load_sid(response)
28532853
return Job(self.service, sid)
28542854

‎tests/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ fetch it from `https://github.com/splunk/sdk-app-collection`. Put the
2222
whole repository in `$SPLUNK_HOME/etc/apps`, so the git root would be
2323
`$SPLUNK_HOME/etc/apps/sdk-app-collection`.
2424

25+
If you are running Python 2.6, you must install the `unittest2` library,
26+
since the test suite depends on features added to `unittest` in Python 2.7.
27+
Python 2.7 should run the test suite using only Python's standard library.
28+
2529
The test suite depends on nothing but Python's standard library. You can
2630
simply execute:
2731

‎tests/test_job.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_normal_job_with_garbage_fails(self):
6666
bad_search = "abcd|asfwqqq"
6767
jobs.create(bad_search)
6868
except TypeError as te:
69-
self.assertTrue('abcd' in te.message)
69+
self.assertTrue('abcd' in str(te))
7070
return
7171
self.fail("Job with garbage search failed to raise TypeError.")
7272

‎tests/test_saved_search.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ def test_scheduled_times(self):
174174
time_pairs = zip(scheduled_times[:-1], scheduled_times[1:])
175175
for earlier, later in time_pairs:
176176
diff = later-earlier
177-
self.assertEqual(diff.total_seconds()/60, 5)
177+
# diff is an instance of datetime.timedelta, which
178+
# didn't get a total_seconds() method until Python 2.7.
179+
# Since we support Python 2.6, we have to calculate the
180+
# total seconds ourselves.
181+
total_seconds = diff.days*24*60*60 + diff.seconds
182+
self.assertEqual(total_seconds/60.0, 5)
178183

179184
def test_no_equality(self):
180185
self.assertRaises(client.IncomparableException,

0 commit comments

Comments
 (0)