]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpa/elpy-20230803.1455/elpy/tests/test_pydocutils.py
8 from unittest
import mock
12 import elpy
.pydocutils
15 class TestGetPydocCompletions(unittest
.TestCase
):
16 def test_should_return_top_level_modules(self
):
17 modules
= elpy
.pydocutils
.get_pydoc_completions("")
18 self
.assertIn('sys', modules
)
19 self
.assertIn('json', modules
)
21 def test_should_return_submodules(self
):
22 modules
= elpy
.pydocutils
.get_pydoc_completions("elpy")
23 self
.assertIn("elpy.rpc", modules
)
24 self
.assertIn("elpy.server", modules
)
25 modules
= elpy
.pydocutils
.get_pydoc_completions("os")
26 self
.assertIn("os.path", modules
)
28 def test_should_find_objects_in_module(self
):
29 self
.assertIn("elpy.tests.test_pydocutils.TestGetPydocCompletions",
30 elpy
.pydocutils
.get_pydoc_completions
31 ("elpy.tests.test_pydocutils"))
33 def test_should_find_attributes_of_objects(self
):
34 attribs
= elpy
.pydocutils
.get_pydoc_completions(
35 "elpy.tests.test_pydocutils.TestGetPydocCompletions")
36 self
.assertIn("elpy.tests.test_pydocutils.TestGetPydocCompletions."
37 "test_should_find_attributes_of_objects",
40 def test_should_return_none_for_inexisting_module(self
):
42 elpy
.pydocutils
.get_pydoc_completions
45 def test_should_work_for_unicode_strings(self
):
46 self
.assertIsNotNone(elpy
.pydocutils
.get_pydoc_completions
49 def test_should_find_partial_completions(self
):
50 self
.assertIn("multiprocessing",
51 elpy
.pydocutils
.get_pydoc_completions
53 self
.assertIn("multiprocessing.util",
54 elpy
.pydocutils
.get_pydoc_completions
55 ("multiprocessing.ut"))
57 def test_should_ignore_trailing_dot(self
):
58 self
.assertIn("elpy.pydocutils",
59 elpy
.pydocutils
.get_pydoc_completions
63 class TestGetModules(unittest
.TestCase
):
64 def test_should_return_top_level_modules(self
):
65 modules
= elpy
.pydocutils
.get_modules()
66 self
.assertIn('sys', modules
)
67 self
.assertIn('json', modules
)
69 def test_should_return_submodules(self
):
70 modules
= elpy
.pydocutils
.get_modules("elpy")
71 self
.assertIn("rpc", modules
)
72 self
.assertIn("server", modules
)
74 @mock.patch
.object(elpy
.pydocutils
, 'safeimport')
75 def test_should_catch_import_errors(self
, safeimport
):
76 def raise_function(message
):
77 raise elpy
.pydocutils
.ErrorDuringImport(message
,
79 safeimport
.side_effect
= raise_function
80 self
.assertEqual([], elpy
.pydocutils
.get_modules("foo.bar"))
82 def test_should_not_fail_for_permission_denied(self
):
83 tmpdir
= tempfile
.mkdtemp(prefix
="test-elpy-get-modules-")
84 sys
.path
.append(tmpdir
)
85 os
.chmod(tmpdir
, 0o000)
87 elpy
.pydocutils
.get_modules()
89 os
.chmod(tmpdir
, 0o755)
91 sys
.path
.remove(tmpdir
)