-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_util.py
35 lines (29 loc) · 1.33 KB
/
test_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Tests related to the utility functions."""
from pathlib import Path, PurePath
import pytest
from clang_tools import install_os
from clang_tools.install import clang_tools_binary_url
from clang_tools.util import check_install_os, download_file, get_sha_checksum
from clang_tools import release_tag
def test_check_install_os():
"""Tests the return value of `check_install_os()`."""
current_os = check_install_os()
assert current_os in ("linux", "windows", "macosx")
@pytest.mark.parametrize(
"tag", [release_tag, pytest.param("latest", marks=pytest.mark.xfail)]
)
def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, tag: str):
"""Test that deliberately fails to download a file."""
monkeypatch.chdir(str(tmp_path))
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
file_name = download_file(url, "file.tar.gz", True)
assert file_name is not None
def test_get_sha(monkeypatch: pytest.MonkeyPatch):
"""Test the get_sha() function used to fetch the
releases' corresponding SHA512 checksum."""
monkeypatch.chdir(PurePath(__file__).parent.as_posix())
expected = Path(f"clang-format-12_{install_os}-amd64.sha512sum").read_text(
encoding="utf-8"
)
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
assert get_sha_checksum(url) == expected