tests: fix more cases of env variables (#41226)
This commit is contained in:
		@@ -43,7 +43,7 @@ def test_find_gpg(cmd_name, version, tmpdir, mock_gnupghome, monkeypatch):
 | 
				
			|||||||
                f.write(TEMPLATE.format(version=version))
 | 
					                f.write(TEMPLATE.format(version=version))
 | 
				
			||||||
            fs.set_executable(fname)
 | 
					            fs.set_executable(fname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    monkeypatch.setitem(os.environ, "PATH", str(tmpdir))
 | 
					    monkeypatch.setenv("PATH", str(tmpdir))
 | 
				
			||||||
    if version == "undetectable" or version.endswith("1.3.4"):
 | 
					    if version == "undetectable" or version.endswith("1.3.4"):
 | 
				
			||||||
        with pytest.raises(spack.util.gpg.SpackGPGError):
 | 
					        with pytest.raises(spack.util.gpg.SpackGPGError):
 | 
				
			||||||
            spack.util.gpg.init(force=True)
 | 
					            spack.util.gpg.init(force=True)
 | 
				
			||||||
@@ -54,7 +54,7 @@ def test_find_gpg(cmd_name, version, tmpdir, mock_gnupghome, monkeypatch):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_no_gpg_in_path(tmpdir, mock_gnupghome, monkeypatch, mutable_config):
 | 
					def test_no_gpg_in_path(tmpdir, mock_gnupghome, monkeypatch, mutable_config):
 | 
				
			||||||
    monkeypatch.setitem(os.environ, "PATH", str(tmpdir))
 | 
					    monkeypatch.setenv("PATH", str(tmpdir))
 | 
				
			||||||
    bootstrap("disable")
 | 
					    bootstrap("disable")
 | 
				
			||||||
    with pytest.raises(RuntimeError):
 | 
					    with pytest.raises(RuntimeError):
 | 
				
			||||||
        spack.util.gpg.init(force=True)
 | 
					        spack.util.gpg.init(force=True)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -904,13 +904,12 @@ def test_install_help_cdash():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.disable_clean_stage_check
 | 
					@pytest.mark.disable_clean_stage_check
 | 
				
			||||||
def test_cdash_auth_token(tmpdir, mock_fetch, install_mockery, capfd):
 | 
					def test_cdash_auth_token(tmpdir, mock_fetch, install_mockery, monkeypatch, capfd):
 | 
				
			||||||
    # capfd interferes with Spack's capturing
 | 
					    # capfd interferes with Spack's capturing
 | 
				
			||||||
    with tmpdir.as_cwd():
 | 
					    with tmpdir.as_cwd(), capfd.disabled():
 | 
				
			||||||
        with capfd.disabled():
 | 
					        monkeypatch.setenv("SPACK_CDASH_AUTH_TOKEN", "asdf")
 | 
				
			||||||
            os.environ["SPACK_CDASH_AUTH_TOKEN"] = "asdf"
 | 
					        out = install("-v", "--log-file=cdash_reports", "--log-format=cdash", "a")
 | 
				
			||||||
            out = install("-v", "--log-file=cdash_reports", "--log-format=cdash", "a")
 | 
					        assert "Using CDash auth token from environment" in out
 | 
				
			||||||
            assert "Using CDash auth token from environment" in out
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.not_on_windows("Windows log_output logs phase header out of order")
 | 
					@pytest.mark.not_on_windows("Windows log_output logs phase header out of order")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,10 +9,7 @@
 | 
				
			|||||||
This just tests whether the right args are getting passed to make.
 | 
					This just tests whether the right args are getting passed to make.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import shutil
 | 
					 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import tempfile
 | 
					 | 
				
			||||||
import unittest
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,110 +17,104 @@
 | 
				
			|||||||
from spack.util.environment import path_put_first
 | 
					from spack.util.environment import path_put_first
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pytestmark = pytest.mark.skipif(
 | 
					pytestmark = pytest.mark.skipif(
 | 
				
			||||||
    sys.platform == "win32",
 | 
					    sys.platform == "win32", reason="MakeExecutable not supported on Windows"
 | 
				
			||||||
    reason="MakeExecutable \
 | 
					 | 
				
			||||||
                                        not supported on Windows",
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MakeExecutableTest(unittest.TestCase):
 | 
					@pytest.fixture(autouse=True)
 | 
				
			||||||
    def setUp(self):
 | 
					def make_executable(tmp_path, working_env):
 | 
				
			||||||
        self.tmpdir = tempfile.mkdtemp()
 | 
					    make_exe = tmp_path / "make"
 | 
				
			||||||
 | 
					    with open(make_exe, "w") as f:
 | 
				
			||||||
 | 
					        f.write("#!/bin/sh\n")
 | 
				
			||||||
 | 
					        f.write('echo "$@"')
 | 
				
			||||||
 | 
					    os.chmod(make_exe, 0o700)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        make_exe = os.path.join(self.tmpdir, "make")
 | 
					    path_put_first("PATH", [tmp_path])
 | 
				
			||||||
        with open(make_exe, "w") as f:
 | 
					 | 
				
			||||||
            f.write("#!/bin/sh\n")
 | 
					 | 
				
			||||||
            f.write('echo "$@"')
 | 
					 | 
				
			||||||
        os.chmod(make_exe, 0o700)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        path_put_first("PATH", [self.tmpdir])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def tearDown(self):
 | 
					def test_make_normal():
 | 
				
			||||||
        shutil.rmtree(self.tmpdir)
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
 | 
					    assert make(output=str).strip() == "-j8"
 | 
				
			||||||
 | 
					    assert make("install", output=str).strip() == "-j8 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_normal(self):
 | 
					 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j8")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j8 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_explicit(self):
 | 
					def test_make_explicit():
 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
        self.assertEqual(make(parallel=True, output=str).strip(), "-j8")
 | 
					    assert make(parallel=True, output=str).strip() == "-j8"
 | 
				
			||||||
        self.assertEqual(make("install", parallel=True, output=str).strip(), "-j8 install")
 | 
					    assert make("install", parallel=True, output=str).strip() == "-j8 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_one_job(self):
 | 
					 | 
				
			||||||
        make = MakeExecutable("make", 1)
 | 
					 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j1")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j1 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_parallel_false(self):
 | 
					def test_make_one_job():
 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					    make = MakeExecutable("make", 1)
 | 
				
			||||||
        self.assertEqual(make(parallel=False, output=str).strip(), "-j1")
 | 
					    assert make(output=str).strip() == "-j1"
 | 
				
			||||||
        self.assertEqual(make("install", parallel=False, output=str).strip(), "-j1 install")
 | 
					    assert make("install", output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_parallel_disabled(self):
 | 
					 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "true"
 | 
					def test_make_parallel_false():
 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j1")
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j1 install")
 | 
					    assert make(parallel=False, output=str).strip() == "-j1"
 | 
				
			||||||
 | 
					    assert make("install", parallel=False, output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "1"
 | 
					 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j1")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j1 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # These don't disable (false and random string)
 | 
					def test_make_parallel_disabled(monkeypatch):
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "false"
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j8")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j8 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "foobar"
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "true")
 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j8")
 | 
					    assert make(output=str).strip() == "-j1"
 | 
				
			||||||
        self.assertEqual(make("install", output=str).strip(), "-j8 install")
 | 
					    assert make("install", output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        del os.environ["SPACK_NO_PARALLEL_MAKE"]
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "1")
 | 
				
			||||||
 | 
					    assert make(output=str).strip() == "-j1"
 | 
				
			||||||
 | 
					    assert make("install", output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_parallel_precedence(self):
 | 
					    # These don't disable (false and random string)
 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "false")
 | 
				
			||||||
 | 
					    assert make(output=str).strip() == "-j8"
 | 
				
			||||||
 | 
					    assert make("install", output=str).strip() == "-j8 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # These should work
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "foobar")
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "true"
 | 
					    assert make(output=str).strip() == "-j8"
 | 
				
			||||||
        self.assertEqual(make(parallel=True, output=str).strip(), "-j1")
 | 
					    assert make("install", output=str).strip() == "-j8 install"
 | 
				
			||||||
        self.assertEqual(make("install", parallel=True, output=str).strip(), "-j1 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "1"
 | 
					 | 
				
			||||||
        self.assertEqual(make(parallel=True, output=str).strip(), "-j1")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", parallel=True, output=str).strip(), "-j1 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # These don't disable (false and random string)
 | 
					def test_make_parallel_precedence(monkeypatch):
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "false"
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
        self.assertEqual(make(parallel=True, output=str).strip(), "-j8")
 | 
					 | 
				
			||||||
        self.assertEqual(make("install", parallel=True, output=str).strip(), "-j8 install")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.environ["SPACK_NO_PARALLEL_MAKE"] = "foobar"
 | 
					    # These should work
 | 
				
			||||||
        self.assertEqual(make(parallel=True, output=str).strip(), "-j8")
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "true")
 | 
				
			||||||
        self.assertEqual(make("install", parallel=True, output=str).strip(), "-j8 install")
 | 
					    assert make(parallel=True, output=str).strip() == "-j1"
 | 
				
			||||||
 | 
					    assert make("install", parallel=True, output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        del os.environ["SPACK_NO_PARALLEL_MAKE"]
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "1")
 | 
				
			||||||
 | 
					    assert make(parallel=True, output=str).strip() == "-j1"
 | 
				
			||||||
 | 
					    assert make("install", parallel=True, output=str).strip() == "-j1 install"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_jobs_env(self):
 | 
					    # These don't disable (false and random string)
 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "false")
 | 
				
			||||||
        dump_env = {}
 | 
					    assert make(parallel=True, output=str).strip() == "-j8"
 | 
				
			||||||
        self.assertEqual(
 | 
					    assert make("install", parallel=True, output=str).strip() == "-j8 install"
 | 
				
			||||||
            make(output=str, jobs_env="MAKE_PARALLELISM", _dump_env=dump_env).strip(), "-j8"
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        self.assertEqual(dump_env["MAKE_PARALLELISM"], "8")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_jobserver(self):
 | 
					    monkeypatch.setenv("SPACK_NO_PARALLEL_MAKE", "foobar")
 | 
				
			||||||
        make = MakeExecutable("make", 8)
 | 
					    assert make(parallel=True, output=str).strip() == "-j8"
 | 
				
			||||||
        os.environ["MAKEFLAGS"] = "--jobserver-auth=X,Y"
 | 
					    assert make("install", parallel=True, output=str).strip() == "-j8 install"
 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "")
 | 
					 | 
				
			||||||
        self.assertEqual(make(parallel=False, output=str).strip(), "-j1")
 | 
					 | 
				
			||||||
        del os.environ["MAKEFLAGS"]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_make_jobserver_not_supported(self):
 | 
					
 | 
				
			||||||
        make = MakeExecutable("make", 8, supports_jobserver=False)
 | 
					def test_make_jobs_env():
 | 
				
			||||||
        os.environ["MAKEFLAGS"] = "--jobserver-auth=X,Y"
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
        # Currently fallback on default job count, Maybe it should force -j1 ?
 | 
					    dump_env = {}
 | 
				
			||||||
        self.assertEqual(make(output=str).strip(), "-j8")
 | 
					    assert make(output=str, jobs_env="MAKE_PARALLELISM", _dump_env=dump_env).strip() == "-j8"
 | 
				
			||||||
        del os.environ["MAKEFLAGS"]
 | 
					    assert dump_env["MAKE_PARALLELISM"] == "8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_make_jobserver(monkeypatch):
 | 
				
			||||||
 | 
					    make = MakeExecutable("make", 8)
 | 
				
			||||||
 | 
					    monkeypatch.setenv("MAKEFLAGS", "--jobserver-auth=X,Y")
 | 
				
			||||||
 | 
					    assert make(output=str).strip() == ""
 | 
				
			||||||
 | 
					    assert make(parallel=False, output=str).strip() == "-j1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_make_jobserver_not_supported(monkeypatch):
 | 
				
			||||||
 | 
					    make = MakeExecutable("make", 8, supports_jobserver=False)
 | 
				
			||||||
 | 
					    monkeypatch.setenv("MAKEFLAGS", "--jobserver-auth=X,Y")
 | 
				
			||||||
 | 
					    # Currently fallback on default job count, Maybe it should force -j1 ?
 | 
				
			||||||
 | 
					    assert make(output=str).strip() == "-j8"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user