MCPcopy Index your code
hub / github.com/python/cpython / test_source_synopsis

Method test_source_synopsis

Lib/test/test_pydoc/test_pydoc.py:928–1002  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

926 self.assertEqual(synopsis, 'line 1: h\xe9')
927
928 def test_source_synopsis(self):
929 def check(source, expected, encoding=None):
930 if isinstance(source, str):
931 source_file = StringIO(source)
932 else:
933 source_file = io.TextIOWrapper(io.BytesIO(source), encoding=encoding)
934 with source_file:
935 result = pydoc.source_synopsis(source_file)
936 self.assertEqual(result, expected)
937
938 check('"""Single line docstring."""',
939 'Single line docstring.')
940 check('"""First line of docstring.\nSecond line.\nThird line."""',
941 'First line of docstring.')
942 check('"""First line of docstring.\\nSecond line.\\nThird line."""',
943 'First line of docstring.')
944 check('""" Whitespace around docstring. """',
945 'Whitespace around docstring.')
946 check('import sys\n"""No docstring"""',
947 None)
948 check(' \n"""Docstring after empty line."""',
949 'Docstring after empty line.')
950 check('# Comment\n"""Docstring after comment."""',
951 'Docstring after comment.')
952 check(' # Indented comment\n"""Docstring after comment."""',
953 'Docstring after comment.')
954 check('""""""', # Empty docstring
955 '')
956 check('', # Empty file
957 None)
958 check('"""Embedded\0null byte"""',
959 None)
960 check('"""Embedded null byte"""\0',
961 None)
962 check('"""Café and résumé."""',
963 'Café and résumé.')
964 check("'''Triple single quotes'''",
965 'Triple single quotes')
966 check('"Single double quotes"',
967 'Single double quotes')
968 check("'Single single quotes'",
969 'Single single quotes')
970 check('"""split\\\nline"""',
971 'splitline')
972 check('"""Unrecognized escape \\sequence"""',
973 'Unrecognized escape \\sequence')
974 check('"""Invalid escape seq\\uence"""',
975 None)
976 check('r"""Raw \\stri\\ng"""',
977 'Raw \\stri\\ng')
978 check('b"""Bytes literal"""',
979 None)
980 check('f"""f-string"""',
981 None)
982 check('"""Concatenated""" \\\n"string" \'literals\'',
983 'Concatenatedstringliterals')
984 check('"""String""" + """expression"""',
985 None)

Callers

nothing calls this directly

Calls 5

checkFunction · 0.50
writeMethod · 0.45
flushMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected