File: test_helpers.py

package info (click to toggle)
python-sphinx-chango 0.5.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,776 kB
  • sloc: python: 4,909; javascript: 74; makefile: 23
file content (32 lines) | stat: -rw-r--r-- 844 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
#  SPDX-FileCopyrightText: 2024-present Hinrich Mahler <chango@mahlerhome.de>
#
#  SPDX-License-Identifier: MIT
from pathlib import Path

from chango.helpers import change_uid_from_file, ensure_uid


class TestHelpers:
    def test_ensure_uid_none(self):
        assert ensure_uid(None) is None

    def test_ensure_uid_str(self):
        assert ensure_uid("uid") == "uid"

    def test_ensure_uid_obj(self):
        class Obj:
            uid = "uid"

        assert ensure_uid(Obj()) == "uid"

    def test_ensure_uid_obj_prop(self):
        class Obj:
            @property
            def uid(self):
                return "uid"

        assert ensure_uid(Obj()) == "uid"

    def test_change_uid_from_file(self):
        assert change_uid_from_file("slug.uid.md") == "uid"
        assert change_uid_from_file(Path("slug.uid.md")) == "uid"