Ejemplo n.º 1
0
def truncate_string(data,
                    headers,
                    max_field_width=None,
                    skip_multiline_string=True,
                    **_):
    """Truncate very long strings. Only needed for tabular
    representation, because trying to tabulate very long data
    is problematic in terms of performance, and does not make any
    sense visually.

    :param iterable data: An :term:`iterable` (e.g. list) of rows.
    :param iterable headers: The column headers.
    :param int max_field_width: Width to truncate field for display
    :return: The processed data and headers.
    :rtype: tuple
    """
    return (
        ([
            utils.truncate_string(v, max_field_width, skip_multiline_string)
            for v in row
        ] for row in data),
        [
            utils.truncate_string(h, max_field_width, skip_multiline_string)
            for h in headers
        ],
    )
Ejemplo n.º 2
0
def test_truncate_string():
    """Test string truncate preprocessor."""
    val = 'x' * 100
    assert utils.truncate_string(val, 10) == 'x' * 10

    val = 'x' * 100
    assert utils.truncate_string(val) == 'x' * 100

    val = ['x'] * 100
    val[20] = '\n'
    str_val = ''.join(val)
    assert utils.truncate_string(str_val, 10, skip_multiline_string=True) == str_val
Ejemplo n.º 3
0
def test_truncate_string():
    """Test string truncate preprocessor."""
    val = "x" * 100
    assert utils.truncate_string(val, 10) == "xxxxxxx..."

    val = "x " * 100
    assert utils.truncate_string(val, 10) == "x x x x..."

    val = "x" * 100
    assert utils.truncate_string(val) == "x" * 100

    val = ["x"] * 100
    val[20] = "\n"
    str_val = "".join(val)
    assert utils.truncate_string(str_val, 10,
                                 skip_multiline_string=True) == str_val
Ejemplo n.º 4
0
def test_truncate_string():
    """Test string truncate preprocessor."""
    val = 'x' * 1000
    assert utils.truncate_string(val, 10) == 'x' * 10