def test_fake_mpi_config(self, fake_mpi_conf: str) -> None: conf_obj = MpiConfig.load(fake_mpi_conf) runner = conf_obj.runner assert os.path.dirname(runner) == os.path.dirname(fake_mpi_conf) assert os.path.basename(runner) == "fake_mpirun" assert conf_obj.nproc_flag == "--num" assert conf_obj.default_nproc == 1 assert conf_obj.extra_flags == ["--no-fail"]
def test_mpi_conf_defaults() -> None: mpi = MpiConfig() assert mpi.runner == "mpirun" assert mpi.nproc_flag == "-n" assert mpi.default_nproc == 1 assert mpi.extra_flags == [] assert mpi.env_pass == [] assert mpi.env_pass_regex == [] assert mpi.env_set == {}
def test_mpi_conf_unknownkeys() -> None: with pytest.raises(TypeError): MpiConfig(runner="mpiexec", foo="bar") # type: ignore
def test_env_passing(monkeypatch: Any) -> None: config = MpiConfig( env_pass=["A", "B", "LONG_NAME"], env_pass_regex=["TOOLNAME", "MPI_.*_CONF"], ) env = {} # type: MutableMapping[str, str] with monkeypatch.context() as m: m.setattr(os, "environ", {}) env = {} config.pass_through_env_vars(env) assert env == {} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a"}) env = {} config.pass_through_env_vars(env) assert env == {"A": "a"} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a", "C": "c"}) env = {} config.pass_through_env_vars(env) assert env == {"A": "a"} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a", "B": "b", "C": "c"}) env = {"PATH": "one:two:three", "HOME": "/tmp/dir", "TMPDIR": "/tmp/dir"} config.pass_through_env_vars(env) assert env == { "PATH": "one:two:three", "HOME": "/tmp/dir", "TMPDIR": "/tmp/dir", "A": "a", "B": "b", } with monkeypatch.context() as m: m.setattr(os, "environ", {"TOOLNAME": "foobar"}) env = {} config.pass_through_env_vars(env) assert env == {"TOOLNAME": "foobar"} with monkeypatch.context() as m: m.setattr(os, "environ", {"_TOOLNAME_": "foobar"}) env = {} config.pass_through_env_vars(env) # Cos we are matching not searching assert env == {} with monkeypatch.context() as m: m.setattr(os, "environ", {"MPI_A_CONF": "A", "MPI_B_CONF": "B"}) env = {} config.pass_through_env_vars(env) # Cos we are matching not searching assert env == {"MPI_A_CONF": "A", "MPI_B_CONF": "B"}
def test_env_passing(monkeypatch: pytest.MonkeyPatch) -> None: """Confirm that MPI extension passes environment variables correctly.""" config = MpiConfig( env_pass=["A", "B", "LONG_NAME"], env_pass_regex=["TOOLNAME", "MPI_.*_CONF"], ) env: MutableMapping[str, str] = {} with monkeypatch.context() as m: m.setattr(os, "environ", {}) env = {} config.pass_through_env_vars(env) assert env == {} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a"}) env = {} config.pass_through_env_vars(env) assert env == {"A": "a"} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a", "C": "c"}) env = {} config.pass_through_env_vars(env) assert env == {"A": "a"} with monkeypatch.context() as m: m.setattr(os, "environ", {"A": "a", "B": "b", "C": "c"}) env = { "PATH": "one:two:three", "HOME": "/tmp/dir", "TMPDIR": "/tmp/dir" } config.pass_through_env_vars(env) assert env == { "PATH": "one:two:three", "HOME": "/tmp/dir", "TMPDIR": "/tmp/dir", "A": "a", "B": "b", } with monkeypatch.context() as m: m.setattr(os, "environ", {"TOOLNAME": "foobar"}) env = {} config.pass_through_env_vars(env) assert env == {"TOOLNAME": "foobar"} with monkeypatch.context() as m: m.setattr(os, "environ", {"_TOOLNAME_": "foobar"}) env = {} config.pass_through_env_vars(env) # Cos we are matching not searching assert env == {} with monkeypatch.context() as m: m.setattr(os, "environ", {"MPI_A_CONF": "A", "MPI_B_CONF": "B"}) env = {} config.pass_through_env_vars(env) # Cos we are matching not searching assert env == {"MPI_A_CONF": "A", "MPI_B_CONF": "B"}