Home - Summaries: (main) : (py3.11) : Everything - Nightly builds - Benchmarks - RPython - Builders - About

pypy/interpreter/astcompiler/test/test_astbuilder.py::TestAstBuilding::()::test_from_import

self = <pypy.interpreter.astcompiler.test.test_astbuilder.TestAstBuilding instance at 0x7efffa80da00>

    def test_from_import(self):
        im = self.get_first_stmt("from x import y")
        assert isinstance(im, ast.ImportFrom)
        assert im.module == "x"
        assert im.level == 0
        assert len(im.names) == 1
        a = im.names[0]
        assert isinstance(a, ast.alias)
        assert a.name == "y"
        assert a.asname is None
        im = self.get_first_stmt("from . import y")
        assert im.level == 1
        assert im.module is None
        im = self.get_first_stmt("from ... import y")
        assert im.level == 3
        assert im.module is None
        im = self.get_first_stmt("from .x import y")
        assert im.level == 1
        assert im.module == "x"
        im = self.get_first_stmt("from ..x.y import m")
        assert im.level == 2
        assert im.module == "x.y"
        im = self.get_first_stmt("from x import *")
        assert len(im.names) == 1
        a = im.names[0]
        assert a.name == "*"
        assert a.asname is None
        for input in ("from x import x, y", "from x import (x, y)"):
            im = self.get_first_stmt(input)
            assert len(im.names) == 2
            a1, a2 = im.names
            assert a1.name == "x"
            assert a1.asname is None
            assert a2.name == "y"
            assert a2.asname is None
        for input in ("from x import a as b, w", "from x import (a as b, w)"):
            im = self.get_first_stmt(input)
            assert len(im.names) == 2
            a1, a2 = im.names
            assert a1.name == "a"
            assert a1.asname == "b"
            assert a2.name == "w"
            assert a2.asname is None
    
        input = "from x import y a b"
        with pytest.raises(SyntaxError) as excinfo:
            self.get_ast(input)
>       assert excinfo.value.text == input + "\n"
E       assert 'from x import y a b' == 'from x import y a b\n'
E           from x import y a b

interpreter/astcompiler/test/test_astbuilder.py:200: AssertionError
builder: own-linux-x86-64 build #10877+
test: pypy/interpreter/astcompiler/test/test_astbuilder.py::TestAstBuilding::()::test_from_import