Debian Codegraph @

tests/test_depends_hashable.py

raw
1 # This is more or less a workaround to make Depends and Security hashable
2 # as other tools that use them depend on that
3 # Ref: https://github.com/fastapi/fastapi/pull/14320
4
5 from fastapi import Depends, Security
6
7
8 def dep():
9 pass
10
11
12 def test_depends_hashable():
13 dep() # just for coverage
14 d1 = Depends(dep)
15 d2 = Depends(dep)
16 d3 = Depends(dep, scope="function")
17 d4 = Depends(dep, scope="function")
18
19 s1 = Security(dep)
20 s2 = Security(dep)
21
22 assert hash(d1) == hash(d2)
23 assert hash(s1) == hash(s2)
24 assert hash(d1) != hash(d3)
25 assert hash(d3) == hash(d4)