Esempio n. 1
0
def test_modulename_conversion():
    assert Module.modulename_to_filename("foo.bar.baz") == "foo/bar/baz.py"
    assert Module.modulename_to_filename("foo.bar") == "foo/bar.py"
    assert Module.modulename_to_filename("foo") == "foo.py"

    with pytest.raises(AssertionError):
        assert Module.modulename_to_filename("")
Esempio n. 2
0
def test_folding():
    module = Module("/foo/bar", "baz/boo.py")
    module = module.fold("/foo/bar/baz")
    assert module.filepath == "/foo/bar/baz/boo.py"
    assert module.filename == "baz/boo.py"
    assert module.virtual_filename == "boo.py"
    assert module.virtual_diff == "baz"

    with pytest.raises(AssertionError):
        Module("/foo/bar", "baz/boo.py").fold("baz")
Esempio n. 3
0
def test_up_by():
    module = Module("/", "foo/bar/baz.py")
    assert module.up_by(1).qualified_name == "foo.bar"
    assert module.up_by(2).qualified_name == "foo"

    module = Module("/foo", "sub/bar/baz.py")
    module = module.fold("/foo/sub")
    module = module.up_by(1)
    assert module.qualified_name == "bar"
    assert module.filepath == "/foo/sub/bar"
    assert module.filename == "sub/bar"
    assert module.virtual_filename == "bar"
Esempio n. 4
0
def test_relative_ref():
    module = Module("/", "foo.py").relative_ref("os.path")
    assert module.root == "/"
    assert module.qualified_name == "foo.os.path"
    assert module.filepath == "/foo/os/path.py"
    assert module.filename == "foo/os/path.py"
    assert module.virtual_filename is None
    assert module.virtual_diff is None

    module = Module("/", "foo/bar.py").relative_ref("os.path")
    assert module.root == "/"
    assert module.qualified_name == "foo.bar.os.path"
    assert module.filepath == "/foo/bar/os/path.py"
    assert module.filename == "foo/bar/os/path.py"
    assert module.virtual_filename is None
    assert module.virtual_diff is None

    module = Module("/", "foo/bar").relative_ref("os.path")
    assert module.root == "/"
    assert module.qualified_name == "foo.bar.os.path"
    assert module.filepath == "/foo/bar/os/path.py"
    assert module.filename == "foo/bar/os/path.py"
    assert module.virtual_filename is None
    assert module.virtual_diff is None

    module = Module("/libs", "foo/bar.py")
    module = module.fold("/libs/foo")
    module = module.relative_ref("os.path")
    assert module.root == "/libs"
    assert module.qualified_name == "bar.os.path"
    assert module.filepath == "/libs/foo/bar/os/path.py"
    assert module.filename == "foo/bar/os/path.py"
    assert module.virtual_filename == "bar/os/path.py"
    assert module.virtual_diff == "foo"