Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichAltheide committed Jan 6, 2025
1 parent 47e5beb commit e3a8639
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def mock_getoutput(mocker):
return_value="24.05.20240815.c3d4ac7 (Uakari)",
)

@pytest.fixture
def mock_subprocess_run(mocker):
return mocker.Mock(name="subprocess.run")

@pytest.fixture
def mock_Popen(mocker):
Expand Down Expand Up @@ -133,14 +136,12 @@ def fake_open(*args, **kwargs):
file, *mode = args
assert len(mode) == 0 or mode[0] == "r", "open() called with non-'r' mode"

assert mode == "r", "open() called without the 'r' mode"

if file.startswith("/run/current-system/sw/lib/calamares/modules/nixos/"):
redirectedDir = '{}/modules/nixos/'.format(testing_parent_dir)
redirectedFile = file.replace("/run/current-system/sw/lib/calamares/modules/nixos/", redirectedDir)
return buildin_open(redirectedFile, mode)
return buildin_open(redirectedFile, "r")
elif file.startswith(testing_dir):
return buildin_open(file, mode)
return buildin_open(file, "r")
elif file.endswith("hardware-configuration.nix"):
return mocker.mock_open(mock=mock_open_hwconf, read_data=hwconf_txt)(*args)
elif file.endswith("nixos-generate-config.conf"):
Expand All @@ -165,6 +166,7 @@ def run(
mock_check_output,
mock_getoutput,
mock_Popen,
mock_subprocess_run,
mock_open,
):
sys.modules["libcalamares"] = mock_libcalamares
Expand All @@ -174,6 +176,7 @@ def run(
mocker.patch("subprocess.check_output", mock_check_output)
mocker.patch("subprocess.getoutput", mock_getoutput)
mocker.patch("subprocess.Popen", mock_Popen)
mocker.patch("subprocess.run", mock_subprocess_run)

mocker.patch("builtins.open", mock_open)

Expand Down
11 changes: 11 additions & 0 deletions testing/test_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_baseline(
mock_open_ngcconf,
mock_open_hwconf,
mock_Popen,
mock_subprocess_run,
):
result = run()

Expand Down Expand Up @@ -75,6 +76,16 @@ def test_baseline(
# libcalamares.job.setprogress(0.3)
assert mock_libcalamares.job.setprogress.mock_calls[3] == mocker.call(0.3)

assert mock_subprocess_run.mock_calls[0] == mocker.call(
["nix", "config", "show", "substituters"],
capture_output=True, text=True
)

assert mock_subprocess_run.mock_calls[1] == mocker.call(
["nix", "config", "show", "trusted-public-keys"],
capture_output=True, text=True
)

# proc = subprocess.Popen(["pkexec", "nixos-install", "--no-root-passwd", "--root", root_mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
mock_Popen.assert_called_once_with(
["pkexec", "nixos-install", "--no-root-passwd", "--root", "/mnt/root"],
Expand Down

0 comments on commit e3a8639

Please sign in to comment.