Esempio n. 1
0
def test_command_avail(tmpdir, mock_modulepath):
    load = PymodCommand("load")
    avail = PymodCommand("avail")
    save = PymodCommand("save")

    # Build modules
    one = tmpdir.mkdir("1")
    one.join("a.py").write('setenv("a", "a")\n')
    one.join("b.py").write('setenv("b", "b")\nload("c")')
    one.join("c.py").write('setenv("c", "c")\nload("d")')
    one.join("d.py").write('setenv("d", "d")\nload("e")')
    one.join("e.py").write('setenv("e", "e")\n')

    two = tmpdir.mkdir("2")
    two.join("a.py").write('setenv("a", "a")\n')
    two.join("b.py").write('setenv("b", "b")\nload_first("c", "e", "d")')
    two.join("d.py").write('setenv("d", "c")\nadd_option("x")')
    two.join("g.py").write('setenv("g", "d")\nload_first("x", "y", "z", None)')

    mock_modulepath([one.strpath, two.strpath])
    load("a")
    load("b")
    load("c")
    load("d", "x=foo")
    save("foo")
    avail()
    avail("-t")
    avail("--terse")
    avail("a")  # regular expression
    avail("--terse", "a")  # regular expression

    avail("-a")
    avail("--terse", "-a")
    avail("--terse", "-a", "a")
Esempio n. 2
0
def test_command_path(modules_path, mock_modulepath):
    load = PymodCommand("load")
    path = PymodCommand("path")
    mock_modulepath([modules_path.one, modules_path.two])
    load("a")
    load("b")
    path()
Esempio n. 3
0
def test_command_load_3(modules_path, mock_modulepath):
    """Load a and b, b loads d. Then, unload b (d should also unload)"""
    load = PymodCommand("load")
    unload = PymodCommand("unload")
    mock_modulepath(modules_path.two)

    load("a")
    assert pymod.environ.get("a") == "a"

    load("b")
    for x in "ced":
        if x in "ce":
            assert pymod.environ.get(x) is None
            assert not pymod.mc.module_is_loaded(x)
        else:
            assert pymod.environ.get(x) == x
            assert pymod.mc.module_is_loaded(x)

    # unload b, e will also unload
    unload("b")
    assert pymod.environ.get("b") is None
    assert pymod.environ.get("c") is None
    assert pymod.environ.get("d") is None
    assert pymod.environ.get("e") is None
    assert pymod.environ.get("a") == "a"

    unload("a")
    assert pymod.environ.get("a") is None
Esempio n. 4
0
def test_command_load_collection(tmpdir, mock_modulepath):
    save = PymodCommand("save")
    load = PymodCommand("load")
    purge = PymodCommand("purge")
    restore = PymodCommand("restore")

    tmpdir.join("a.py").write("")
    tmpdir.join("b.py").write("")
    tmpdir.join("c.py").write("")
    tmpdir.join("d.py").write("")
    mock_modulepath(tmpdir.strpath)
    a = load("a")
    b = load("b")
    c = load("c")
    d = load("d")
    save("foo")
    purge()
    restore("foo")

    for x in "abcd":
        m = pymod.modulepath.get(x)
        assert m.is_loaded
    purge()
    for x in "abcd":
        m = pymod.modulepath.get(x)
        assert not m.is_loaded
    load("foo")
    for x in "abcd":
        m = pymod.modulepath.get(x)
        assert m.is_loaded
Esempio n. 5
0
def test_command_save(modules_path, mock_modulepath):

    mock_modulepath(modules_path.path)
    save = PymodCommand("save")
    restore = PymodCommand("restore")
    a = pymod.mc.load("a")
    b = pymod.mc.load("b")
    c = pymod.mc.load("c")
    d = pymod.mc.load("d")

    save("foo")

    pymod.mc.purge()
    assert not a.is_loaded
    assert not b.is_loaded
    assert not c.is_loaded
    assert not d.is_loaded

    b2 = pymod.mc.load("b2")

    restore("foo")
    assert a.is_loaded
    assert b.is_loaded
    assert c.is_loaded
    assert d.is_loaded
    assert not b2.is_loaded

    cat = PymodCommand("cat")
    cat("foo")
Esempio n. 6
0
def test_command_load_2(modules_path, mock_modulepath):
    """Load a and b, b loads c, d, e. Then, unload b (c, d, e should also
    unload)
    """
    load = PymodCommand("load")
    unload = PymodCommand("unload")
    mock_modulepath(modules_path.one)
    load("a")
    assert pymod.environ.get("a") == "a"

    load("b")
    for x in "bcde":
        assert pymod.environ.get(x) == x
        assert pymod.mc.module_is_loaded(x)

    # just unload e
    unload("d")
    assert pymod.environ.get("d") is None
    assert pymod.environ.get("e") is None

    # unload b, c and d also unload
    unload("b")
    assert pymod.environ.get("b") is None
    assert pymod.environ.get("c") is None
    assert pymod.environ.get("d") is None
    assert pymod.environ.get("a") == "a"

    unload("a")
    assert pymod.environ.get("a") is None
Esempio n. 7
0
def test_command_refresh(modules_path, mock_modulepath):
    load = PymodCommand("load")
    refresh = PymodCommand("refresh")
    mock_modulepath(modules_path.one)
    load("a", "b", "c", "d")
    refresh()
    loaded = "".join(_.fullname for _ in pymod.mc.get_loaded_modules())
    assert loaded == "abcd"
Esempio n. 8
0
def test_command_load_1(modules_path, mock_modulepath):
    load = PymodCommand("load")
    unload = PymodCommand("unload")
    mock_modulepath(modules_path.one)
    load("a")
    assert pymod.environ.get("a") == "a"
    unload("a")
    assert pymod.environ.get("a") is None
Esempio n. 9
0
def test_command_swap(modules_path, mock_modulepath):
    load = PymodCommand("load")
    swap = PymodCommand("swap")
    mock_modulepath(modules_path.one)
    load("a")
    loaded = "".join(_.fullname for _ in pymod.mc.get_loaded_modules())
    assert loaded == "a"
    swap("a", "b")
    loaded = "".join(_.fullname for _ in pymod.mc.get_loaded_modules())
    assert loaded == "b"
Esempio n. 10
0
def test_command_unload_1(modules_path, mock_modulepath):
    load = PymodCommand("load")
    unload = PymodCommand("unload")
    mock_modulepath(modules_path.path)
    load("a")
    a = pymod.modulepath.get("a")
    assert pymod.environ.get("a") == "a"
    assert a.is_loaded
    pymod.mc.unload("a")
    assert pymod.environ.get("a") is None
    assert not a.is_loaded
Esempio n. 11
0
def test_command_reload_1(modules_path, mock_modulepath):
    load = PymodCommand("load")
    reload = PymodCommand("reload")
    mock_modulepath(modules_path.path)
    load("a")
    assert pymod.environ.get("a") == "a"
    reload("a")
    assert pymod.environ.get("a") == "a"
    # Reference count should not change
    a = pymod.modulepath.get("a")
    assert a.refcount == 1
Esempio n. 12
0
def test_command_list(tmpdir, mock_modulepath):
    tmpdir.join("a.py").write("")
    tmpdir.join("b.py").write('add_option("x")')
    tmpdir.join("c.py").write("")
    load = PymodCommand("load")
    list = PymodCommand("list")
    mock_modulepath(tmpdir.strpath)
    list()
    load("a")
    load("b", "x=foo")
    load("c")
    list()
    list("a")  # regular expression
    list("-c")
    list("-t")
Esempio n. 13
0
def test_command_remove(modules_path, mock_modulepath):

    mock_modulepath(modules_path.path)
    save = PymodCommand("save")
    remove = PymodCommand("remove")
    a = pymod.mc.load("a")
    b = pymod.mc.load("b")
    c = pymod.mc.load("c")
    d = pymod.mc.load("d")

    save("foo")
    assert pymod.collection.contains("foo")

    remove("foo")
    assert not pymod.collection.contains("foo")
Esempio n. 14
0
def test_command_clone2(modules_path, mock_modulepath):

    mock_modulepath(modules_path.path)
    clone = PymodCommand("clone")
    a = pymod.mc.load("a")
    b = pymod.mc.load("b")
    c = pymod.mc.load("c")
    d = pymod.mc.load("d")

    clone("save", "foo")

    pymod.mc.purge()
    assert not a.is_loaded
    assert not b.is_loaded
    assert not c.is_loaded
    assert not d.is_loaded

    clone("restore", "foo")
    for x in "abcd":
        m = pymod.modulepath.get(x)
        assert m.is_loaded

    clone("avail")
    clone("avail", "-t")
    clone("avail", "--terse")
Esempio n. 15
0
def test_command_find(tmpdir, mock_modulepath):
    tmpdir.join("a.py").write("")
    find = PymodCommand("find")
    mock_modulepath(tmpdir.strpath)
    find("a")
    with pytest.raises(pymod.error.ModuleNotFoundError):
        find("b")
Esempio n. 16
0
def test_command_cache(tmpdir, mock_modulepath):
    tmpdir.join("a.py").write("")
    mock_modulepath(tmpdir.strpath)
    cache = PymodCommand("cache")
    cache("build")
    cache("rebuild")
    cache("remove")
Esempio n. 17
0
def test_command_cat(modules_path, mock_modulepath):
    cat = PymodCommand("cat")
    mock_modulepath(modules_path.one)
    cat("a")

    with pytest.raises(Exception):
        cat("fake")
Esempio n. 18
0
def test_command_info(tmpdir, mock_modulepath):
    tmpdir.join("a.py").write("")
    info = PymodCommand("info")
    mock_modulepath(tmpdir.strpath)
    info("a")
    with pytest.raises(pymod.error.ModuleNotFoundError):
        info("b")
Esempio n. 19
0
def test_command_unuse(modules_path, mock_modulepath):
    unuse = PymodCommand("unuse")
    load = PymodCommand("load")

    mock_modulepath([modules_path.one, modules_path.two])
    a = pymod.mc.load("a")
    b = pymod.mc.load("b")
    unuse(modules_path.one)

    c = pymod.mc.load("c")
    d = pymod.mc.load("d")
    unuse(modules_path.two)

    loaded = pymod.mc.get_loaded_modules()
    assert len(loaded) == 0

    assert pymod.modulepath.size() == 0
Esempio n. 20
0
def test_command_purge(modules_path, mock_modulepath):
    """Load a and b, b loads c, d, e. Then, unload b (c, d, e should also
    unload)
    """
    load = PymodCommand("load")
    purge = PymodCommand("purge")
    mock_modulepath(modules_path.one)
    load("a")
    assert pymod.environ.get("a") == "a"

    load("b")
    for x in "bcde":
        assert pymod.environ.get(x) == x
        assert pymod.mc.module_is_loaded(x)
    purge()

    loaded = pymod.mc.get_loaded_modules()
    assert len(loaded) == 0
Esempio n. 21
0
def test_command_whatis(tmpdir, modulecmds, mock_modulepath):
    m = modulecmds
    tmpdir.join("a.py").write(m.whatis("WHATIS A"))
    mock_modulepath(tmpdir.strpath)
    whatis = PymodCommand("whatis")
    whatis("a")

    with pytest.raises(ModuleNotFoundError):
        whatis("b")
Esempio n. 22
0
def test_command_unload_3(modules_path, mock_modulepath):
    load = PymodCommand("load")
    unload = PymodCommand("unload")
    mock_modulepath(modules_path.path)
    load("a")
    load("a1")
    load("a2")
    assert pymod.environ.get("a") == "a"
    assert pymod.environ.get("a1") == "a1"
    assert pymod.environ.get("a2") == "a2"

    # a was "loaded" 3  times, loading b causes the
    unload("a2")
    a = pymod.modulepath.get("a")
    assert a.is_loaded
    unload("a1")
    assert a.is_loaded
    unload("a")
    assert not a.is_loaded
Esempio n. 23
0
def test_command_show(tmpdir, mock_modulepath):
    tmpdir.join("a.py").write('append_path("FOO", "/a/b/c", sep=";")')
    show = PymodCommand("show")
    mock_modulepath(tmpdir.strpath)
    show("a", "+x")
    with pytest.raises(ModuleNotFoundError):
        show("fake")
    with pytest.raises(ValueError):
        # need module for options
        show("+x")
Esempio n. 24
0
def test_command_hierarchy_1(modules_path, mock_modulepath):
    """Loop through the module hierarchy to make sure it is laid out
    correctly"""
    load = PymodCommand("load")
    core_path = modules_path.core
    mock_modulepath(modules_path.core)

    is_module = lambda x: pymod.modulepath.get(x) is not None

    for compiler_ver in compiler_versions:
        compiler_module_name = os.path.sep.join((compiler_vendor, compiler_ver))
        load(compiler_module_name)
        compiler = pymod.modulepath.get(compiler_module_name)
        assert compiler is not None

        compiler_unlocks_dir = os.path.normpath(
            os.path.join(core_path, "..", "compiler", compiler_vendor, compiler_ver)
        )

        assert os.path.isdir(compiler_unlocks_dir)
        assert pymod.modulepath.contains(compiler_unlocks_dir)

        a = pymod.modulepath.get("a")
        assert a is not None
        assert a.version.string == "1.0"
        assert a.filename == os.path.join(
            compiler_unlocks_dir, a.name, a.version.string + ".py"
        )

        for mpi_ver in mpi_versions:
            mpi_module_name = os.path.sep.join((mpi_vendor, mpi_ver))
            load(mpi_module_name)
            mpi = pymod.modulepath.get(mpi_module_name)
            assert mpi is not None

            mpi_unlocks_dir = os.path.normpath(
                os.path.join(
                    core_path,
                    "..",
                    "mpi",
                    compiler_vendor,
                    compiler_ver,
                    mpi_vendor,
                    mpi_ver,
                )
            )

            assert os.path.isdir(mpi_unlocks_dir)
            assert pymod.modulepath.contains(mpi_unlocks_dir)

            load("b")

    return
Esempio n. 25
0
def test_command_alias(tmpdir, mock_modulepath):
    a = tmpdir.join("a.py").write("")
    mock_modulepath(tmpdir.strpath)
    alias = PymodCommand("alias")
    alias("save", "a", "a-alias")
    a = pymod.mc.load("a-alias")
    aa = pymod.modulepath.get("a")
    assert a.filename == aa.filename

    alias("avail")
    alias("remove", "a-alias")
    assert pymod.alias.get("a-alias") is None

    with pytest.raises(ModuleNotFoundError):
        alias("save", "b", "b-alias")
Esempio n. 26
0
def test_command_hierarchy_2(modules_path, mock_modulepath):
    """Tests the basic functionality of module hierarchy.

    Steps:
    - Load a compiler.  The compiler unlocks compiler dependent modules
    - Load a compiler dependent module.
    - Load an mpi implementation. The mpi implementation unlocks mpi
      implementation dependent modules
    - Load an mpi implementation dependent module

    Now is the fun part
    - Load a different compiler.

    The compiler dependent and mpi dependent modules will all be updated
    accordingly

    """
    load = PymodCommand("load")
    core_path = modules_path.core
    mock_modulepath(modules_path.core)

    _compiler_unlocks_dir = lambda cc, cv: os.path.normpath(
        os.path.join(core_path, "..", "compiler", cc, cv)
    )
    _mpi_unlocks_dir = lambda cc, cv, mpi, mpiv: os.path.normpath(
        os.path.join(core_path, "..", "mpi", cc, cv, mpi, mpiv)
    )

    compiler_ver = compiler_versions[0]
    compiler_module_name = os.path.sep.join((compiler_vendor, compiler_ver))
    load(compiler_module_name)
    compiler = pymod.modulepath.get(compiler_module_name)
    assert compiler is not None

    compiler_unlocks_dir = _compiler_unlocks_dir(compiler_vendor, compiler_ver)

    assert os.path.isdir(compiler_unlocks_dir)
    assert pymod.modulepath.contains(compiler_unlocks_dir)

    a = pymod.modulepath.get("a")
    assert a is not None
    assert a.version.string == "1.0"
    assert a.filename == os.path.join(
        compiler_unlocks_dir, a.name, a.version.string + ".py"
    )

    mpi_ver = mpi_versions[0]
    mpi_module_name = os.path.sep.join((mpi_vendor, mpi_ver))
    load(mpi_module_name)
    mpi = pymod.modulepath.get(mpi_module_name)
    assert mpi is not None

    mpi_unlocks_dir = _mpi_unlocks_dir(
        compiler_vendor, compiler_ver, mpi_vendor, mpi_ver
    )

    assert os.path.isdir(mpi_unlocks_dir)
    assert pymod.modulepath.contains(mpi_unlocks_dir)

    b = load("b")
    b = pymod.modulepath.get("b")
    assert b.filename == os.path.join(mpi_unlocks_dir, b.name, b.version.string + ".py")

    # Now, load a different compiler and a, mpi, and b modules will all be
    # updated automatically
    compiler_ver = compiler_versions[1]
    compiler_module_name = os.path.sep.join((compiler_vendor, compiler_ver))
    load(compiler_module_name)
    compiler = pymod.modulepath.get(compiler_module_name)
    assert compiler is not None
    compiler_unlocks_dir = _compiler_unlocks_dir(compiler_vendor, compiler_ver)
    assert os.path.isdir(compiler_unlocks_dir)
    assert pymod.modulepath.contains(compiler_unlocks_dir)

    a = pymod.modulepath.get("a")
    assert a.filename == os.path.join(
        compiler_unlocks_dir, a.name, a.version.string + ".py"
    )

    mpi = pymod.modulepath.get(mpi_module_name)
    assert mpi is not None
    mpi_unlocks_dir = _mpi_unlocks_dir(
        compiler_vendor, compiler_ver, mpi_vendor, mpi_ver
    )
    assert os.path.isdir(mpi_unlocks_dir)
    assert pymod.modulepath.contains(mpi_unlocks_dir)

    b = pymod.modulepath.get("b")
    assert b.filename == os.path.join(mpi_unlocks_dir, b.name, b.version.string + ".py")

    return
Esempio n. 27
0
def test_command_tutorial():
    tutorial = PymodCommand("tutorial")
    tutorial("basic")
    tutorial("teardown")
Esempio n. 28
0
def test_command_restore_clone_bad(modules_path, mock_modulepath):
    clone = PymodCommand("clone")
    with pytest.raises(CloneDoesNotExistError):
        clone("restore", "fake")
Esempio n. 29
0
def test_command_commands_rst():
    commands = PymodCommand("commands")
    commands("--format=rst")
Esempio n. 30
0
def test_command_commands_default():
    commands = PymodCommand("commands")
    commands()