Exemplo n.º 1
0
def test_validation(monkeypatch, tmpdir, cli_runner):
    """Test that we retrieve the correct module versions.

       Names are retrieved from a given path and the module names and versions
       are validated.
    """
    @click.group()
    def test_cli():
        pass

    @test_cli.command()
    def test():
        validate_module_name('wrong-format')

    with tmpdir.as_cwd():
        for k, v in DIR_STRUCTURE.items():
            for k2, v2 in v.items():
                os.makedirs(os.path.join(k, k2))
                for v3 in v2:
                    open(os.path.join(k, k2, v3), 'a').close()

        # Prepare path variable that we are going to monkeypatch for
        # `get_available_modules`
        dirs = ':'.join(
            [os.path.join(os.getcwd(), x) for x in os.listdir(os.getcwd())])
        monkeypatch.setenv('MODULEPATH', dirs)
        modules = get_available_modules()

        # Assert that the correct modules and their versions are returned.
        assert set(modules['gromacs']) == set(
            ['2016.4', '5.1.4-plumed2.3', '2018.1'])
        assert set(modules['namd']) == set(['123', '456'])

        # Make sure we return a boolean if the module is available or not.
        assert not validate_module_name('gromacs/123', modules)
        assert validate_module_name('gromacs/2018.1', modules)

        output = 'ERROR We were not able to determine the module name.\n'
        result = cli_runner.invoke(test_cli, ['test'])
        assert result.exit_code == 1
        assert result.output == output
Exemplo n.º 2
0
def test_validation(capsys, monkeypatch, tmpdir):
    """Test that we retrieve the correct module versions.

       Names are retrieved from a given path and the module names and versions
       are validated.
    """
    with tmpdir.as_cwd():
        for k, v in DIR_STRUCTURE.items():
            for k2, v2 in v.items():
                os.makedirs(os.path.join(k, k2))
                for v3 in v2:
                    open(os.path.join(k, k2, v3), "a").close()

        # Prepare path variable that we are going to monkeypatch for
        # `get_available_modules`
        dirs = ":".join(
            [os.path.join(os.getcwd(), x) for x in os.listdir(os.getcwd())])
        monkeypatch.setenv("MODULEPATH", dirs)
        modules = get_available_modules()

        # Assert that the correct modules and their versions are returned.
        assert set(modules["gromacs"]) == set(
            ["2016.4", "5.1.4-plumed2.3", "2018.1"])
        assert set(modules["namd"]) == set(["123", "456"])

        # Make sure we return a boolean if the module is available or not.
        assert not validate_module_name("gromacs/123", modules)
        assert validate_module_name("gromacs/2018.1", modules)

        output = "ERROR We were not able to determine the module name.\n"
        with pytest.raises(SystemExit) as e:
            validate_module_name("wrong=format")
            out, err = capsys.readouterr()

            assert e.type == SystemExit
            assert e.code == 1
            assert out == output
Exemplo n.º 3
0
 def test():
     validate_module_name('wrong-format')