forked from splunk/splunk-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·162 lines (123 loc) · 4.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
#
# Copyright 2011-2015 Splunk, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"): you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from setuptools import setup, Command
import os
import sys
import splunklib
failed = False
def run_test_suite():
try:
import unittest2 as unittest
except ImportError:
import unittest
def mark_failed():
global failed
failed = True
class _TrackingTextTestResult(unittest._TextTestResult):
def addError(self, test, err):
unittest._TextTestResult.addError(self, test, err)
mark_failed()
def addFailure(self, test, err):
unittest._TextTestResult.addFailure(self, test, err)
mark_failed()
class TrackingTextTestRunner(unittest.TextTestRunner):
def _makeResult(self):
return _TrackingTextTestResult(
self.stream, self.descriptions, self.verbosity)
original_cwd = os.path.abspath(os.getcwd())
os.chdir('tests')
suite = unittest.defaultTestLoader.discover('.')
runner = TrackingTextTestRunner(verbosity=2)
runner.run(suite)
os.chdir(original_cwd)
return failed
def run_test_suite_with_junit_output():
try:
import unittest2 as unittest
except ImportError:
import unittest
import xmlrunner
original_cwd = os.path.abspath(os.getcwd())
os.chdir('tests')
suite = unittest.defaultTestLoader.discover('.')
xmlrunner.XMLTestRunner(output='../test-reports').run(suite)
os.chdir(original_cwd)
class CoverageCommand(Command):
"""setup.py command to run code coverage of the test suite."""
description = "Create an HTML coverage report from running the full test suite."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
import coverage
except ImportError:
print("Could not import coverage. Please install it and try again.")
exit(1)
cov = coverage.coverage(source=['splunklib'])
cov.start()
run_test_suite()
cov.stop()
cov.html_report(directory='coverage_report')
class TestCommand(Command):
"""setup.py command to run the whole test suite."""
description = "Run test full test suite."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
failed = run_test_suite()
if failed:
sys.exit(1)
class JunitXmlTestCommand(Command):
"""setup.py command to run the whole test suite."""
description = "Run test full test suite with JUnit-formatted output."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
run_test_suite_with_junit_output()
setup(
author="Splunk, Inc.",
author_email="devinfo@splunk.com",
cmdclass={'coverage': CoverageCommand,
'test': TestCommand,
'testjunit': JunitXmlTestCommand},
description="The Splunk Software Development Kit for Python.",
license="http://www.apache.org/licenses/LICENSE-2.0",
name="splunk-sdk",
packages = ["splunklib",
"splunklib.modularinput",
"splunklib.searchcommands"],
url="http://github.com/splunk/splunk-sdk-python",
version=splunklib.__version__,
classifiers = [
"Programming Language :: Python",
"Development Status :: 6 - Mature",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Libraries :: Application Frameworks",
],
)