File: test_utils.py

package info (click to toggle)
flask-dance 7.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 932 kB
  • sloc: python: 6,342; makefile: 162
file content (33 lines) | stat: -rw-r--r-- 686 bytes parent folder | download | duplicates (3)
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
import pytest

from flask_dance.utils import FakeCache, first, getattrd


def test_first():
    assert first([1, 2, 3]) == 1
    assert first([None, 2, 3]) == 2
    assert first([None, 0, False, [], {}]) == None
    assert first([None, 0, False, [], {}], default=42) == 42
    first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0) == 4


class C:
    d = "foo"


class B:
    C = C


class A:
    B = B


def test_getattrd():
    assert A.B.C.d == "foo"
    assert getattrd(A, "B.C.d") == "foo"
    assert getattrd(A, "B") == B
    assert getattrd(A, "B", default=42) == B
    assert getattrd(A, "Q", default=42) == 42
    with pytest.raises(AttributeError):
        assert getattrd(A, "Q")