aboutsummaryrefslogtreecommitdiff
path: root/tests/test_setup.py
blob: 1850319dc067d3cd6d8e392413f81305ad4ed8f9 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Test for module setup."""
from __future__ import annotations

from unittest.mock import Mock
from unittest.mock import patch

import pytest

from setup import replace_markdown_relative_paths


@pytest.mark.parametrize(
    "linked_file_found, file_content, expected_result",
    [
        [
            True,
            "[Test](README.md)",
            "[Test](https://review.mlplatform.org/plugins/gitiles/"
            "ml/mlia/+/refs/tags/0.1.0/README.md)",
        ],
        [
            True,
            "![Test](image.png)",
            "![Test](https://git.mlplatform.org/ml/mlia.git/plain/image.png?h=0.1.0)",
        ],
        [
            False,
            "[Test](http://review.mlplatform.org)",
            "[Test](http://review.mlplatform.org)",
        ],
        [False, "[Test](README.md)", "[Test](README.md)"],
        [
            True,
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
        ],
    ],
)
@patch("pathlib.Path")
def test_replace_markdown_relative_paths(
    path_mock: Mock,
    linked_file_found: bool,
    file_content: str,
    expected_result: str,
) -> None:
    """Test replacement of relative md paths with links to review.mlplatform.org."""
    # Set a mock setuptools scm version for testing
    tag = "0.1.0"
    path_mock.read_text.return_value = file_content
    path_mock.exists.return_value = linked_file_found
    path_mock.joinpath.return_value = path_mock

    result = replace_markdown_relative_paths(path_mock, "test.md", tag)
    assert result == expected_result