test_canvas.py 20 KB

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