From 07ba6658dd3ecd539f344ad5cc7ad17c53ab5eb0 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 16 Mar 2013 20:37:12 +0100 Subject: [PATCH] Add test_no_duplicate_modules --- test/test_regression.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test_regression.py b/test/test_regression.py index d71dec1a..201ca063 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -537,5 +537,41 @@ def test_settings_module(): assert cache.settings is settings +def test_no_duplicate_modules(): + """ + Make sure that import hack works as expected. + + Jedi does an import hack (see: jedi/__init__.py) to have submodules + with circular dependencies. The modules in this circular dependency + "loop" must be imported by ``import `` rather than normal + ``from jedi import `` (or ``from . jedi ...``). This test + make sure that this is satisfied. + + See also: + + - `#160 `_ + - `#161 `_ + """ + import sys + jedipath = os.path.dirname(os.path.abspath(jedi.__file__)) + + def is_submodule(m): + try: + filepath = m.__file__ + except AttributeError: + return False + return os.path.abspath(filepath).startswith(jedipath) + + modules = list(filter(is_submodule, sys.modules.values())) + top_modules = [m for m in modules if not m.__name__.startswith('jedi.')] + for m in modules: + for tm in top_modules: + try: + imported = getattr(m, tm.__name__) + except AttributeError: + continue + assert imported is tm + + if __name__ == '__main__': unittest.main()