test_absolute_import.py 861 B

1234567891011121314151617181920212223242526272829
  1. """
  2. Tests ``from __future__ import absolute_import`` (only important for
  3. Python 2.X)
  4. """
  5. from parso import parse
  6. def test_explicit_absolute_imports():
  7. """
  8. Detect modules with ``from __future__ import absolute_import``.
  9. """
  10. module = parse("from __future__ import absolute_import")
  11. assert module._has_explicit_absolute_import()
  12. def test_no_explicit_absolute_imports():
  13. """
  14. Detect modules without ``from __future__ import absolute_import``.
  15. """
  16. assert not parse("1")._has_explicit_absolute_import()
  17. def test_dont_break_imports_without_namespaces():
  18. """
  19. The code checking for ``from __future__ import absolute_import`` shouldn't
  20. assume that all imports have non-``None`` namespaces.
  21. """
  22. src = "from __future__ import absolute_import\nimport xyzzy"
  23. assert parse(src)._has_explicit_absolute_import()