test_canvas.py 21 KB

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