Example #1
0
 def run(self, input_, timeout=None, get_pty=False):
     with self.execute(timeout=timeout,
                       get_pty=get_pty) as (in_, out, err):
         if input_:
             in_.write(input_)
             in_.close()
         self.out = normalize_string(out.read())
         self.err = normalize_string(err.read())
     return self.rc, self.out, self.err
Example #2
0
def test_normalize_string_unicode_input():
    """
    Test 'normalize_string' function with 'unicode' input (PY2 only)

    In python2 unicode input should not be converted
    'unicode' is not supported at python3
    """
    if six.PY2:
        assert type(common.normalize_string(data=unicode())  # noqa: F821
                    ) == unicode  # noqa: F821
Example #3
0
def test_normalize_string_bytes_input():
    """
    Test 'normalize_string' function with 'bytes' input

    In python3 we want to convert bytes() to str(),
        to eliminate TypeError exception when mixing between bytes & str
        at the calling function
    In python2 there is no meaning if the output will by bytes() or str()
        python will not raise a TypeError exception when mixing between them
    """
    if six.PY3:
        assert type(common.normalize_string(data=bytes())) == str
Example #4
0
def test_normalize_string_str_input():
    """
    Test 'normalize_string' function with 'str' input

    Keep the str type in python3
    Convert the str type to unicode in python2
    """
    try:
        expected_type = unicode  # Python2
    except NameError:
        expected_type = str  # Python3

    assert type(common.normalize_string(data=str())) == expected_type