File: test_dependencies.py

package info (click to toggle)
python-apischema 0.18.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,636 kB
  • sloc: python: 15,281; makefile: 3; sh: 2
file content (41 lines) | stat: -rw-r--r-- 994 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
import pytest

from apischema.validation.dependencies import find_all_dependencies, find_dependencies


def a_equal_b(param):
    assert param.a == param.b


@pytest.mark.parametrize("func, deps", [(a_equal_b, {"a", "b"}), (int, set())])
def test_find_dependencies(func, deps):
    assert find_dependencies(func) == deps


def test_no_parameter():
    with pytest.raises(TypeError):
        find_dependencies(lambda: None)


def test_find_end_dependencies():
    class Test:
        class_var = ""

        def __init__(self):
            self.a = 0
            self.b = {}

        def pseudo_validate(self):
            if self.a not in self.method(0):
                yield self.class_var

        def method(self, arg):
            res = list(self.c)
            if len(res) < arg:
                return self.method(arg - 1)

        @property
        def c(self):
            return self.b.values()

    assert find_all_dependencies(Test, Test.pseudo_validate) == {"a", "b", "class_var"}