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 42 43 44 45 46 47 48 49 50 51 52
|
from celery.app.annotations import MapAnnotation, prepare
from celery.utils.imports import qualname
class MyAnnotation:
foo = 65
class AnnotationCase:
def setup_method(self):
@self.app.task(shared=False)
def add(x, y):
return x + y
self.add = add
@self.app.task(shared=False)
def mul(x, y):
return x * y
self.mul = mul
class test_MapAnnotation(AnnotationCase):
def test_annotate(self):
x = MapAnnotation({self.add.name: {'foo': 1}})
assert x.annotate(self.add) == {'foo': 1}
assert x.annotate(self.mul) is None
def test_annotate_any(self):
x = MapAnnotation({'*': {'foo': 2}})
assert x.annotate_any() == {'foo': 2}
x = MapAnnotation()
assert x.annotate_any() is None
class test_prepare(AnnotationCase):
def test_dict_to_MapAnnotation(self):
x = prepare({self.add.name: {'foo': 3}})
assert isinstance(x[0], MapAnnotation)
def test_returns_list(self):
assert prepare(1) == [1]
assert prepare([1]) == [1]
assert prepare((1,)) == [1]
assert prepare(None) == ()
def test_evalutes_qualnames(self):
assert prepare(qualname(MyAnnotation))[0]().foo == 65
assert prepare([qualname(MyAnnotation)])[0]().foo == 65
|