Add support for multiple input files to runner
This commit is contained in:
parent
712ce035cf
commit
4c3065562d
@ -10,7 +10,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Implementation of a command-line runner of single Gabbi files."""
|
||||
"""Implementation of a command-line runner for gabbi files (AKA suites)."""
|
||||
|
||||
import argparse
|
||||
from importlib import import_module
|
||||
@ -88,6 +88,13 @@ def run():
|
||||
help='Custom response handler. Should be an import path of the '
|
||||
'form package.module or package.module:class.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f',
|
||||
nargs='?', default=None,
|
||||
dest='input_files',
|
||||
action='append',
|
||||
help='input files'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
host, port, prefix, force_ssl = utils.host_info_from_target(
|
||||
@ -95,9 +102,27 @@ def run():
|
||||
|
||||
handler_objects = initialize_handlers(args.response_handlers)
|
||||
|
||||
success = run_suite(sys.stdin, handler_objects, host, port, prefix,
|
||||
force_ssl, args.failfast)
|
||||
sys.exit(not success)
|
||||
input_files = args.input_files
|
||||
if input_files is None:
|
||||
input_files = [sys.stdin]
|
||||
|
||||
failfast = args.failfast
|
||||
failure = False
|
||||
for input_file in input_files:
|
||||
params = (handler_objects, host, port, prefix, force_ssl, failfast)
|
||||
# XXX(FND): special-casing; use generic stream detection instead?
|
||||
if input_file is sys.stdin:
|
||||
success = run_suite(input_file, *params)
|
||||
else: # file path
|
||||
with open(input_file, 'r') as fh:
|
||||
success = run_suite(fh, *params)
|
||||
|
||||
if not failure: # once failed, this is considered immutable
|
||||
failure = not success
|
||||
if failure and failfast:
|
||||
break
|
||||
|
||||
sys.exit(failure)
|
||||
|
||||
|
||||
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
||||
|
6
gabbi/tests/gabbits_runner/failure.yaml
Normal file
6
gabbi/tests/gabbits_runner/failure.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
tests:
|
||||
|
||||
- name: expected failure
|
||||
GET: /
|
||||
|
||||
status: 666
|
6
gabbi/tests/gabbits_runner/success.yaml
Normal file
6
gabbi/tests/gabbits_runner/success.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
tests:
|
||||
|
||||
- name: expected success
|
||||
GET: /baz
|
||||
|
||||
status: 200
|
6
gabbi/tests/gabbits_runner/success_alt.yaml
Normal file
6
gabbi/tests/gabbits_runner/success_alt.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
tests:
|
||||
|
||||
- name: expected success
|
||||
GET: /baz
|
||||
|
||||
status: 200
|
@ -56,6 +56,36 @@ class RunnerTest(unittest.TestCase):
|
||||
sys.stderr = self._stderr
|
||||
sys.argv = self._argv
|
||||
|
||||
def test_input_files(self):
|
||||
sys.argv = ['gabbi-run', 'http://%s:%s/foo' % (self.host, self.port)]
|
||||
|
||||
sys.argv.insert(1, '-f')
|
||||
sys.argv.insert(2, 'gabbi/tests/gabbits_runner/success.yaml')
|
||||
|
||||
with self.server():
|
||||
try:
|
||||
runner.run()
|
||||
except SystemExit as err:
|
||||
self.assertSuccess(err)
|
||||
|
||||
sys.argv.insert(3, '-f')
|
||||
sys.argv.insert(4, 'gabbi/tests/gabbits_runner/failure.yaml')
|
||||
|
||||
with self.server():
|
||||
try:
|
||||
runner.run()
|
||||
except SystemExit as err:
|
||||
self.assertFailure(err)
|
||||
|
||||
sys.argv.insert(5, '-f')
|
||||
sys.argv.insert(6, 'gabbi/tests/gabbits_runner/success_alt.yaml')
|
||||
|
||||
with self.server():
|
||||
try:
|
||||
runner.run()
|
||||
except SystemExit as err:
|
||||
self.assertFailure(err)
|
||||
|
||||
def test_target_url_parsing(self):
|
||||
sys.argv = ['gabbi-run', 'http://%s:%s/foo' % (self.host, self.port)]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user