aboutsummaryrefslogtreecommitdiff
path: root/tests/test_setup.py
diff options
context:
space:
mode:
authorRaul Farkas <raul.farkas@arm.com>2022-10-28 16:11:53 +0100
committerRaul Farkas <raul.farkas@arm.com>2022-11-08 14:44:52 +0000
commitcec84af5b0051bfa7ed30b15c6b25ef528a53027 (patch)
tree85b02025e7417a130c5abcf0c489ee6056f907c4 /tests/test_setup.py
parent27668f6837c4f0a7197d13baff7bffc11f652fba (diff)
downloadmlia-cec84af5b0051bfa7ed30b15c6b25ef528a53027.tar.gz
MLIA-630 Fix links to other files in README.md
* Update setup.py to replace relative paths in README.md with links to files on review.mlplatform.org * Add a mechanism that replaces relative paths to images with the link to the plain image on review.mlplatform.org Change-Id: Ifeb17e3c03e8366bd12665eb9f4a630fc9933e26
Diffstat (limited to 'tests/test_setup.py')
-rw-r--r--tests/test_setup.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_setup.py b/tests/test_setup.py
new file mode 100644
index 0000000..1850319
--- /dev/null
+++ b/tests/test_setup.py
@@ -0,0 +1,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