rally/tests/test_utils.py
ekonstantinov 1888c3d2cf Init benchmark framework
We add rally.benchmark module that contains Tester.
This is base of our benchmark framework. It allows us to easy write
test scenarios that could call any test N times simuntaneously and collect results

Add rally.utils stdout captures that allows us to caputre stdout and stderr in easy
way using "with" expression.

Add test for our benchmark base and rally.utils
2013-09-01 01:28:51 +04:00

49 lines
1.5 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
# 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.
"""Test for Rally utils."""
from __future__ import print_function
import sys
from rally import test
from rally import utils
class StdIOCaptureTestCase(test.NoDBTestCase):
def test_stdout_capture(self):
stdout = sys.stdout
messages = ['abcdef', 'defgaga']
with utils.StdOutCapture() as out:
for msg in messages:
print(msg)
self.assertEqual(out.getvalue().rstrip('\n').split('\n'), messages)
self.assertEqual(stdout, sys.stdout)
def test_stderr_capture(self):
stderr = sys.stderr
messages = ['abcdef', 'defgaga']
with utils.StdErrCapture() as err:
for msg in messages:
print(msg, file=sys.stderr)
self.assertEqual(err.getvalue().rstrip('\n').split('\n'), messages)
self.assertEqual(stderr, sys.stderr)