我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用pydoc.synopsis()。
def test_synopsis(self): self.addCleanup(unlink, TESTFN) for encoding in ('ISO-8859-1', 'UTF-8'): with open(TESTFN, 'w', encoding=encoding) as script: if encoding != 'UTF-8': print('#coding: {}'.format(encoding), file=script) print('"""line 1: h\xe9', file=script) print('line 2: hi"""', file=script) synopsis = pydoc.synopsis(TESTFN, {}) self.assertEqual(synopsis, 'line 1: h\xe9')
def test_synopsis(self): with test.test_support.temp_cwd() as test_dir: init_path = os.path.join(test_dir, 'dt.py') with open(init_path, 'w') as fobj: fobj.write('''\ """ my doc second line """ foo = 1 ''') py_compile.compile(init_path) synopsis = pydoc.synopsis(init_path, {}) self.assertEqual(synopsis, 'my doc')
def test_synopsis_sourceless_empty_doc(self): with test.test_support.temp_cwd() as test_dir: init_path = os.path.join(test_dir, 'foomod42.py') cached_path = os.path.join(test_dir, 'foomod42.pyc') with open(init_path, 'w') as fobj: fobj.write("foo = 1") py_compile.compile(init_path) synopsis = pydoc.synopsis(init_path, {}) self.assertIsNone(synopsis) synopsis_cached = pydoc.synopsis(cached_path, {}) self.assertIsNone(synopsis_cached)
def test_synopsis_sourceless(self): expected = os.__doc__.splitlines()[0] filename = os.__cached__ synopsis = pydoc.synopsis(filename) self.assertEqual(synopsis, expected)
def test_synopsis_sourceless_empty_doc(self): with test.support.temp_cwd() as test_dir: init_path = os.path.join(test_dir, 'foomod42.py') cached_path = importlib.util.cache_from_source(init_path) with open(init_path, 'w') as fobj: fobj.write("foo = 1") py_compile.compile(init_path) synopsis = pydoc.synopsis(init_path, {}) self.assertIsNone(synopsis) synopsis_cached = pydoc.synopsis(cached_path, {}) self.assertIsNone(synopsis_cached)