From 2018b00eafdc6b4e7916f0af53aba5365e9c4bae Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 15 Apr 2015 12:55:56 +0100 Subject: [PATCH] Add a command line to to run yaml-tests from stdin. A console-script reads stdin and generates a TestSuite to be run. This can be used as a nice way to test running services without any test-building-in-python requirements. --- gabbi/runner.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 4 ++++ 2 files changed, 63 insertions(+) create mode 100644 gabbi/runner.py diff --git a/gabbi/runner.py b/gabbi/runner.py new file mode 100644 index 0000000..8ed5798 --- /dev/null +++ b/gabbi/runner.py @@ -0,0 +1,59 @@ +# Copyright 2014, 2015 Red Hat +# +# Authors: Chris Dent +# +# 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. + +import sys +import yaml +import unittest + +from . import driver + + +def run(): + """Run simple tests from STDIN. + + This command provides a way to run a set of tests encoded in YAML that + is provided on STDIN. No fixtures are supported, so this is primarily + designed for use with real running services. + + Host and port information may be provided in two different ways: + + * In the URL value of the tests. + * In a `host` or `host:port` argument on the command line. + + An example run might looks like this:: + + gabbi-run example.com:9999 < mytest.yaml + + Output is formatted as unittest summary information. + """ + try: + hostport = sys.argv[1] + if ':' in hostport: + host, port = hostport.split(':') + else: + host = hostport + port = None + except IndexError: + host, port = 'stub', None + loader = unittest.defaultTestLoader + data = yaml.safe_load(sys.stdin.read()) + suite = driver.test_suite_from_yaml(loader, 'input', data, '.', + host, port, None, None) + unittest.TextTestRunner(verbosity=2).run(suite) + + +if __name__ == '__main__': + run() diff --git a/setup.cfg b/setup.cfg index bc48de0..1b218ba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,3 +29,7 @@ packages = all_files = 1 build-dir = docs/build source-dir = docs/source + +[entry_points] +console_scripts = + gabbi-run = gabbi.runner:run