summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2018-11-01 14:46:36 -0400
committerMatthew Treinish <mtreinish@kortar.org>2019-12-15 14:26:32 -0500
commit05cf8b497befd75207a910450d9eeafc7affa5e1 (patch)
tree515d52ac260f3057d9164080373cd435cf8bb30e
parent8e79501adca5df505436e942fff15c76916c0de1 (diff)
downloadsubunit-git-05cf8b497befd75207a910450d9eeafc7affa5e1.tar.gz
Switch to setuptools entrypoint console scripts for filters
This commit switches from using scripts to setuptools entrypoint console scripts for the filter scripts. This should fix the issues for windows users trying to execute the scripts. To accomplish this the filter scripts are moved into the subunit package namespace and a callable to run the script is added to each module. Closes-Bug: #1322888
-rwxr-xr-xfilters/subunit-ls60
-rwxr-xr-xfilters/subunit2pyunit59
-rw-r--r--python/subunit/filter_scripts/__init__.py0
-rwxr-xr-xpython/subunit/filter_scripts/subunit2csv.py (renamed from filters/subunit2csv)9
-rwxr-xr-xpython/subunit/filter_scripts/subunit2disk.py (renamed from filters/subunit2disk)6
-rwxr-xr-xpython/subunit/filter_scripts/subunit2gtk.py (renamed from filters/subunit2gtk)46
-rwxr-xr-xpython/subunit/filter_scripts/subunit2junitxml.py (renamed from filters/subunit2junitxml)11
-rwxr-xr-xpython/subunit/filter_scripts/subunit2pyunit.py65
-rwxr-xr-xpython/subunit/filter_scripts/subunit_1to2.py (renamed from filters/subunit-1to2)0
-rwxr-xr-xpython/subunit/filter_scripts/subunit_2to1.py (renamed from filters/subunit-2to1)0
-rwxr-xr-xpython/subunit/filter_scripts/subunit_filter.py (renamed from filters/subunit-filter)0
-rwxr-xr-xpython/subunit/filter_scripts/subunit_ls.py64
-rwxr-xr-xpython/subunit/filter_scripts/subunit_notify.py (renamed from filters/subunit-notify)11
-rwxr-xr-xpython/subunit/filter_scripts/subunit_output.py (renamed from filters/subunit-output)7
-rwxr-xr-xpython/subunit/filter_scripts/subunit_stats.py (renamed from filters/subunit-stats)18
-rwxr-xr-xpython/subunit/filter_scripts/subunit_tags.py (renamed from filters/subunit-tags)8
-rwxr-xr-xpython/subunit/filter_scripts/tap2subunit.py (renamed from filters/tap2subunit)9
-rwxr-xr-xsetup.py76
18 files changed, 251 insertions, 198 deletions
diff --git a/filters/subunit-ls b/filters/subunit-ls
deleted file mode 100755
index 8c6a1e7..0000000
--- a/filters/subunit-ls
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env python
-# subunit: extensions to python unittest to get test results from subprocesses.
-# Copyright (C) 2008 Robert Collins <robertc@robertcollins.net>
-#
-# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
-# license at the users choice. A copy of both licenses are available in the
-# project source as Apache-2.0 and BSD. You may not use this file except in
-# compliance with one of these two licences.
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# license you chose for the specific language governing permissions and
-# limitations under that license.
-#
-
-"""List tests in a subunit stream."""
-
-from optparse import OptionParser
-import sys
-
-from testtools import (
- CopyStreamResult, StreamToExtendedDecorator, StreamResultRouter,
- StreamSummary)
-
-from subunit import ByteStreamToStreamResult
-from subunit.filters import find_stream, run_tests_from_stream
-from subunit.test_results import (
- CatFiles,
- TestIdPrintingResult,
- )
-
-
-parser = OptionParser(description=__doc__)
-parser.add_option("--times", action="store_true",
- help="list the time each test took (requires a timestamped stream)",
- default=False)
-parser.add_option("--exists", action="store_true",
- help="list tests that are reported as existing (as well as ran)",
- default=False)
-parser.add_option("--no-passthrough", action="store_true",
- help="Hide all non subunit input.", default=False, dest="no_passthrough")
-(options, args) = parser.parse_args()
-test = ByteStreamToStreamResult(
- find_stream(sys.stdin, args), non_subunit_name="stdout")
-result = TestIdPrintingResult(sys.stdout, options.times, options.exists)
-if not options.no_passthrough:
- result = StreamResultRouter(result)
- cat = CatFiles(sys.stdout)
- result.add_rule(cat, 'test_id', test_id=None)
-summary = StreamSummary()
-result = CopyStreamResult([result, summary])
-result.startTestRun()
-test.run(result)
-result.stopTestRun()
-if summary.wasSuccessful():
- exit_code = 0
-else:
- exit_code = 1
-sys.exit(exit_code)
diff --git a/filters/subunit2pyunit b/filters/subunit2pyunit
deleted file mode 100755
index d10ceea..0000000
--- a/filters/subunit2pyunit
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python
-# subunit: extensions to python unittest to get test results from subprocesses.
-# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
-#
-# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
-# license at the users choice. A copy of both licenses are available in the
-# project source as Apache-2.0 and BSD. You may not use this file except in
-# compliance with one of these two licences.
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# license you chose for the specific language governing permissions and
-# limitations under that license.
-#
-
-"""Display a subunit stream through python's unittest test runner."""
-
-from operator import methodcaller
-from optparse import OptionParser
-import sys
-import unittest
-
-from testtools import StreamToExtendedDecorator, DecorateTestCaseResult, StreamResultRouter
-
-from subunit import ByteStreamToStreamResult
-from subunit.filters import find_stream
-from subunit.test_results import CatFiles
-
-parser = OptionParser(description=__doc__)
-parser.add_option("--no-passthrough", action="store_true",
- help="Hide all non subunit input.", default=False, dest="no_passthrough")
-parser.add_option("--progress", action="store_true",
- help="Use bzrlib's test reporter (requires bzrlib)",
- default=False)
-(options, args) = parser.parse_args()
-test = ByteStreamToStreamResult(
- find_stream(sys.stdin, args), non_subunit_name='stdout')
-def wrap_result(result):
- result = StreamToExtendedDecorator(result)
- if not options.no_passthrough:
- result = StreamResultRouter(result)
- result.add_rule(CatFiles(sys.stdout), 'test_id', test_id=None)
- return result
-test = DecorateTestCaseResult(test, wrap_result,
- before_run=methodcaller('startTestRun'),
- after_run=methodcaller('stopTestRun'))
-if options.progress:
- from bzrlib.tests import TextTestRunner
- from bzrlib import ui
- ui.ui_factory = ui.make_ui_for_terminal(None, sys.stdout, sys.stderr)
- runner = TextTestRunner()
-else:
- runner = unittest.TextTestRunner(verbosity=2)
-if runner.run(test).wasSuccessful():
- exit_code = 0
-else:
- exit_code = 1
-sys.exit(exit_code)
diff --git a/python/subunit/filter_scripts/__init__.py b/python/subunit/filter_scripts/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/subunit/filter_scripts/__init__.py
diff --git a/filters/subunit2csv b/python/subunit/filter_scripts/subunit2csv.py
index 4adf5cd..4802314 100755
--- a/filters/subunit2csv
+++ b/python/subunit/filter_scripts/subunit2csv.py
@@ -22,5 +22,10 @@ from subunit.filters import run_filter_script
from subunit.test_results import CsvResult
-run_filter_script(lambda output:StreamToExtendedDecorator(CsvResult(output)),
- __doc__, protocol_version=2)
+def main()
+ run_filter_script(lambda output:StreamToExtendedDecorator(
+ CsvResult(output)), __doc__, protocol_version=2)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit2disk b/python/subunit/filter_scripts/subunit2disk.py
index c1d2e1a..a674d28 100755
--- a/filters/subunit2disk
+++ b/python/subunit/filter_scripts/subunit2disk.py
@@ -19,5 +19,9 @@
from subunit._to_disk import to_disk
-if __name__ == '__main__':
+def main():
exit(to_disk())
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit2gtk b/python/subunit/filter_scripts/subunit2gtk.py
index 5c0ebe3..013b07a 100755
--- a/filters/subunit2gtk
+++ b/python/subunit/filter_scripts/subunit2gtk.py
@@ -218,23 +218,29 @@ class GTKTestResult(unittest.TestResult):
self.ok_label.set_text(str(self.testsRun - bad))
self.not_ok_label.set_text(str(bad))
-GObject.threads_init()
-result = StreamToExtendedDecorator(GTKTestResult())
-test = ByteStreamToStreamResult(sys.stdin, non_subunit_name='stdout')
-# Get setup
-while Gtk.events_pending():
- Gtk.main_iteration()
-# Start IO
-def run_and_finish():
- test.run(result)
- result.stopTestRun()
-t = threading.Thread(target=run_and_finish)
-t.daemon = True
-result.startTestRun()
-t.start()
-Gtk.main()
-if result.decorated.wasSuccessful():
- exit_code = 0
-else:
- exit_code = 1
-sys.exit(exit_code)
+
+def main():
+ GObject.threads_init()
+ result = StreamToExtendedDecorator(GTKTestResult())
+ test = ByteStreamToStreamResult(sys.stdin, non_subunit_name='stdout')
+ # Get setup
+ while Gtk.events_pending():
+ Gtk.main_iteration()
+ # Start IO
+ def run_and_finish():
+ test.run(result)
+ result.stopTestRun()
+ t = threading.Thread(target=run_and_finish)
+ t.daemon = True
+ result.startTestRun()
+ t.start()
+ Gtk.main()
+ if result.decorated.wasSuccessful():
+ exit_code = 0
+ else:
+ exit_code = 1
+ sys.exit(exit_code)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit2junitxml b/python/subunit/filter_scripts/subunit2junitxml.py
index 8e827d5..59f3c62 100755
--- a/filters/subunit2junitxml
+++ b/python/subunit/filter_scripts/subunit2junitxml.py
@@ -31,6 +31,11 @@ except ImportError:
raise
-run_filter_script(
- lambda output:StreamToExtendedDecorator(JUnitXmlResult(output)), __doc__,
- protocol_version=2)
+def main():
+ run_filter_script(
+ lambda output:StreamToExtendedDecorator(
+ JUnitXmlResult(output)), __doc__, protocol_version=2)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/python/subunit/filter_scripts/subunit2pyunit.py b/python/subunit/filter_scripts/subunit2pyunit.py
new file mode 100755
index 0000000..89b5f26
--- /dev/null
+++ b/python/subunit/filter_scripts/subunit2pyunit.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
+#
+# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
+# license at the users choice. A copy of both licenses are available in the
+# project source as Apache-2.0 and BSD. You may not use this file except in
+# compliance with one of these two licences.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# license you chose for the specific language governing permissions and
+# limitations under that license.
+#
+
+"""Display a subunit stream through python's unittest test runner."""
+
+from operator import methodcaller
+from optparse import OptionParser
+import sys
+import unittest
+
+from testtools import StreamToExtendedDecorator, DecorateTestCaseResult, StreamResultRouter
+
+from subunit import ByteStreamToStreamResult
+from subunit.filters import find_stream
+from subunit.test_results import CatFiles
+
+
+def main():
+ parser = OptionParser(description=__doc__)
+ parser.add_option("--no-passthrough", action="store_true",
+ help="Hide all non subunit input.", default=False, dest="no_passthrough")
+ parser.add_option("--progress", action="store_true",
+ help="Use bzrlib's test reporter (requires bzrlib)",
+ default=False)
+ (options, args) = parser.parse_args()
+ test = ByteStreamToStreamResult(
+ find_stream(sys.stdin, args), non_subunit_name='stdout')
+ def wrap_result(result):
+ result = StreamToExtendedDecorator(result)
+ if not options.no_passthrough:
+ result = StreamResultRouter(result)
+ result.add_rule(CatFiles(sys.stdout), 'test_id', test_id=None)
+ return result
+ test = DecorateTestCaseResult(test, wrap_result,
+ before_run=methodcaller('startTestRun'),
+ after_run=methodcaller('stopTestRun'))
+ if options.progress:
+ from bzrlib.tests import TextTestRunner
+ from bzrlib import ui
+ ui.ui_factory = ui.make_ui_for_terminal(None, sys.stdout, sys.stderr)
+ runner = TextTestRunner()
+ else:
+ runner = unittest.TextTestRunner(verbosity=2)
+ if runner.run(test).wasSuccessful():
+ exit_code = 0
+ else:
+ exit_code = 1
+ sys.exit(exit_code)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit-1to2 b/python/subunit/filter_scripts/subunit_1to2.py
index 9725820..9725820 100755
--- a/filters/subunit-1to2
+++ b/python/subunit/filter_scripts/subunit_1to2.py
diff --git a/filters/subunit-2to1 b/python/subunit/filter_scripts/subunit_2to1.py
index d358f66..d358f66 100755
--- a/filters/subunit-2to1
+++ b/python/subunit/filter_scripts/subunit_2to1.py
diff --git a/filters/subunit-filter b/python/subunit/filter_scripts/subunit_filter.py
index 7314531..7314531 100755
--- a/filters/subunit-filter
+++ b/python/subunit/filter_scripts/subunit_filter.py
diff --git a/python/subunit/filter_scripts/subunit_ls.py b/python/subunit/filter_scripts/subunit_ls.py
new file mode 100755
index 0000000..ef4c225
--- /dev/null
+++ b/python/subunit/filter_scripts/subunit_ls.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2008 Robert Collins <robertc@robertcollins.net>
+#
+# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
+# license at the users choice. A copy of both licenses are available in the
+# project source as Apache-2.0 and BSD. You may not use this file except in
+# compliance with one of these two licences.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# license you chose for the specific language governing permissions and
+# limitations under that license.
+#
+
+"""List tests in a subunit stream."""
+
+from optparse import OptionParser
+import sys
+
+from testtools import (
+ CopyStreamResult, StreamToExtendedDecorator, StreamResultRouter,
+ StreamSummary)
+
+from subunit import ByteStreamToStreamResult
+from subunit.filters import find_stream, run_tests_from_stream
+from subunit.test_results import (
+ CatFiles,
+ TestIdPrintingResult,
+ )
+
+
+def main():
+ parser = OptionParser(description=__doc__)
+ parser.add_option("--times", action="store_true",
+ help="list the time each test took (requires a timestamped stream)",
+ default=False)
+ parser.add_option("--exists", action="store_true",
+ help="list tests that are reported as existing (as well as ran)",
+ default=False)
+ parser.add_option("--no-passthrough", action="store_true",
+ help="Hide all non subunit input.", default=False, dest="no_passthrough")
+ (options, args) = parser.parse_args()
+ test = ByteStreamToStreamResult(
+ find_stream(sys.stdin, args), non_subunit_name="stdout")
+ result = TestIdPrintingResult(sys.stdout, options.times, options.exists)
+ if not options.no_passthrough:
+ result = StreamResultRouter(result)
+ cat = CatFiles(sys.stdout)
+ result.add_rule(cat, 'test_id', test_id=None)
+ summary = StreamSummary()
+ result = CopyStreamResult([result, summary])
+ result.startTestRun()
+ test.run(result)
+ result.stopTestRun()
+ if summary.wasSuccessful():
+ exit_code = 0
+ else:
+ exit_code = 1
+ sys.exit(exit_code)
+
+if __name__ = '__main__':
+ main()
diff --git a/filters/subunit-notify b/python/subunit/filter_scripts/subunit_notify.py
index 71da071..af04327 100755
--- a/filters/subunit-notify
+++ b/python/subunit/filter_scripts/subunit_notify.py
@@ -43,6 +43,11 @@ def notify_of_result(result):
nw.show()
-run_filter_script(
- lambda output:StreamToExtendedDecorator(TestResultStats(output)),
- __doc__, notify_of_result, protocol_version=2)
+def main():
+ run_filter_script(
+ lambda output:StreamToExtendedDecorator(TestResultStats(output)),
+ __doc__, notify_of_result, protocol_version=2)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit-output b/python/subunit/filter_scripts/subunit_output.py
index 61e5d11..9447ad1 100755
--- a/filters/subunit-output
+++ b/python/subunit/filter_scripts/subunit_output.py
@@ -16,8 +16,13 @@
"""A command-line tool to generate a subunit result byte-stream."""
+import sys
+
from subunit._output import output_main
+def main():
+ sys.exit(output_main()
+
if __name__ == '__main__':
- exit(output_main())
+ main()
diff --git a/filters/subunit-stats b/python/subunit/filter_scripts/subunit_stats.py
index 79733b0..a152250 100755
--- a/filters/subunit-stats
+++ b/python/subunit/filter_scripts/subunit_stats.py
@@ -24,9 +24,15 @@ from subunit import TestResultStats
from subunit.filters import run_filter_script
-result = TestResultStats(sys.stdout)
-def show_stats(r):
- r.decorated.formatStats()
-run_filter_script(
- lambda output:StreamToExtendedDecorator(result),
- __doc__, show_stats, protocol_version=2, passthrough_subunit=False)
+def main():
+ result = TestResultStats(sys.stdout)
+
+ def show_stats(r):
+ r.decorated.formatStats()
+
+ run_filter_script(
+ lambda output:StreamToExtendedDecorator(result),
+ __doc__, show_stats, protocol_version=2, passthrough_subunit=False)
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/subunit-tags b/python/subunit/filter_scripts/subunit_tags.py
index 1022492..e2b40d6 100755
--- a/filters/subunit-tags
+++ b/python/subunit/filter_scripts/subunit_tags.py
@@ -24,4 +24,10 @@ import sys
from subunit import tag_stream
-sys.exit(tag_stream(sys.stdin, sys.stdout, sys.argv[1:]))
+
+def main():
+ sys.exit(tag_stream(sys.stdin, sys.stdout, sys.argv[1:]))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/filters/tap2subunit b/python/subunit/filter_scripts/tap2subunit.py
index c571972..4263335 100755
--- a/filters/tap2subunit
+++ b/python/subunit/filter_scripts/tap2subunit.py
@@ -23,4 +23,11 @@ http://testanything.org/wiki/index.php/Main_Page.
import sys
from subunit import TAP2SubUnit
-sys.exit(TAP2SubUnit(sys.stdin, sys.stdout))
+
+
+def main():
+ sys.exit(TAP2SubUnit(sys.stdin, sys.stdout))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.py b/setup.py
index 54b1a32..b3c53a0 100755
--- a/setup.py
+++ b/setup.py
@@ -1,29 +1,6 @@
#!/usr/bin/env python
import os.path
-try:
- # If the user has setuptools / distribute installed, use it
- from setuptools import setup
-except ImportError:
- # Otherwise, fall back to distutils.
- from distutils.core import setup
- extra = {}
-else:
- extra = {
- 'install_requires': [
- 'extras',
- 'testtools>=0.9.34',
- ],
- 'tests_require': [
- 'fixtures',
- 'hypothesis',
- 'testscenarios',
- ],
- 'extras_require': {
- 'docs': ['docutils'],
- 'test': ['fixtures', 'testscenarios'],
- 'test:python_version!="3.2"': ['hypothesis'],
- },
- }
+from setuptools import setup
def _get_version_from_file(filename, start_of_line, split_marker):
@@ -63,21 +40,38 @@ setup(
url='http://launchpad.net/subunit',
packages=['subunit', 'subunit.tests'],
package_dir={'subunit': 'python/subunit'},
- scripts = [
- 'filters/subunit-1to2',
- 'filters/subunit-2to1',
- 'filters/subunit-filter',
- 'filters/subunit-ls',
- 'filters/subunit-notify',
- 'filters/subunit-output',
- 'filters/subunit-stats',
- 'filters/subunit-tags',
- 'filters/subunit2csv',
- 'filters/subunit2disk',
- 'filters/subunit2gtk',
- 'filters/subunit2junitxml',
- 'filters/subunit2pyunit',
- 'filters/tap2subunit',
- ],
- **extra
+ entry_points={
+ 'console_scripts': [
+ 'subunit-1to2=subunit.filter_scripts.subunit_1to2:main',
+ 'subunit-2to1=subunit.filter_scripts.subunit_2to1:main',
+ 'subunit-filter=subunit.filter_scripts.subunit_filter:main',
+ 'subunit-ls=subunit.filter_scripts.subunit_ls:main',
+ 'subunit-notify=subunit.filter_scripts.subunit_notify:main',
+ 'subunit-output=subunit.filter_scripts.subunit_output:main',
+ 'subunit-stats=subunit.filter_scripts.subunit_stats:main',
+ 'subunit-tags=subunit.filter_scripts.subunit_tags:main',
+ 'subunit2csv=subunit.filter_scripts.subunit2csv:main',
+ 'subunit2disk=subunit.filter_scripts.subunit2disk:main',
+ 'subunit2gtk=subunit.filter_scripts.subunit2gtk:main',
+ 'subunit2junitxml=subunit.filter_scripts.subunit2junitxml:main',
+ 'subunit2pyunit=subunit.filter_scripts.subunit2pyunit:main',
+ 'tap2subunit=subunit.filter_scripts.tap2subunit:main',
+ ]
+ },
+ extras={
+ 'install_requires': [
+ 'extras',
+ 'testtools>=0.9.34',
+ ],
+ 'tests_require': [
+ 'fixtures',
+ 'hypothesis',
+ 'testscenarios',
+ ],
+ 'extras_require': {
+ 'docs': ['docutils'],
+ 'test': ['fixtures', 'testscenarios'],
+ 'test:python_version!="3.2"': ['hypothesis'],
+ },
+ }
)