test_canvas.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. from __future__ import absolute_import, unicode_literals
  2. import json
  3. import pytest
  4. from case import MagicMock, Mock
  5. from celery._state import _task_stack
  6. from celery.canvas import (
  7. Signature,
  8. chain,
  9. _chain,
  10. group,
  11. chord,
  12. signature,
  13. xmap,
  14. xstarmap,
  15. chunks,
  16. _maybe_group,
  17. maybe_signature,
  18. maybe_unroll_group,
  19. )
  20. from celery.result import AsyncResult, GroupResult, EagerResult
  21. SIG = Signature({
  22. 'task': 'TASK',
  23. 'args': ('A1',),
  24. 'kwargs': {'K1': 'V1'},
  25. 'options': {'task_id': 'TASK_ID'},
  26. 'subtask_type': ''},
  27. )
  28. class test_maybe_unroll_group:
  29. def test_when_no_len_and_no_length_hint(self):
  30. g = MagicMock(name='group')
  31. g.tasks.__len__.side_effect = TypeError()
  32. g.tasks.__length_hint__ = Mock()
  33. g.tasks.__length_hint__.return_value = 0
  34. assert maybe_unroll_group(g) is g
  35. g.tasks.__length_hint__.side_effect = AttributeError()
  36. assert maybe_unroll_group(g) is g
  37. class CanvasCase:
  38. def setup(self):
  39. @self.app.task(shared=False)
  40. def add(x, y):
  41. return x + y
  42. self.add = add
  43. @self.app.task(shared=False)
  44. def mul(x, y):
  45. return x * y
  46. self.mul = mul
  47. @self.app.task(shared=False)
  48. def div(x, y):
  49. return x / y
  50. self.div = div
  51. class test_Signature(CanvasCase):
  52. def test_getitem_property_class(self):
  53. assert Signature.task
  54. assert Signature.args
  55. assert Signature.kwargs
  56. assert Signature.options
  57. assert Signature.subtask_type
  58. def test_getitem_property(self):
  59. assert SIG.task == 'TASK'
  60. assert SIG.args == ('A1',)
  61. assert SIG.kwargs == {'K1': 'V1'}
  62. assert SIG.options == {'task_id': 'TASK_ID'}
  63. assert SIG.subtask_type == ''
  64. def test_call(self):
  65. x = Signature('foo', (1, 2), {'arg1': 33}, app=self.app)
  66. x.type = Mock(name='type')
  67. x(3, 4, arg2=66)
  68. x.type.assert_called_with(3, 4, 1, 2, arg1=33, arg2=66)
  69. def test_link_on_scalar(self):
  70. x = Signature('TASK', link=Signature('B'))
  71. assert x.options['link']
  72. x.link(Signature('C'))
  73. assert isinstance(x.options['link'], list)
  74. assert Signature('B') in x.options['link']
  75. assert Signature('C') in x.options['link']
  76. def test_json(self):
  77. x = Signature('TASK', link=Signature('B', app=self.app), app=self.app)
  78. assert x.__json__() == dict(x)
  79. @pytest.mark.usefixtures('depends_on_current_app')
  80. def test_reduce(self):
  81. x = Signature('TASK', (2, 4), app=self.app)
  82. fun, args = x.__reduce__()
  83. assert fun(*args) == x
  84. def test_replace(self):
  85. x = Signature('TASK', ('A'), {})
  86. assert x.replace(args=('B',)).args == ('B',)
  87. assert x.replace(kwargs={'FOO': 'BAR'}).kwargs == {
  88. 'FOO': 'BAR',
  89. }
  90. assert x.replace(options={'task_id': '123'}).options == {
  91. 'task_id': '123',
  92. }
  93. def test_set(self):
  94. assert Signature('TASK', x=1).set(task_id='2').options == {
  95. 'x': 1, 'task_id': '2',
  96. }
  97. def test_link(self):
  98. x = signature(SIG)
  99. x.link(SIG)
  100. x.link(SIG)
  101. assert SIG in x.options['link']
  102. assert len(x.options['link']) == 1
  103. def test_link_error(self):
  104. x = signature(SIG)
  105. x.link_error(SIG)
  106. x.link_error(SIG)
  107. assert SIG in x.options['link_error']
  108. assert len(x.options['link_error']) == 1
  109. def test_flatten_links(self):
  110. tasks = [self.add.s(2, 2), self.mul.s(4), self.div.s(2)]
  111. tasks[0].link(tasks[1])
  112. tasks[1].link(tasks[2])
  113. assert tasks[0].flatten_links() == tasks
  114. def test_OR(self):
  115. x = self.add.s(2, 2) | self.mul.s(4)
  116. assert isinstance(x, _chain)
  117. y = self.add.s(4, 4) | self.div.s(2)
  118. z = x | y
  119. assert isinstance(y, _chain)
  120. assert isinstance(z, _chain)
  121. assert len(z.tasks) == 4
  122. with pytest.raises(TypeError):
  123. x | 10
  124. ax = self.add.s(2, 2) | (self.add.s(4) | self.add.s(8))
  125. assert isinstance(ax, _chain)
  126. assert len(ax.tasks), 3 == 'consolidates chain to chain'
  127. def test_INVERT(self):
  128. x = self.add.s(2, 2)
  129. x.apply_async = Mock()
  130. x.apply_async.return_value = Mock()
  131. x.apply_async.return_value.get = Mock()
  132. x.apply_async.return_value.get.return_value = 4
  133. assert ~x == 4
  134. x.apply_async.assert_called()
  135. def test_merge_immutable(self):
  136. x = self.add.si(2, 2, foo=1)
  137. args, kwargs, options = x._merge((4,), {'bar': 2}, {'task_id': 3})
  138. assert args == (2, 2)
  139. assert kwargs == {'foo': 1}
  140. assert options == {'task_id': 3}
  141. def test_set_immutable(self):
  142. x = self.add.s(2, 2)
  143. assert not x.immutable
  144. x.set(immutable=True)
  145. assert x.immutable
  146. x.set(immutable=False)
  147. assert not x.immutable
  148. def test_election(self):
  149. x = self.add.s(2, 2)
  150. x.freeze('foo')
  151. x.type.app.control = Mock()
  152. r = x.election()
  153. x.type.app.control.election.assert_called()
  154. assert r.id == 'foo'
  155. def test_AsyncResult_when_not_registered(self):
  156. s = signature('xxx.not.registered', app=self.app)
  157. assert s.AsyncResult
  158. def test_apply_async_when_not_registered(self):
  159. s = signature('xxx.not.registered', app=self.app)
  160. assert s._apply_async
  161. class test_xmap_xstarmap(CanvasCase):
  162. def test_apply(self):
  163. for type, attr in [(xmap, 'map'), (xstarmap, 'starmap')]:
  164. args = [(i, i) for i in range(10)]
  165. s = getattr(self.add, attr)(args)
  166. s.type = Mock()
  167. s.apply_async(foo=1)
  168. s.type.apply_async.assert_called_with(
  169. (), {'task': self.add.s(), 'it': args}, foo=1,
  170. route_name=self.add.name,
  171. )
  172. assert type.from_dict(dict(s)) == s
  173. assert repr(s)
  174. class test_chunks(CanvasCase):
  175. def test_chunks(self):
  176. x = self.add.chunks(range(100), 10)
  177. assert dict(chunks.from_dict(dict(x), app=self.app)) == dict(x)
  178. assert x.group()
  179. assert len(x.group().tasks) == 10
  180. x.group = Mock()
  181. gr = x.group.return_value = Mock()
  182. x.apply_async()
  183. gr.apply_async.assert_called_with((), {}, route_name=self.add.name)
  184. gr.apply_async.reset_mock()
  185. x()
  186. gr.apply_async.assert_called_with((), {}, route_name=self.add.name)
  187. self.app.conf.task_always_eager = True
  188. chunks.apply_chunks(app=self.app, **x['kwargs'])
  189. class test_chain(CanvasCase):
  190. def test_clone_preserves_state(self):
  191. x = chain(self.add.s(i, i) for i in range(10))
  192. assert x.clone().tasks == x.tasks
  193. assert x.clone().kwargs == x.kwargs
  194. assert x.clone().args == x.args
  195. def test_repr(self):
  196. x = self.add.s(2, 2) | self.add.s(2)
  197. assert repr(x) == '%s(2, 2) | add(2)' % (self.add.name,)
  198. def test_apply_async(self):
  199. c = self.add.s(2, 2) | self.add.s(4) | self.add.s(8)
  200. result = c.apply_async()
  201. assert result.parent
  202. assert result.parent.parent
  203. assert result.parent.parent.parent is None
  204. def test_splices_chains(self):
  205. c = chain(
  206. self.add.s(5, 5),
  207. chain(self.add.s(6), self.add.s(7), self.add.s(8), app=self.app),
  208. app=self.app,
  209. )
  210. c.freeze()
  211. tasks, _ = c._frozen
  212. assert len(tasks) == 4
  213. def test_from_dict_no_tasks(self):
  214. assert chain.from_dict(dict(chain(app=self.app)), app=self.app)
  215. def test_from_dict_full_subtasks(self):
  216. c = chain(self.add.si(1, 2), self.add.si(3, 4), self.add.si(5, 6))
  217. serialized = json.loads(json.dumps(c))
  218. deserialized = chain.from_dict(serialized)
  219. for task in deserialized.tasks:
  220. assert isinstance(task, Signature)
  221. @pytest.mark.usefixtures('depends_on_current_app')
  222. def test_app_falls_back_to_default(self):
  223. from celery._state import current_app
  224. assert chain().app is current_app
  225. def test_handles_dicts(self):
  226. c = chain(
  227. self.add.s(5, 5), dict(self.add.s(8)), app=self.app,
  228. )
  229. c.freeze()
  230. tasks, _ = c._frozen
  231. for task in tasks:
  232. assert isinstance(task, Signature)
  233. assert task.app is self.app
  234. def test_group_to_chord(self):
  235. c = (
  236. self.add.s(5) |
  237. group([self.add.s(i, i) for i in range(5)], app=self.app) |
  238. self.add.s(10) |
  239. self.add.s(20) |
  240. self.add.s(30)
  241. )
  242. c._use_link = True
  243. tasks, results = c.prepare_steps((), c.tasks)
  244. assert tasks[-1].args[0] == 5
  245. assert isinstance(tasks[-2], chord)
  246. assert len(tasks[-2].tasks) == 5
  247. body = tasks[-2].body
  248. assert len(body.tasks) == 3
  249. assert body.tasks[0].args[0] == 10
  250. assert body.tasks[1].args[0] == 20
  251. assert body.tasks[2].args[0] == 30
  252. c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
  253. c2._use_link = True
  254. tasks2, _ = c2.prepare_steps((), c2.tasks)
  255. assert isinstance(tasks2[0], group)
  256. def test_group_to_chord__protocol_2__or(self):
  257. c = (
  258. group([self.add.s(i, i) for i in range(5)], app=self.app) |
  259. self.add.s(10) |
  260. self.add.s(20) |
  261. self.add.s(30)
  262. )
  263. assert isinstance(c, chord)
  264. def test_group_to_chord__protocol_2(self):
  265. c = chain(
  266. group([self.add.s(i, i) for i in range(5)], app=self.app),
  267. self.add.s(10),
  268. self.add.s(20),
  269. self.add.s(30)
  270. )
  271. assert isinstance(c, chord)
  272. assert isinstance(c.body, _chain)
  273. assert len(c.body.tasks) == 3
  274. c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
  275. c2._use_link = False
  276. tasks2, _ = c2.prepare_steps((), c2.tasks)
  277. assert isinstance(tasks2[0], group)
  278. def test_apply_options(self):
  279. class static(Signature):
  280. def clone(self, *args, **kwargs):
  281. return self
  282. def s(*args, **kwargs):
  283. return static(self.add, args, kwargs, type=self.add, app=self.app)
  284. c = s(2, 2) | s(4) | s(8)
  285. r1 = c.apply_async(task_id='some_id')
  286. assert r1.id == 'some_id'
  287. c.apply_async(group_id='some_group_id')
  288. assert c.tasks[-1].options['group_id'] == 'some_group_id'
  289. c.apply_async(chord='some_chord_id')
  290. assert c.tasks[-1].options['chord'] == 'some_chord_id'
  291. c.apply_async(link=[s(32)])
  292. assert c.tasks[-1].options['link'] == [s(32)]
  293. c.apply_async(link_error=[s('error')])
  294. for task in c.tasks:
  295. assert task.options['link_error'] == [s('error')]
  296. def test_reverse(self):
  297. x = self.add.s(2, 2) | self.add.s(2)
  298. assert isinstance(signature(x), _chain)
  299. assert isinstance(signature(dict(x)), _chain)
  300. def test_always_eager(self):
  301. self.app.conf.task_always_eager = True
  302. assert ~(self.add.s(4, 4) | self.add.s(8)) == 16
  303. def test_apply(self):
  304. x = chain(self.add.s(4, 4), self.add.s(8), self.add.s(10))
  305. res = x.apply()
  306. assert isinstance(res, EagerResult)
  307. assert res.get() == 26
  308. assert res.parent.get() == 16
  309. assert res.parent.parent.get() == 8
  310. assert res.parent.parent.parent is None
  311. def test_empty_chain_returns_none(self):
  312. assert chain(app=self.app)() is None
  313. assert chain(app=self.app).apply_async() is None
  314. def test_call_no_tasks(self):
  315. x = chain()
  316. assert not x()
  317. def test_call_with_tasks(self):
  318. x = self.add.s(2, 2) | self.add.s(4)
  319. x.apply_async = Mock()
  320. x(2, 2, foo=1)
  321. x.apply_async.assert_called_with((2, 2), {'foo': 1})
  322. def test_from_dict_no_args__with_args(self):
  323. x = dict(self.add.s(2, 2) | self.add.s(4))
  324. x['args'] = None
  325. assert isinstance(chain.from_dict(x), _chain)
  326. x['args'] = (2,)
  327. assert isinstance(chain.from_dict(x), _chain)
  328. def test_accepts_generator_argument(self):
  329. x = chain(self.add.s(i) for i in range(10))
  330. assert x.tasks[0].type, self.add
  331. assert x.type
  332. def test_chord_sets_result_parent(self):
  333. g = (self.add.s(0, 0) |
  334. group(self.add.s(i, i) for i in range(1, 10)) |
  335. self.add.s(2, 2) |
  336. self.add.s(4, 4))
  337. res = g.freeze()
  338. assert isinstance(res, AsyncResult)
  339. assert not isinstance(res, GroupResult)
  340. assert isinstance(res.parent, AsyncResult)
  341. assert not isinstance(res.parent, GroupResult)
  342. assert isinstance(res.parent.parent, GroupResult)
  343. assert isinstance(res.parent.parent.parent, AsyncResult)
  344. assert not isinstance(res.parent.parent.parent, GroupResult)
  345. assert res.parent.parent.parent.parent is None
  346. seen = set()
  347. node = res
  348. while node:
  349. assert node.id not in seen
  350. seen.add(node.id)
  351. node = node.parent
  352. class test_group(CanvasCase):
  353. def test_repr(self):
  354. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  355. assert repr(x)
  356. def test_reverse(self):
  357. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  358. assert isinstance(signature(x), group)
  359. assert isinstance(signature(dict(x)), group)
  360. def test_cannot_link_on_group(self):
  361. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  362. with pytest.raises(TypeError):
  363. x.apply_async(link=self.add.s(2, 2))
  364. def test_cannot_link_error_on_group(self):
  365. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  366. with pytest.raises(TypeError):
  367. x.apply_async(link_error=self.add.s(2, 2))
  368. def test_group_with_group_argument(self):
  369. g1 = group(self.add.s(2, 2), self.add.s(4, 4), app=self.app)
  370. g2 = group(g1, app=self.app)
  371. assert g2.tasks is g1.tasks
  372. def test_maybe_group_sig(self):
  373. assert _maybe_group(self.add.s(2, 2), self.app) == [self.add.s(2, 2)]
  374. def test_apply(self):
  375. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  376. res = x.apply()
  377. assert res.get(), [8 == 16]
  378. def test_apply_async(self):
  379. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  380. x.apply_async()
  381. def test_prepare_with_dict(self):
  382. x = group([self.add.s(4, 4), dict(self.add.s(8, 8))], app=self.app)
  383. x.apply_async()
  384. def test_group_in_group(self):
  385. g1 = group(self.add.s(2, 2), self.add.s(4, 4), app=self.app)
  386. g2 = group(self.add.s(8, 8), g1, self.add.s(16, 16), app=self.app)
  387. g2.apply_async()
  388. def test_set_immutable(self):
  389. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  390. g1.set_immutable(True)
  391. for task in g1.tasks:
  392. task.set_immutable.assert_called_with(True)
  393. def test_link(self):
  394. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  395. sig = Mock(name='sig')
  396. g1.link(sig)
  397. g1.tasks[0].link.assert_called_with(sig.clone().set(immutable=True))
  398. def test_link_error(self):
  399. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  400. sig = Mock(name='sig')
  401. g1.link_error(sig)
  402. g1.tasks[0].link_error.assert_called_with(
  403. sig.clone().set(immutable=True),
  404. )
  405. def test_apply_empty(self):
  406. x = group(app=self.app)
  407. x.apply()
  408. res = x.apply_async()
  409. assert res
  410. assert not res.results
  411. def test_apply_async_with_parent(self):
  412. _task_stack.push(self.add)
  413. try:
  414. self.add.push_request(called_directly=False)
  415. try:
  416. assert not self.add.request.children
  417. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  418. res = x()
  419. assert self.add.request.children
  420. assert res in self.add.request.children
  421. assert len(self.add.request.children) == 1
  422. finally:
  423. self.add.pop_request()
  424. finally:
  425. _task_stack.pop()
  426. def test_from_dict(self):
  427. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  428. x['args'] = (2, 2)
  429. assert group.from_dict(dict(x))
  430. x['args'] = None
  431. assert group.from_dict(dict(x))
  432. def test_call_empty_group(self):
  433. x = group(app=self.app)
  434. assert not len(x())
  435. x.delay()
  436. x.apply_async()
  437. x()
  438. def test_skew(self):
  439. g = group([self.add.s(i, i) for i in range(10)])
  440. g.skew(start=1, stop=10, step=1)
  441. for i, task in enumerate(g.tasks):
  442. assert task.options['countdown'] == i + 1
  443. def test_iter(self):
  444. g = group([self.add.s(i, i) for i in range(10)])
  445. assert list(iter(g)) == list(g.keys())
  446. @staticmethod
  447. def helper_test_get_delay(result):
  448. import time
  449. t0 = time.time()
  450. while not result.ready():
  451. time.sleep(0.01)
  452. if time.time() - t0 > 1:
  453. return None
  454. return result.get()
  455. def test_kwargs_direct(self):
  456. res = [self.add(x=1, y=1), self.add(x=1, y=1)]
  457. assert res == [2, 2]
  458. def test_kwargs_apply(self):
  459. x = group([self.add.s(), self.add.s()])
  460. res = x.apply(kwargs=dict(x=1, y=1)).get()
  461. assert res == [2, 2]
  462. def test_kwargs_apply_async(self):
  463. self.app.conf.task_always_eager = True
  464. x = group([self.add.s(), self.add.s()])
  465. res = self.helper_test_get_delay(x.apply_async(kwargs=dict(x=1, y=1)))
  466. assert res == [2, 2]
  467. def test_kwargs_delay(self):
  468. self.app.conf.task_always_eager = True
  469. x = group([self.add.s(), self.add.s()])
  470. res = self.helper_test_get_delay(x.delay(x=1, y=1))
  471. assert res == [2, 2]
  472. def test_kwargs_delay_partial(self):
  473. self.app.conf.task_always_eager = True
  474. x = group([self.add.s(1), self.add.s(x=1)])
  475. res = self.helper_test_get_delay(x.delay(y=1))
  476. assert res == [2, 2]
  477. class test_chord(CanvasCase):
  478. def test_reverse(self):
  479. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  480. assert isinstance(signature(x), chord)
  481. assert isinstance(signature(dict(x)), chord)
  482. def test_clone_clones_body(self):
  483. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  484. y = x.clone()
  485. assert x.kwargs['body'] is not y.kwargs['body']
  486. y.kwargs.pop('body')
  487. z = y.clone()
  488. assert z.kwargs.get('body') is None
  489. def test_argument_is_group(self):
  490. x = chord(group(self.add.s(2, 2), self.add.s(4, 4), app=self.app))
  491. assert x.tasks
  492. def test_app_when_app(self):
  493. app = Mock(name='app')
  494. x = chord([self.add.s(4, 4)], app=app)
  495. assert x.app is app
  496. def test_app_when_app_in_task(self):
  497. t1 = Mock(name='t1')
  498. t2 = Mock(name='t2')
  499. x = chord([t1, self.add.s(4, 4)])
  500. assert x.app is x.tasks[0].app
  501. t1.app = None
  502. x = chord([t1], body=t2)
  503. assert x.app is t2._app
  504. def test_app_when_header_is_empty(self):
  505. x = chord([], self.add.s(4, 4))
  506. assert x.app is self.add.app
  507. @pytest.mark.usefixtures('depends_on_current_app')
  508. def test_app_fallback_to_current(self):
  509. from celery._state import current_app
  510. t1 = Mock(name='t1')
  511. t1.app = t1._app = None
  512. x = chord([t1], body=t1)
  513. assert x.app is current_app
  514. def test_set_immutable(self):
  515. x = chord([Mock(name='t1'), Mock(name='t2')], app=self.app)
  516. x.set_immutable(True)
  517. def test_links_to_body(self):
  518. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  519. x.link(self.div.s(2))
  520. assert not x.options.get('link')
  521. assert x.kwargs['body'].options['link']
  522. x.link_error(self.div.s(2))
  523. assert not x.options.get('link_error')
  524. assert x.kwargs['body'].options['link_error']
  525. assert x.tasks
  526. assert x.body
  527. def test_repr(self):
  528. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  529. assert repr(x)
  530. x.kwargs['body'] = None
  531. assert 'without body' in repr(x)
  532. def test_freeze_tasks_is_not_group(self):
  533. x = chord([self.add.s(2, 2)], body=self.add.s(), app=self.app)
  534. x.freeze()
  535. x.tasks = [self.add.s(2, 2)]
  536. x.freeze()
  537. class test_maybe_signature(CanvasCase):
  538. def test_is_None(self):
  539. assert maybe_signature(None, app=self.app) is None
  540. def test_is_dict(self):
  541. assert isinstance(maybe_signature(dict(self.add.s()), app=self.app),
  542. Signature)
  543. def test_when_sig(self):
  544. s = self.add.s()
  545. assert maybe_signature(s, app=self.app) is s