test_canvas.py 21 KB

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