File: test_utils.py

package info (click to toggle)
python-limits 4.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,064 kB
  • sloc: python: 7,833; makefile: 162; sh: 59
file content (34 lines) | stat: -rw-r--r-- 920 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
from __future__ import annotations

import pytest
from packaging.version import Version

from limits.errors import ConfigurationError
from limits.util import LazyDependency


def test_lazy_dependency_found():
    class Demo(LazyDependency):
        DEPENDENCIES = ["redis"]

    d = Demo()
    assert d.dependencies["redis"].version_found


def test_lazy_dependency_version_low():
    class Demo(LazyDependency):
        DEPENDENCIES = {
            "redis": Version("999.999"),
            "maythisneverexist": Version("1.0"),
        }

    d = Demo()
    with pytest.raises(
        ConfigurationError,
        match="minimum version of 999.999 for 'redis' could not be found",
    ):
        assert d.dependencies["redis"].version_found
    with pytest.raises(
        ConfigurationError, match="'maythisneverexist' prerequisite not available"
    ):
        assert d.dependencies["maythisneverexist"].version_found