File: test_pathlib.py

package info (click to toggle)
doxysphinx 3.3.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,296 kB
  • sloc: python: 2,974; javascript: 235; cpp: 88; makefile: 52; sh: 10
file content (97 lines) | stat: -rw-r--r-- 3,667 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# =====================================================================================
#  C O P Y R I G H T
# -------------------------------------------------------------------------------------
#  Copyright (c) 2023 by Robert Bosch GmbH. All rights reserved.
#
#  Author(s):
#  - Markus Braun, :em engineering methods AG (contracted by Robert Bosch GmbH)
# =====================================================================================

import sys
from pathlib import Path

import pytest

from doxysphinx.utils.pathlib_fix import path_is_relative_to

older_than_3_9 = sys.version_info < (3, 9)


@pytest.mark.skipif(older_than_3_9, reason="requires python 3.9")
@pytest.mark.parametrize(
    "path, relative_to",
    [
        (
            Path("/workspaces/doxysphinx/doxygen/html/test.css"),
            Path("/workspaces/doxysphinx"),
        ),
        (
            Path("/workspaces/doxysphinx/doxygen/html/test.css"),
            Path("/workspaces/doxysphinx"),
        ),
    ],
)
def test_pathlib_is_relative_to_works_as_expected(path: Path, relative_to: Path):
    assert path.is_relative_to(relative_to)


@pytest.mark.parametrize(
    "path, relative_to, expected_result",
    [
        # positive tests
        # unix absolute paths
        (
            Path("/workspaces/doxysphinx/doxygen/html/test.css"),
            Path("/workspaces/doxysphinx"),
            True,
        ),
        (
            Path("/workspaces/doxysphinx/doxygen/html/test.css"),
            Path("/workspaces/doxysphinx"),
            True,
        ),
        (
            Path("/workspaces/doxysphinx/doxygen/html/test.css"),
            Path("/workspaces/"),
            True,
        ),
        (Path("/workspaces/doxysphinx/doxygen/html/test.css"), Path("/"), True),
        (
            Path("/workspaces/doxysphinx/doxygen/html"),
            Path("/workspaces/doxysphinx"),
            True,
        ),
        (Path("/workspaces/doxysphinx/doxygen/html/"), Path("/workspaces/"), True),
        (Path("/workspaces/doxysphinx/doxygen/html"), Path("/"), True),
        # unix relative paths
        (Path("."), Path("."), True),
        (Path("./"), Path("./"), True),
        (Path("doxysphinx/doxygen/html/test.css"), Path("doxysphinx"), True),
        (Path("doxysphinx/doxygen/html/test.css"), Path("doxysphinx"), True),
        (Path("doxysphinx/doxygen/html/test.css"), Path("/"), True),
        (Path("./doxygen/html/test.css"), Path("doxygen/"), True),
        (Path("doxysphinx/doxygen/html/"), Path("/"), True),
        (Path("./doxysphinx/doxygen/html"), Path("/"), True),
        # windows absolute paths
        (Path("D:\\test\\doxysphinx"), Path("D:\\"), True),
        (Path("D:\\test\\doxysphinx"), Path("D:\\test"), True),
        (Path("D:\\test\\doxysphinx"), Path("D:\\test\\doxysphinx"), True),
        # windows relative paths
        (Path("test\\doxysphinx"), Path("test"), True),
        (Path("test\\doxysphinx"), Path("test\\doxysphinx"), True),
        # negative tests
        (Path("a"), Path("b"), False),
        (Path("a/b"), Path("b/b"), False),
        (Path("a/b/c"), Path("a/b/d"), False),
        (
            Path("/doxysphinx/doxygen/html/test.css"),
            Path("/doxysphinx-other/dir"),
            False,
        ),
        (Path("D:\\test"), Path("C:\\nothing_to_do"), False),
        (Path(".\\test\\doxysphinx"), Path("\\$/$(ยง"), False),
        (Path("D:\\this is only a test"), Path("C:\\lets try\\doxy sphinx"), False),
    ],
)
def test_path_is_relative_to_works_as_expected(path: Path, relative_to: Path, expected_result: bool):
    assert path_is_relative_to(path, relative_to) == expected_result