From d32045303fd82f423afd943e423615e8bce97063 Mon Sep 17 00:00:00 2001 From: Laurens Van Houtven <_@lvh.cc> Date: Fri, 21 Jun 2013 19:25:18 +0200 Subject: [PATCH] Add absolute_import failing SSCCE, and get pytest to ignore it --- pytest.ini | 2 +- test/absolute_import/local_module.py | 13 +++++++++++++ test/absolute_import/minimal_demo.py | 9 +++++++++ test/absolute_import/unittest.py | 13 +++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/absolute_import/local_module.py create mode 100644 test/absolute_import/minimal_demo.py create mode 100644 test/absolute_import/unittest.py diff --git a/pytest.ini b/pytest.ini index b393f082..ab58a87e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,7 +2,7 @@ addopts = --doctest-modules # Ignore broken files in blackbox test directories -norecursedirs = .* docs completion refactor +norecursedirs = .* docs completion refactor absolute_import # Activate `clean_jedi_cache` fixture for all tests. This should be # fine as long as we are using `clean_jedi_cache` as a session scoped diff --git a/test/absolute_import/local_module.py b/test/absolute_import/local_module.py new file mode 100644 index 00000000..0064586e --- /dev/null +++ b/test/absolute_import/local_module.py @@ -0,0 +1,13 @@ +""" +This is a module that imports the *standard library* unittest, +despite there being a local "unittest" module. It specifies that it +wants the stdlib one with the ``absolute_import`` __future__ import. + +The twisted equivalent of this module is ``twisted.trial._synctest``. +""" +from __future__ import absolute_import + +import unittest # this is stdlib unittest, but jedi gets the local one + +class Assertions(unittest.TestCase): + pass diff --git a/test/absolute_import/minimal_demo.py b/test/absolute_import/minimal_demo.py new file mode 100644 index 00000000..6231e62a --- /dev/null +++ b/test/absolute_import/minimal_demo.py @@ -0,0 +1,9 @@ +import jedi + +filename = "unittest.py" +with open(filename) as f: + lines = f.readlines() +src = "".join(lines) +script = jedi.Script(src, len(lines), len(lines[1]), filename) + +print script.completions() diff --git a/test/absolute_import/unittest.py b/test/absolute_import/unittest.py new file mode 100644 index 00000000..d8957afc --- /dev/null +++ b/test/absolute_import/unittest.py @@ -0,0 +1,13 @@ +""" +This is a module that shadows a builtin (intentionally). + +It imports a local module, which in turn imports stdlib unittest (the +name shadowed by this module). If that is properly resolved, there's +no problem. However, if jedi doesn't understand absolute_imports, it +will get this module again, causing infinite recursion. +""" +from local_module import Assertions + +class TestCase(Assertions): + def test(self): + self.assertT