Skip to content

Commit 7aa2b55

Browse files
author
Frederick Ross
committed
Fixed running test suite and coverage from the command line.
Cleaned up various files that were lying around.
1 parent b809148 commit 7aa2b55

36 files changed

+127
-108150
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ built on Splunk and should not be used if you are concerned about the security
8686
of the credentails used in your development environment.
8787

8888
You can view a sample `.splunkrc` file by looking at the `splunkrc.spec` file
89-
in the root directory of the repistory.
89+
in the root directory of the repository.
9090

9191
## Overview
9292

setup.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,63 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
from distutils.core import setup
18-
17+
from distutils.core import setup, Command
18+
import os, shutil
1919
import splunklib
2020

21+
def run_test_suite():
22+
import unittest
23+
original_cwd = os.path.abspath(os.getcwd())
24+
os.chdir('tests')
25+
suite = unittest.defaultTestLoader.discover('.')
26+
unittest.TextTestRunner().run(suite)
27+
os.chdir(original_cwd)
28+
29+
class CoverageCommand(Command):
30+
"""setup.py command to run code coverage of the test suite."""
31+
description = "Create an HTML coverage report from running the full test suite."
32+
user_options = []
33+
34+
def initialize_options(self):
35+
pass
36+
37+
def finalize_options(self):
38+
pass
39+
40+
def run(self):
41+
try:
42+
import coverage
43+
except ImportError:
44+
print "Could not import coverage. Please install it and try again."
45+
exit(1)
46+
cov = coverage.coverage(source=['splunklib'])
47+
cov.start()
48+
run_test_suite()
49+
cov.stop()
50+
cov.html_report(directory='coverage_report')
51+
52+
class TestCommand(Command):
53+
"""setup.py command to run the whole test suite."""
54+
description = "Run test full test suite."
55+
user_options = []
56+
57+
def initialize_options(self):
58+
pass
59+
60+
def finalize_options(self):
61+
pass
62+
63+
def run(self):
64+
run_test_suite()
65+
2166
setup(
2267
author="Splunk, Inc.",
2368

2469
author_email="[email protected]",
2570

71+
cmdclass={'coverage': CoverageCommand,
72+
'test': TestCommand},
73+
2674
description="The Splunk Software Development Kit for Python.",
2775

2876
license="http://www.apache.org/licenses/LICENSE-2.0",
@@ -47,3 +95,4 @@
4795
],
4896
)
4997

98+

tests/README.md

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The truth is that there really isn't a Splunk Test Framework. It simply uses
44
Python's builtin unittest module.
55

66
Each distinct area of the SDK is tested in a single file. For example,
7-
`splunk.client` is tested in `test_client.py`, while the examples are tested
7+
roles are tested in `test_role.py`, while the examples are tested
88
in `test_examples.py`.
99

1010
Before running the test suite, make sure the instance of Splunk you
@@ -15,15 +15,19 @@ should at least disable the *NIX and Windows apps. Do not run the test
1515
suite against a production instance of Splunk! It will run just fine
1616
with the free Splunk license, so don't be stingy with instances.
1717

18-
There are no dependencies to run the tests. You can simply execute:
18+
You also need to install the `sdk-app-collection` app in your instance of
19+
Splunk. The `sdk-app-collection` is a set of small, single purpose apps
20+
for testing capabilities that cannot be created with the REST API.You can
21+
fetch it from `https://github.com/splunk/sdk-app-collection`. Put the
22+
whole repository in `$SPLUNK_HOME/etc/apps`, so the git root would be
23+
`$SPLUNK_HOME/etc/apps/sdk-app-collection`.
1924

20-
cd tests
21-
python -m unittest discover
25+
The test suite depends on nothing but Python's standard library. You can
26+
simply execute:
2227

23-
or, if you have py.test installed,
28+
python setup.py test
2429

25-
cd tests
26-
py.test
30+
or run the test_all.py script in the tests/ directory.
2731

2832
## Code Coverage
2933

@@ -33,32 +37,16 @@ at the author's website: http://nedbatchelder.com/code/coverage/
3337

3438
To install it, simply use `easy_install` or `pip`:
3539

36-
easy_install coverage
40+
pip install coverage
3741

3842
or
3943

40-
pip install coverage
44+
easy_install coverage
4145

4246
Once you have `coverage.py` installed, you can run get coverage information
4347
as follows:
4448

45-
cd tests
46-
coverage run runtests.py
47-
coverage combine
48-
coverage report
49-
50-
If you are using py.test, youcan replace
51-
52-
coverage run runtests.py
53-
54-
with
55-
56-
coverage run `which py.test`
57-
58-
which provides better reporting, and lets you specify any additional
59-
options, such as a particular file to test. Should you want to get an
60-
HTML report:
61-
62-
coverage html
49+
python setup.py coverage
6350

64-
and open `coverage_html_report/index.html` in your favorite browser.
51+
This will create an HTML report in coverage_html/. Open `coverage_html/index.html`
52+
in your favorite browser to see the coverage report.

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pass
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)