bootstrap-vz/tests/integration/tools_tests.py
Anders Ingemann 6302d5d962 Fix log_call test to not give random outcomes.
We shouldn't play around with the carriage return char,
seems like using that together with readline gives undefined results (wrt ordering).
2014-05-04 15:01:45 +02:00

40 lines
1,010 B
Python

import os
from nose.tools import eq_
from bootstrapvz.common.tools import log_call
subprocess_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'subprocess.sh')
def setup_logger():
import logging
root = logging.getLogger()
root.setLevel(logging.NOTSET)
import StringIO
output = StringIO.StringIO()
string_handler = logging.StreamHandler(output)
string_handler.setLevel(logging.DEBUG)
root.addHandler(string_handler)
return output
def test_log_call_output_order():
logged = setup_logger()
fixture = """
2 0.00 one\\\\n
1 0.02 two\\\\n
1 0.02 four\\\\n
2 0.02 No, three..\\\\n
1 0.02 three\\\\n
"""
status, stdout, stderr = log_call([subprocess_path], stdin=fixture)
eq_(status, 0)
eq_(stderr, ['one', 'No, three..'])
eq_(stdout, ['two', 'four', 'three'])
expected_order = ['one',
'two',
'four',
'No, three..',
'three',
]
eq_(expected_order, logged.getvalue().split("\n")[8:-1])