문제

I'm trying to keep my source code under the 80 character guideline width that PEP8 recommends, but can't figure out how to wrap my doctest which has results longer than 80 characters.

A noddy example:

def long_string():
    """
    Returns a string which is wider than the recommended PEP8 linewidth

    >>> print long_string()
    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

    """
    return '0123456789' * 10

I've tried a couple of combinations, including using # doctest: +NORMALIZE_WHITESPACE and trying to simply wrap the line with a newline.

도움이 되었습니까?

해결책

Just figured out:

def long_string():
    """
    Returns a string which is wider than the recommended PEP8 linewidth

    >>> print long_string()
    01234567890123456789012345678901234567890123456789012345678901234567890\
12345678901234567890123456789

    """
    return '0123456789' * 10

Hope that helps somebody else out.

다른 팁

As suggested by davitenio and qris, I would recommend using the #doctest: +ELLIPSIS directive, like so.

>>> from test.test_ppp import MockForm
>>> form = MockForm(mock_file='no-errors.xlsx')
>>> form.get_languages(settings_default='English', survey_header=
... form.metadata['raw_data']['survey'][0])  #doctest: +ELLIPSIS
['Ateso', 'English', 'Luganda', ... 'Runyoro-Rutoro']
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top