File: test_comp_with_appdirs.py

package info (click to toggle)
platformdirs 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: python: 1,702; sh: 7; makefile: 4
file content (73 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download | duplicates (2)
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
from __future__ import annotations

import sys
from inspect import getmembers, isfunction
from typing import Any

import appdirs
import pytest

import platformdirs


def test_has_backward_compatible_class() -> None:
    from platformdirs import AppDirs  # noqa: PLC0415

    assert AppDirs is platformdirs.PlatformDirs


def test_has_all_functions() -> None:
    # Get all public function names from appdirs
    appdirs_function_names = [f[0] for f in getmembers(appdirs, isfunction) if not f[0].startswith("_")]

    # Exception will be raised if any appdirs functions aren't in platformdirs.
    for function_name in appdirs_function_names:
        getattr(platformdirs, function_name)


def test_has_all_properties() -> None:
    # Get names of all the properties of appdirs.AppDirs
    appdirs_property_names = [p[0] for p in getmembers(appdirs.AppDirs, lambda member: isinstance(member, property))]

    # Exception will be raised if any appdirs.AppDirs properties aren't in platformdirs.AppDirs
    for property_name in appdirs_property_names:
        getattr(platformdirs.AppDirs, property_name)


@pytest.mark.parametrize(
    "params",
    [
        {},
        {"appname": "foo"},
        {"appname": "foo", "appauthor": "bar"},
        {"appname": "foo", "appauthor": "bar", "version": "v1.0"},
    ],
    ids=[
        "no_args",
        "app_name",
        "app_name_with_app_author",
        "app_name_author_version",
    ],
)
def test_compatibility(params: dict[str, Any], func: str) -> None:
    # Only test functions that are part of appdirs
    if getattr(appdirs, func, None) is None:
        pytest.skip(f"`{func}` does not exist in `appdirs`")

    if sys.platform == "darwin":
        msg = {  # pragma: no cover
            "user_log_dir": "without appname produces NoneType error",
        }
        if func in msg:  # pragma: no cover
            pytest.skip(f"`appdirs.{func}` {msg[func]} on macOS")  # pragma: no cover
    elif sys.platform != "win32":
        msg = {  # pragma: no cover
            "user_log_dir": "Uses XDG_STATE_DIR instead of appdirs.user_data_dir per the XDG spec",
        }
        if func in msg:  # pragma: no cover
            pytest.skip(f"`appdirs.{func}` {msg[func]} on Unix")  # pragma: no cover

    new = getattr(platformdirs, func)(*params)
    old = getattr(appdirs, func)(*params)

    assert new == old.rstrip("/")