File: test_util.py

package info (click to toggle)
mkosi 26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,564 kB
  • sloc: python: 20,615; sh: 640; makefile: 12
file content (52 lines) | stat: -rw-r--r-- 1,292 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
# SPDX-License-Identifier: LGPL-2.1-or-later

from pathlib import Path

import pytest

from mkosi.util import parents_below


def test_parents_below_basic() -> None:
    path = Path("/a/b/c/d/e")
    below = Path("/a/b")
    assert parents_below(path, below) == [Path("/a/b/c/d"), Path("/a/b/c")]


def test_parents_below_root() -> None:
    path = Path("/a/b/c")
    below = Path("/")
    assert parents_below(path, below) == [Path("/a/b"), Path("/a")]


def test_parents_below_direct_child() -> None:
    path = Path("/a/b/c")
    below = Path("/a/b")
    assert parents_below(path, below) == []


def test_parents_below_relative_paths() -> None:
    path = Path("a/b/c/d")
    below = Path("a/b")
    assert parents_below(path, below) == [Path("a/b/c")]


def test_parents_below_same_path_raises() -> None:
    path = Path("/a/b/c")
    below = Path("/a/b/c")
    with pytest.raises(ValueError):
        parents_below(path, below)


def test_parents_below_not_parent_raises() -> None:
    path = Path("/a/b/c")
    below = Path("/x/y/z")
    with pytest.raises(ValueError):
        parents_below(path, below)


def test_parents_below_below_is_child_raises() -> None:
    path = Path("/a/b")
    below = Path("/a/b/c")
    with pytest.raises(ValueError):
        parents_below(path, below)