aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/parso/py2/tests/test_absolute_import.py
blob: c959ea5340611544055bde0ae5979c974ad9a938 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Tests ``from __future__ import absolute_import`` (only important for
Python 2.X)
"""
from parso import parse


def test_explicit_absolute_imports():
    """
    Detect modules with ``from __future__ import absolute_import``.
    """
    module = parse("from __future__ import absolute_import")
    assert module._has_explicit_absolute_import()


def test_no_explicit_absolute_imports():
    """
     Detect modules without ``from __future__ import absolute_import``.
    """
    assert not parse("1")._has_explicit_absolute_import()


def test_dont_break_imports_without_namespaces():
    """
    The code checking for ``from __future__ import absolute_import`` shouldn't
    assume that all imports have non-``None`` namespaces.
    """
    src = "from __future__ import absolute_import\nimport xyzzy"
    assert parse(src)._has_explicit_absolute_import()