@@ -934,6 +934,60 @@ def test_format_docstring_for_one_line_summary_alone_but_too_long(
934934 )
935935 )
936936
937+ @pytest .mark .unit
938+ @pytest .mark .parametrize ("args" , [["" ]])
939+ def test_format_docstring_with_class_attributes (self , test_args , args ):
940+ """Wrap long class attribute docstrings."""
941+ uut = Formatter (
942+ test_args ,
943+ sys .stderr ,
944+ sys .stdin ,
945+ sys .stdout ,
946+ )
947+
948+ docstring = '''\
949+ class TestClass:
950+ """This is a class docstring."""
951+
952+ test_int = 1
953+ """This is a very, very, very long docstring that should really be
954+ reformatted nicely by docformatter."""
955+ '''
956+ assert docstring == uut ._do_format_code (
957+ '''\
958+ class TestClass:
959+ """This is a class docstring."""
960+
961+ test_int = 1
962+ """This is a very, very, very long docstring that should really be reformatted nicely by docformatter."""
963+ '''
964+ )
965+
966+ @pytest .mark .unit
967+ @pytest .mark .parametrize ("args" , [["" ]])
968+ def test_format_docstring_no_newline_in_summary_with_symbol (self , test_args , args ):
969+ """Wrap summary with symbol should not add newline.
970+
971+ See issue #79.
972+ """
973+ uut = Formatter (
974+ test_args ,
975+ sys .stderr ,
976+ sys .stdin ,
977+ sys .stdout ,
978+ )
979+
980+ docstring = '''\
981+ def function2():
982+ """Hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet
983+ -v."""
984+ '''
985+ assert docstring == uut ._do_format_code (docstring )
986+
987+
988+ class TestFormatWrapURL :
989+ """Class for testing _do_format_docstring() with line wrapping and URLs."""
990+
937991 @pytest .mark .unit
938992 @pytest .mark .parametrize (
939993 "args" ,
@@ -1472,8 +1526,11 @@ def test_format_docstring_with_short_anonymous_link(self, test_args, args):
14721526
14731527 @pytest .mark .unit
14741528 @pytest .mark .parametrize ("args" , [["" ]])
1475- def test_format_docstring_with_class_attributes (self , test_args , args ):
1476- """Wrap long class attribute docstrings."""
1529+ def test_format_docstring_with_quoted_link (self , test_args , args ):
1530+ """Anonymous link references should not be wrapped into the link.
1531+
1532+ See issue #218.
1533+ """
14771534 uut = Formatter (
14781535 test_args ,
14791536 sys .stderr ,
@@ -1482,43 +1539,32 @@ def test_format_docstring_with_class_attributes(self, test_args, args):
14821539 )
14831540
14841541 docstring = '''\
1485- class TestClass:
1486- """This is a class docstring."""
1542+ """Construct a candidate project URL from the bundle and app name.
14871543
1488- test_int = 1
1489- """This is a very, very, very long docstring that should really be
1490- reformatted nicely by docformatter."""
1544+ It's not a perfect guess, but it's better than having
1545+ "https://example.com".
1546+
1547+ :param bundle: The bundle identifier.
1548+ :param app_name: The app name.
1549+ :returns: The candidate project URL
1550+ """
14911551'''
14921552 assert docstring == uut ._do_format_code (
14931553 '''\
1494- class TestClass:
1495- """This is a class docstring."""
1554+ """Construct a candidate project URL from the bundle and app name.
14961555
1497- test_int = 1
1498- """This is a very, very, very long docstring that should really be reformatted nicely by docformatter."""
1556+ It's not a perfect guess, but it's better than having "https://example.com".
1557+
1558+ :param bundle: The bundle identifier.
1559+ :param app_name: The app name.
1560+ :returns: The candidate project URL
1561+ """
14991562'''
15001563 )
15011564
1502- @pytest .mark .unit
1503- @pytest .mark .parametrize ("args" , [["" ]])
1504- def test_format_docstring_no_newline_in_summary_with_symbol (self , test_args , args ):
1505- """Wrap summary with symbol should not add newline.
15061565
1507- See issue #79.
1508- """
1509- uut = Formatter (
1510- test_args ,
1511- sys .stderr ,
1512- sys .stdin ,
1513- sys .stdout ,
1514- )
1515-
1516- docstring = '''\
1517- def function2():
1518- """Hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet
1519- -v."""
1520- '''
1521- assert docstring == uut ._do_format_code (docstring )
1566+ class TestFormatWrapBlack :
1567+ """Class for testing _do_format_docstring() with line wrapping and black option."""
15221568
15231569 @pytest .mark .unit
15241570 @pytest .mark .parametrize (
@@ -1585,6 +1631,10 @@ def test_format_docstring_black(
15851631 )
15861632 )
15871633
1634+
1635+ class TestFormatWrapEpytext :
1636+ """Class for testing _do_format_docstring() with line wrapping and Epytext lists."""
1637+
15881638 @pytest .mark .unit
15891639 @pytest .mark .parametrize (
15901640 "args" ,
@@ -1720,6 +1770,10 @@ def test_format_docstring_non_epytext_style(
17201770 )
17211771 )
17221772
1773+
1774+ class TestFormatWrapSphinx :
1775+ """Class for testing _do_format_docstring() with line wrapping and Sphinx lists."""
1776+
17231777 @pytest .mark .unit
17241778 @pytest .mark .parametrize (
17251779 "args" ,
@@ -1857,6 +1911,118 @@ def test_format_docstring_non_sphinx_style(
18571911 )
18581912 )
18591913
1914+ @pytest .mark .unit
1915+ @pytest .mark .parametrize (
1916+ "args" ,
1917+ [
1918+ [
1919+ "--wrap-descriptions" ,
1920+ "88" ,
1921+ "--wrap-summaries" ,
1922+ "88" ,
1923+ "" ,
1924+ ]
1925+ ],
1926+ )
1927+ def test_format_docstring_sphinx_style_remove_excess_whitespace (
1928+ self ,
1929+ test_args ,
1930+ args ,
1931+ ):
1932+ """Should remove unneeded whitespace.
1933+
1934+ See issue #217
1935+ """
1936+ uut = Formatter (
1937+ test_args ,
1938+ sys .stderr ,
1939+ sys .stdin ,
1940+ sys .stdout ,
1941+ )
1942+
1943+ assert (
1944+ (
1945+ '''\
1946+ """Base for all Commands.
1947+
1948+ :param logger: Logger for console and logfile.
1949+ :param console: Facilitates console interaction and input solicitation.
1950+ :param tools: Cache of tools populated by Commands as they are required.
1951+ :param apps: Dictionary of project's Apps keyed by app name.
1952+ :param base_path: Base directory for Briefcase project.
1953+ :param data_path: Base directory for Briefcase tools, support packages, etc.
1954+ :param is_clone: Flag that Command was triggered by the user's requested Command;
1955+ for instance, RunCommand can invoke UpdateCommand and/or BuildCommand.
1956+ """\
1957+ '''
1958+ )
1959+ == uut ._do_format_docstring (
1960+ INDENTATION ,
1961+ '''\
1962+ """Base for all Commands.
1963+
1964+ :param logger: Logger for console and logfile.
1965+ :param console: Facilitates console interaction and input solicitation.
1966+ :param tools: Cache of tools populated by Commands as they are required.
1967+ :param apps: Dictionary of project's Apps keyed by app name.
1968+ :param base_path: Base directory for Briefcase project.
1969+ :param data_path: Base directory for Briefcase tools, support packages, etc.
1970+ :param is_clone: Flag that Command was triggered by the user's requested Command;
1971+ for instance, RunCommand can invoke UpdateCommand and/or BuildCommand.
1972+ """\
1973+ ''' ,
1974+ )
1975+ )
1976+
1977+ @pytest .mark .unit
1978+ @pytest .mark .parametrize (
1979+ "args" ,
1980+ [
1981+ [
1982+ "--wrap-descriptions" ,
1983+ "88" ,
1984+ "--wrap-summaries" ,
1985+ "88" ,
1986+ "" ,
1987+ ]
1988+ ],
1989+ )
1990+ def test_format_docstring_sphinx_style_two_directives_in_row (
1991+ self ,
1992+ test_args ,
1993+ args ,
1994+ ):
1995+ """Should remove unneeded whitespace.
1996+
1997+ See issue #215.
1998+ """
1999+ uut = Formatter (
2000+ test_args ,
2001+ sys .stderr ,
2002+ sys .stdin ,
2003+ sys .stdout ,
2004+ )
2005+
2006+ assert (
2007+ (
2008+ '''\
2009+ """Create or return existing HTTP session.
2010+
2011+ :return: Requests :class:`~requests.Session` object
2012+ """\
2013+ '''
2014+ )
2015+ == uut ._do_format_docstring (
2016+ INDENTATION ,
2017+ '''\
2018+ """Create or return existing HTTP session.
2019+
2020+ :return: Requests :class:`~requests.Session` object
2021+ """\
2022+ ''' ,
2023+ )
2024+ )
2025+
18602026
18612027class TestFormatStyleOptions :
18622028 """Class for testing format_docstring() when requesting style options."""
0 commit comments