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.
This commit is contained in:
59
gabbi/runner.py
Normal file
59
gabbi/runner.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright 2014, 2015 Red Hat
|
||||
#
|
||||
# Authors: Chris Dent <chdent@redhat.com>
|
||||
#
|
||||
# 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()
|
Reference in New Issue
Block a user