Debian Codegraph @

t/unit/app/test_annotations.py

raw
1 from celery.app.annotations import MapAnnotation, prepare
2 from celery.utils.imports import qualname
3
4
5 class MyAnnotation:
6 foo = 65
7
8
9 class AnnotationCase:
10
11 def setup_method(self):
12 @self.app.task(shared=False)
13 def add(x, y):
14 return x + y
15 self.add = add
16
17 @self.app.task(shared=False)
18 def mul(x, y):
19 return x * y
20 self.mul = mul
21
22
23 class test_MapAnnotation(AnnotationCase):
24
25 def test_annotate(self):
26 x = MapAnnotation({self.add.name: {'foo': 1}})
27 assert x.annotate(self.add) == {'foo': 1}
28 assert x.annotate(self.mul) is None
29
30 def test_annotate_any(self):
31 x = MapAnnotation({'*': {'foo': 2}})
32 assert x.annotate_any() == {'foo': 2}
33
34 x = MapAnnotation()
35 assert x.annotate_any() is None
36
37
38 class test_prepare(AnnotationCase):
39
40 def test_dict_to_MapAnnotation(self):
41 x = prepare({self.add.name: {'foo': 3}})
42 assert isinstance(x[0], MapAnnotation)
43
44 def test_returns_list(self):
45 assert prepare(1) == [1]
46 assert prepare([1]) == [1]
47 assert prepare((1,)) == [1]
48 assert prepare(None) == ()
49
50 def test_evalutes_qualnames(self):
51 assert prepare(qualname(MyAnnotation))[0]().foo == 65
52 assert prepare([qualname(MyAnnotation)])[0]().foo == 65