示例#1
0
def test_parse_spec():
    p = sys.path

    assert parse_spec("dataclasses") == "dataclasses"
    assert sys.path == p

    assert parse_spec(here / "testdata" / "demo.py") == "demo"
    assert str(here / "testdata") in sys.path
    sys.path = p

    assert (parse_spec(here / "testdata" / "demopackage" /
                       "_child.py") == "demopackage._child")
    assert str(here / "testdata") in sys.path
    sys.path = p
示例#2
0
def test_parse_spec_mod_and_dir(capsys, tmp_path, monkeypatch):
    """Test that we display a warning when both a module and a local directory exist with the provided name."""
    (tmp_path / "dataclasses").mkdir()
    (tmp_path / "dataclasses" / "__init__.py").touch()
    monkeypatch.chdir(tmp_path)

    assert parse_spec("dataclasses") == "dataclasses"
    captured = capsys.readouterr()
    assert captured.out.startswith(
        "Warning: 'dataclasses' may refer to either the installed Python module or the local file/directory"
    )

    monkeypatch.chdir(here / "testdata")
    assert parse_spec("demo.py") == "demo"
    captured = capsys.readouterr()
    assert not captured.out
示例#3
0
def test_all_with_import_err():
    mod = extract.load_module(extract.parse_spec(here / "import_err"))
    m = Module(mod)
    with pytest.warns(
            RuntimeWarning,
            match=
            "Found 'err' in test.import_err.__all__, but it does not resolve: Error importing test.import_err",
    ):
        assert m.members
示例#4
0
def test_attrs():
    mod = extract.load_module(
        extract.parse_spec(here / "testdata" / "demo_long.py"))

    m = Module(mod)
    assert m.variables
    assert m.classes
    assert m.functions

    c = m.members["Foo"]
    assert isinstance(c, Class)
    assert c.class_variables
    assert c.instance_variables
    assert c.classmethods
    assert c.staticmethods
    assert c.methods