fork/mons

git clone https://git.julia.blue/fork/mons

coloursofnoiseMock all http requests in integration testse96fbdd

misc-fixes
3.4 KiB97 linesraw
1import os
2import shutil
3import zipfile
4
5import outputs
6import pytest
7
8import mons.commands.main
9from mons.mons import cli as mons_cli
10
11# mock data for Everest build list in ./_data/build_list
12
13GITHUB_REPO = "https://github.com/EverestAPI/Everest"
14
15
16@pytest.fixture(autouse=True)
17def mock_installer(monkeypatch):
18    monkeypatch.setattr(mons.commands.main, "download_artifact", lambda *args: None)
19    monkeypatch.setattr(mons.commands.main, "run_installer", lambda *args: True)
20
21
22def test_install_default(runner_result, test_install):
23    # install preferred branch, set to a stable version by `test_install` fixture
24    with runner_result(mons_cli, ["install", test_install]) as result:
25        assert result.exit_code == 0
26        assert outputs.INSTALL_SUCCESS in result.output
27
28
29def test_install_branch(runner_result, test_install):
30    with runner_result(mons_cli, ["install", test_install, "stable"]) as result:
31        assert result.exit_code == 0
32        assert outputs.INSTALL_SUCCESS in result.output
33
34
35def test_install_url(runner_result, test_install):
36    url = f"{GITHUB_REPO}/releases/latest/download/main.zip"
37
38    with runner_result(mons_cli, ["install", test_install, url]) as result:
39        assert result.exit_code == 0
40        assert outputs.INSTALL_SUCCESS in result.output
41
42
43@pytest.mark.data_file_download(
44    f"{GITHUB_REPO}/releases/latest/download/olympus-build.zip", "olympus-build.zip"
45)
46def test_install_zip(runner_result, test_install, data_file_download):
47    with runner_result(
48        mons_cli, ["install", test_install, data_file_download]
49    ) as result:
50        assert result.exit_code == 0
51        assert outputs.INSTALL_SUCCESS in result.output
52
53
54@pytest.mark.data_file_download(
55    f"{GITHUB_REPO}/releases/latest/download/olympus-build.zip", "olympus-build.zip"
56)
57def test_install_stdin(runner_result, test_install, data_file_download):
58    with open(data_file_download) as data:
59        with runner_result(
60            mons_cli, ["install", test_install, "-"], input=data
61        ) as result:
62            assert result.exit_code == 0
63            assert outputs.INSTALL_SUCCESS in result.output
64
65
66@pytest.mark.xfail(
67    not (shutil.which("dotnet") or shutil.which("msbuild")),
68    reason="no .NET build tool found",
69    run=False,
70)
71@pytest.mark.data_file_download(
72    f"{GITHUB_REPO}/archive/refs/heads/stable.zip", "stable.zip"
73)
74def test_install_src(runner_result, test_install, cache, data_file_download):
75    source_dir = os.path.join(cache.mkdir("mons_test_install"), "Everest-stable")
76    if not os.path.exists(source_dir):
77        with zipfile.ZipFile(data_file_download, "r") as zip:
78            zip.extractall(cache.mkdir("mons_test_install"))
79
80    assert os.listdir(source_dir), "Failed to download source artifact: " + source_dir
81
82    with runner_result(
83        mons_cli, ["install", test_install, "--src", source_dir]
84    ) as result:
85        assert result.exit_code == 0
86        assert outputs.INSTALL_SUCCESS in result.output
87        assert "Building Everest source" in result.output
88
89    # Previous command builds straight to `test_install.path`.
90    # Build artifacts in in place so that `--no-build` is possible.
91    mons.commands.main.build_source(source_dir, None, False, None, [])
92    with runner_result(
93        mons_cli, ["install", test_install, "--src", source_dir, "--no-build"]
94    ) as result:
95        assert result.exit_code == 0
96        assert outputs.INSTALL_SUCCESS in result.output
97        assert "Copying build artifacts" in result.output