diff options
author | Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> | 2023-05-16 10:30:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 10:30:12 +0200 |
commit | 12c3d1556be3bacaf4816898616b6124e0d44da9 (patch) | |
tree | 0155475c0086e78480d38709a06796be7bd93151 /tests/test_modutils.py | |
parent | 1177accd39acffe1288d0f8fa08dbea0454035ba (diff) | |
download | astroid-git-main.tar.gz |
Recognize stub ``pyi`` Python files.
Refs pylint-dev/pylint#4987
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'tests/test_modutils.py')
-rw-r--r-- | tests/test_modutils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_modutils.py b/tests/test_modutils.py index 34f7132f..0da6ce21 100644 --- a/tests/test_modutils.py +++ b/tests/test_modutils.py @@ -287,6 +287,11 @@ class GetSourceFileTest(unittest.TestCase): def test_raise(self) -> None: self.assertRaises(modutils.NoSourceFile, modutils.get_source_file, "whatever") + def test_(self) -> None: + package = resources.find("pyi_data") + module = os.path.join(package, "__init__.pyi") + self.assertEqual(modutils.get_source_file(module), os.path.normpath(module)) + class IsStandardModuleTest(resources.SysPathSetup, unittest.TestCase): """ @@ -417,8 +422,12 @@ class ModuleInPathTest(resources.SysPathSetup, unittest.TestCase): assert modutils.module_in_path("data.module", datadir) assert modutils.module_in_path("data.module", (datadir,)) assert modutils.module_in_path("data.module", os.path.abspath(datadir)) + assert modutils.module_in_path("pyi_data.module", datadir) + assert modutils.module_in_path("pyi_data.module", (datadir,)) + assert modutils.module_in_path("pyi_data.module", os.path.abspath(datadir)) # "" will evaluate to cwd assert modutils.module_in_path("data.module", "") + assert modutils.module_in_path("pyi_data.module", "") def test_bad_import(self) -> None: datadir = resources.find("") @@ -496,6 +505,19 @@ class GetModuleFilesTest(unittest.TestCase): ] self.assertEqual(modules, {os.path.join(package, x) for x in expected}) + def test_get_module_files_2(self) -> None: + package = resources.find("pyi_data/find_test") + modules = set(modutils.get_module_files(package, [])) + expected = [ + "__init__.py", + "__init__.pyi", + "module.py", + "module2.py", + "noendingnewline.py", + "nonregr.py", + ] + self.assertEqual(modules, {os.path.join(package, x) for x in expected}) + def test_get_all_files(self) -> None: """Test that list_all returns all Python files from given location.""" non_package = resources.find("data/notamodule") |