home · contact · privacy
Minor tests refactoring.
[plomtask] / tests / processes.py
1 """Test Processes module."""
2 from typing import Any
3 from tests.utils import (TestCaseSansDB, TestCaseWithDB, TestCaseWithServer,
4                          Expected)
5 from plomtask.processes import Process, ProcessStep
6 from plomtask.conditions import Condition
7 from plomtask.exceptions import NotFoundException
8
9
10 class TestsSansDB(TestCaseSansDB):
11     """Module tests not requiring DB setup."""
12     checked_class = Process
13
14
15 class TestsSansDBProcessStep(TestCaseSansDB):
16     """Module tests not requiring DB setup."""
17     checked_class = ProcessStep
18     default_init_kwargs = {'owner_id': 2, 'step_process_id': 3,
19                            'parent_step_id': 4}
20
21
22 class TestsWithDB(TestCaseWithDB):
23     """Module tests requiring DB setup."""
24     checked_class = Process
25
26     def three_processes(self) -> tuple[Process, Process, Process]:
27         """Return three saved processes."""
28         p1, p2, p3 = Process(None), Process(None), Process(None)
29         for p in [p1, p2, p3]:
30             p.save(self.db_conn)
31         return p1, p2, p3
32
33     def p_of_conditions(self) -> tuple[Process, list[Condition],
34                                        list[Condition], list[Condition]]:
35         """Return Process and its three Condition sets."""
36         p = Process(None)
37         c1, c2, c3 = Condition(None), Condition(None), Condition(None)
38         for c in [c1, c2, c3]:
39             c.save(self.db_conn)
40         assert isinstance(c1.id_, int)
41         assert isinstance(c2.id_, int)
42         assert isinstance(c3.id_, int)
43         set_1 = [c1, c2]
44         set_2 = [c2, c3]
45         set_3 = [c1, c3]
46         conds = [c.id_ for c in set_1 if isinstance(c.id_, int)]
47         enables = [c.id_ for c in set_2 if isinstance(c.id_, int)]
48         disables = [c.id_ for c in set_3 if isinstance(c.id_, int)]
49         p.set_condition_relations(self.db_conn, conds, [], enables, disables)
50         p.save(self.db_conn)
51         return p, set_1, set_2, set_3
52
53     def test_Process_conditions_saving(self) -> None:
54         """Test .save/.save_core."""
55         p, set1, set2, set3 = self.p_of_conditions()
56         assert p.id_ is not None
57         r = Process.by_id(self.db_conn, p.id_)
58         self.assertEqual(sorted(r.conditions), sorted(set1))
59         self.assertEqual(sorted(r.enables), sorted(set2))
60         self.assertEqual(sorted(r.disables), sorted(set3))
61
62     def test_from_table_row(self) -> None:
63         """Test .from_table_row() properly reads in class from DB."""
64         super().test_from_table_row()
65         p, set1, set2, set3 = self.p_of_conditions()
66         p.save(self.db_conn)
67         assert isinstance(p.id_, int)
68         for row in self.db_conn.row_where(self.checked_class.table_name,
69                                           'id', p.id_):
70             r = Process.from_table_row(self.db_conn, row)
71             self.assertEqual(sorted(r.conditions), sorted(set1))
72             self.assertEqual(sorted(r.enables), sorted(set2))
73             self.assertEqual(sorted(r.disables), sorted(set3))
74
75     # def test_Process_steps(self) -> None:
76     #     """Test addition, nesting, and non-recursion of ProcessSteps"""
77     #     # pylint: disable=too-many-locals
78     #     # pylint: disable=too-many-statements
79     #     p1, p2, p3 = self.three_processes()
80     #     assert isinstance(p1.id_, int)
81     #     assert isinstance(p2.id_, int)
82     #     assert isinstance(p3.id_, int)
83     #     steps_p1: list[ProcessStep] = []
84     #     # add step of process p2 as first (top-level) step to p1
85     #     s_p2_to_p1 = ProcessStep(None, p1.id_, p2.id_, None)
86     #     steps_p1 += [s_p2_to_p1]
87     #     p1.set_steps(self.db_conn, steps_p1)
88     #     p1_dict: dict[int, ProcessStepsNode] = {}
89     #     p1_dict[1] = ProcessStepsNode(p2, None, True, {})
90     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
91     #     # add step of process p3 as second (top-level) step to p1
92     #     s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None)
93     #     steps_p1 += [s_p3_to_p1]
94     #     p1.set_steps(self.db_conn, steps_p1)
95     #     p1_dict[2] = ProcessStepsNode(p3, None, True, {})
96     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
97     #     # add step of process p3 as first (top-level) step to p2,
98     #     steps_p2: list[ProcessStep] = []
99     #     s_p3_to_p2 = ProcessStep(None, p2.id_, p3.id_, None)
100     #     steps_p2 += [s_p3_to_p2]
101     #     p2.set_steps(self.db_conn, steps_p2)
102     #     # expect it as implicit sub-step of p1's second (p3) step
103     #     p2_dict = {3: ProcessStepsNode(p3, None, False, {})}
104     #     p1_dict[1].steps[3] = p2_dict[3]
105     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
106     #     # add step of process p2 as explicit sub-step to p1's second sub-step
107     #     s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_)
108     #     steps_p1 += [s_p2_to_p1_first]
109     #     p1.set_steps(self.db_conn, steps_p1)
110     #     seen_3 = ProcessStepsNode(p3, None, False, {}, False)
111     #     p1_dict[1].steps[3].seen = True
112     #     p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True,
113     #                                            {3: seen_3})
114     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
115     #     # add step of process p3 as explicit sub-step to non-existing p1
116     #     # sub-step (of id=999), expect it to become another p1 top-level step
117     #     s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999)
118     #     steps_p1 += [s_p3_to_p1_999]
119     #     p1.set_steps(self.db_conn, steps_p1)
120     #     p1_dict[5] = ProcessStepsNode(p3, None, True, {})
121     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
122     #     # add step of process p3 as explicit sub-step to p1's implicit p3
123     #     # sub-step, expect it to become another p1 top-level step
124     #     s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_,
125     #                                      s_p3_to_p2.id_)
126     #     steps_p1 += [s_p3_to_p1_impl_p3]
127     #     p1.set_steps(self.db_conn, steps_p1)
128     #     p1_dict[6] = ProcessStepsNode(p3, None, True, {})
129     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
130     #     self.assertEqual(p1.used_as_step_by(self.db_conn), [])
131     #     self.assertEqual(p2.used_as_step_by(self.db_conn), [p1])
132     #     self.assertEqual(p3.used_as_step_by(self.db_conn), [p1, p2])
133     #     # # add step of process p3 as explicit sub-step to p1's first
134     #     # # sub-step, expect it to eliminate implicit p3 sub-step
135     #     # s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_,
136     #     #                                         s_p2_to_p1.id_)
137     #     # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})}
138     #     # p1_dict[2].steps[4].steps[3].seen = False
139     #     # steps_p1 += [s_p3_to_p1_first_explicit]
140     #     # p1.set_steps(self.db_conn, steps_p1)
141     #     # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
142     #     # ensure implicit steps non-top explicit steps are shown
143     #     s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_)
144     #     steps_p2 += [s_p3_to_p2_first]
145     #     p2.set_steps(self.db_conn, steps_p2)
146     #     p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {},
147     #                                                     True)
148     #     p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(
149     #             p3, 3, False, {}, False)
150     #     self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
151     #     # ensure suppressed step nodes are hidden
152     #     assert isinstance(s_p3_to_p2.id_, int)
153     #     p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_])
154     #     p1_dict[1].steps[3].steps = {}
155     #     p1_dict[1].steps[3].is_suppressed = True
156     #     p1_dict[2].steps[4].steps[3].steps = {}
157     #     p1_dict[2].steps[4].steps[3].is_suppressed = True
158     #     self.assertEqual(p1.get_steps(self.db_conn), p1_dict)
159
160     def test_Process_conditions(self) -> None:
161         """Test setting Process.conditions/enables/disables."""
162         p = Process(None)
163         p.save(self.db_conn)
164         targets = ['conditions', 'blockers', 'enables', 'disables']
165         for i, target in enumerate(targets):
166             c1, c2 = Condition(None), Condition(None)
167             c1.save(self.db_conn)
168             c2.save(self.db_conn)
169             assert isinstance(c1.id_, int)
170             assert isinstance(c2.id_, int)
171             args: list[list[int]] = [[], [], [], []]
172             args[i] = []
173             p.set_condition_relations(self.db_conn, *args)
174             self.assertEqual(getattr(p, target), [])
175             args[i] = [c1.id_]
176             p.set_condition_relations(self.db_conn, *args)
177             self.assertEqual(getattr(p, target), [c1])
178             args[i] = [c2.id_]
179             p.set_condition_relations(self.db_conn, *args)
180             self.assertEqual(getattr(p, target), [c2])
181             args[i] = [c1.id_, c2.id_]
182             p.set_condition_relations(self.db_conn, *args)
183             self.assertEqual(getattr(p, target), [c1, c2])
184
185     def test_remove(self) -> None:
186         """Test removal of Processes and ProcessSteps."""
187         super().test_remove()
188         p1, p2, p3 = self.three_processes()
189         assert isinstance(p1.id_, int)
190         assert isinstance(p2.id_, int)
191         assert isinstance(p3.id_, int)
192         step = ProcessStep(None, p2.id_, p1.id_, None)
193         p2.set_steps(self.db_conn, [step])
194         step_id = step.id_
195         p2.set_steps(self.db_conn, [])
196         with self.assertRaises(NotFoundException):
197             # check unset ProcessSteps actually cannot be found anymore
198             assert step_id is not None
199             ProcessStep.by_id(self.db_conn, step_id)
200         p1.remove(self.db_conn)
201         step = ProcessStep(None, p2.id_, p3.id_, None)
202         p2.set_steps(self.db_conn, [step])
203         step_id = step.id_
204         # check _can_ remove Process pointed to by ProcessStep.owner_id, and …
205         p2.remove(self.db_conn)
206         with self.assertRaises(NotFoundException):
207             # … being dis-owned eliminates ProcessStep
208             assert step_id is not None
209             ProcessStep.by_id(self.db_conn, step_id)
210
211
212 class TestsWithDBForProcessStep(TestCaseWithDB):
213     """Module tests requiring DB setup."""
214     checked_class = ProcessStep
215     default_init_kwargs = {'owner_id': 1, 'step_process_id': 2,
216                            'parent_step_id': 3}
217
218     def setUp(self) -> None:
219         super().setUp()
220         self.p1 = Process(1)
221         self.p1.save(self.db_conn)
222
223     def test_remove(self) -> None:
224         """Test .remove and unsetting of owner's .explicit_steps entry."""
225         p2 = Process(2)
226         p2.save(self.db_conn)
227         assert isinstance(self.p1.id_, int)
228         assert isinstance(p2.id_, int)
229         step = ProcessStep(None, self.p1.id_, p2.id_, None)
230         self.p1.set_steps(self.db_conn, [step])
231         step.remove(self.db_conn)
232         self.assertEqual(self.p1.explicit_steps, [])
233         self.check_identity_with_cache_and_db([])
234
235
236 class ExpectedGetProcess(Expected):
237     """Builder of expectations for GET /processes."""
238     _default_dict = {'is_new': False, 'preset_top_step': None, 'n_todos': 0}
239     _on_empty_make_temp = ('Process', 'proc_as_dict')
240
241     def __init__(self,
242                  proc_id: int,
243                  *args: Any, **kwargs: Any) -> None:
244         self._fields = {'process': proc_id, 'steps': []}
245         super().__init__(*args, **kwargs)
246
247     @staticmethod
248     def stepnode_as_dict(step_id: int,
249                          proc_id: int,
250                          seen: bool = False,
251                          steps: None | list[dict[str, object]] = None,
252                          is_explicit: bool = True,
253                          is_suppressed: bool = False) -> dict[str, object]:
254         # pylint: disable=too-many-arguments
255         """Return JSON of ProcessStepNode to expect."""
256         return {'step': step_id,
257                 'process': proc_id,
258                 'seen': seen,
259                 'steps': steps if steps else [],
260                 'is_explicit': is_explicit,
261                 'is_suppressed': is_suppressed}
262
263     def recalc(self) -> None:
264         """Update internal dictionary by subclass-specific rules."""
265         super().recalc()
266         self._fields['process_candidates'] = self.as_ids(
267                 self.lib_all('Process'))
268         self._fields['condition_candidates'] = self.as_ids(
269                 self.lib_all('Condition'))
270         self._fields['owners'] = [
271                 s['owner_id'] for s in self.lib_all('ProcessStep')
272                 if s['step_process_id'] == self._fields['process']]
273
274
275 class ExpectedGetProcesses(Expected):
276     """Builder of expectations for GET /processes."""
277     _default_dict = {'sort_by': 'title', 'pattern': ''}
278
279     def recalc(self) -> None:
280         """Update internal dictionary by subclass-specific rules."""
281         super().recalc()
282         self._fields['processes'] = self.as_ids(self.lib_all('Process'))
283
284
285 class TestsWithServer(TestCaseWithServer):
286     """Module tests against our HTTP server/handler (and database)."""
287
288     def _post_process(self, id_: int = 1,
289                       form_data: dict[str, Any] | None = None
290                       ) -> dict[str, Any]:
291         """POST basic Process."""
292         if not form_data:
293             form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
294         self.check_post(form_data, f'/process?id={id_}',
295                         redir=f'/process?id={id_}')
296         return form_data
297
298     def test_fail_POST_process(self) -> None:
299         """Test POST /process and its effect on the database."""
300         valid_post = {'title': '', 'description': '', 'effort': 1.0}
301         # check payloads lacking minimum expecteds
302         self.check_post({}, '/process', 400)
303         self.check_post({'title': '', 'description': ''}, '/process', 400)
304         self.check_post({'title': '', 'effort': 1}, '/process', 400)
305         self.check_post({'description': '', 'effort': 1}, '/process', 400)
306         # check payloads of bad data types
307         self.check_post(valid_post | {'effort': ''}, '/process', 400)
308         # check references to non-existant items
309         self.check_post(valid_post | {'conditions': [1]}, '/process', 404)
310         self.check_post(valid_post | {'disables': [1]}, '/process', 404)
311         self.check_post(valid_post | {'blockers': [1]}, '/process', 404)
312         self.check_post(valid_post | {'enables': [1]}, '/process', 404)
313         self.check_post(valid_post | {'new_top_step': 2}, '/process', 404)
314         # check deletion of non-existant
315         self.check_post({'delete': ''}, '/process?id=1', 404)
316
317     def test_basic_POST_process(self) -> None:
318         """Test basic GET/POST /process operations."""
319         # check on un-saved
320         exp = ExpectedGetProcess(1)
321         exp.force('process_candidates', [])
322         self.check_json_get('/process?id=1', exp)
323         # check on minimal payload post
324         valid_post = {'title': 'foo', 'description': 'oof', 'effort': 2.3}
325         exp.unforce('process_candidates')
326         self.post_exp_process([exp], valid_post, 1)
327         self.check_json_get('/process?id=1', exp)
328         # check n_todos field
329         self.post_exp_day([], {'new_todo': ['1']}, '2024-01-01')
330         self.post_exp_day([], {'new_todo': ['1']}, '2024-01-02')
331         exp.set('n_todos', 2)
332         self.check_json_get('/process?id=1', exp)
333         # check cannot delete if Todos to Process
334         self.check_post({'delete': ''}, '/process?id=1', 500)
335         # check cannot delete if some ProcessStep's .step_process_id
336         self.post_exp_process([exp], valid_post, 2)
337         self.post_exp_process([exp], valid_post | {'new_top_step': 2}, 3)
338         self.check_post({'delete': ''}, '/process?id=2', 500)
339         # check successful deletion
340         self.post_exp_process([exp], valid_post, 4)
341         self.check_post({'delete': ''}, '/process?id=4', 302, '/processes')
342         exp = ExpectedGetProcess(4)
343         exp.set_proc_from_post(1, valid_post)
344         exp.set_proc_from_post(2, valid_post)
345         exp.set_proc_from_post(3, valid_post)
346         exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 3, 2)])
347         exp.force('process_candidates', [1, 2, 3])
348         self.check_json_get('/process?id=4', exp)
349
350     def test_POST_process_steps(self) -> None:
351         """Test behavior of ProcessStep posting."""
352         # pylint: disable=too-many-statements
353         url = '/process?id=1'
354         exp = ExpectedGetProcess(1)
355         self.post_exp_process([exp], {}, 1)
356         # post first (top-level) step of proc 2 to proc 1 by 'step_of' in 2
357         self.post_exp_process([exp], {'step_of': 1}, 2)
358         exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)])
359         exp.set('steps', [exp.stepnode_as_dict(1, 2)])
360         self.check_json_get(url, exp)
361         # post empty/absent steps list to process, expect clean slate, and old
362         # step to completely disappear
363         self.post_exp_process([exp], {}, 1)
364         exp.lib_wipe('ProcessStep')
365         exp.set('steps', [])
366         self.check_json_get(url, exp)
367         # post new step of proc2 to proc1 by 'new_top_step'
368         self.post_exp_process([exp], {'new_top_step': 2}, 1)
369         exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)])
370         self.post_exp_process([exp], {'kept_steps': [1]}, 1)
371         exp.set('steps', [exp.stepnode_as_dict(1, 2)])
372         self.check_json_get(url, exp)
373         # fail on single- and multi-step recursion
374         p_min = {'title': '', 'description': '', 'effort': 0}
375         self.check_post(p_min | {'new_top_step': 1}, url, 400)
376         self.check_post(p_min | {'step_of': 1}, url, 400)
377         self.post_exp_process([exp], {'new_top_step': 1}, 2)
378         self.check_post(p_min | {'step_of': 2, 'new_top_step': 2}, url, 400)
379         self.post_exp_process([exp], {}, 3)
380         self.post_exp_process([exp], {'step_of': 3}, 4)
381         self.check_post(p_min | {'new_top_step': 3, 'step_of': 4}, url, 400)
382         # post sibling steps
383         self.post_exp_process([exp], {}, 4)
384         self.post_exp_process([exp], {'new_top_step': 4}, 1)
385         self.post_exp_process([exp], {'kept_steps': [1], 'new_top_step': 4}, 1)
386         exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 4),
387                                     exp.procstep_as_dict(2, 1, 4)])
388         exp.set('steps', [exp.stepnode_as_dict(1, 4),
389                           exp.stepnode_as_dict(2, 4)])
390         self.check_json_get(url, exp)
391         # post sub-step chain
392         p = {'kept_steps': [1, 2], 'new_step_to_2': 4}
393         self.post_exp_process([exp], p, 1)
394         exp.lib_set('ProcessStep', [exp.procstep_as_dict(3, 1, 4, 2)])
395         exp.set('steps', [exp.stepnode_as_dict(1, 4),
396                           exp.stepnode_as_dict(2, 4, steps=[
397                               exp.stepnode_as_dict(3, 4)])])
398         self.check_json_get(url, exp)
399         # fail posting sub-step that would cause recursion
400         self.post_exp_process([exp], {}, 6)
401         self.post_exp_process([exp], {'new_top_step': 6}, 5)
402         p = p_min | {'kept_steps': [1, 2, 3], 'new_step_to_2': 5, 'step_of': 6}
403         self.check_post(p, url, 400)
404
405     def test_GET(self) -> None:
406         """Test /process and /processes response codes."""
407         self.check_get('/process', 200)
408         self.check_get('/process?id=', 200)
409         self.check_get('/process?id=1', 200)
410         self.check_get_defaults('/process')
411         self.check_get('/processes', 200)
412
413     def test_fail_GET_process(self) -> None:
414         """Test invalid GET /process params."""
415         # check for invalid IDs
416         self.check_get('/process?id=foo', 400)
417         self.check_get('/process?id=0', 500)
418         # check we catch invalid base64
419         self.check_get('/process?title_b64=foo', 400)
420         # check failure on references to unknown processes; we create Process
421         # of ID=1 here so we know the 404 comes from step_to=2 etc. (that tie
422         # the Process displayed by /process to others), not from not finding
423         # the main Process itself
424         self.post_exp_process([], {}, 1)
425         self.check_get('/process?id=1&step_to=2', 404)
426         self.check_get('/process?id=1&has_step=2', 404)
427
428     def test_GET_processes(self) -> None:
429         """Test GET /processes."""
430         # pylint: disable=too-many-statements
431         # test empty result on empty DB, default-settings on empty params
432         exp = ExpectedGetProcesses()
433         self.check_json_get('/processes', exp)
434         # test on meaningless non-empty params (incl. entirely un-used key),
435         # that 'sort_by' default to 'title' (even if set to something else, as
436         # long as without handler) and 'pattern' get preserved
437         exp.set('pattern', 'bar')
438         url = '/processes?sort_by=foo&pattern=bar&foo=x'
439         self.check_json_get(url, exp)
440         # test non-empty result, automatic (positive) sorting by title
441         proc1_post = {'title': 'foo', 'description': 'oof', 'effort': 1.0}
442         self.post_exp_process([exp], proc1_post, 1)
443         proc2_post = {'title': 'bar', 'description': 'rab', 'effort': 1.1}
444         self.post_exp_process([exp], proc2_post | {'new_top_step': [1]}, 2)
445         proc3_post = {'title': 'baz', 'description': 'zab', 'effort': 0.9}
446         self.post_exp_process([exp], proc3_post | {'new_top_step': [1]}, 3)
447         proc3_post = proc3_post | {'new_top_step': [2], 'kept_steps': [2]}
448         self.post_exp_process([exp], proc3_post, 3)
449         exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 2, 1),
450                                     exp.procstep_as_dict(2, 3, 1),
451                                     exp.procstep_as_dict(3, 3, 2)])
452         exp.set('pattern', '')
453         self.check_filter(exp, 'processes', 'sort_by', 'title', [2, 3, 1])
454         # test other sortings
455         self.check_filter(exp, 'processes', 'sort_by', '-title', [1, 3, 2])
456         self.check_filter(exp, 'processes', 'sort_by', 'effort', [3, 1, 2])
457         self.check_filter(exp, 'processes', 'sort_by', '-effort', [2, 1, 3])
458         self.check_filter(exp, 'processes', 'sort_by', 'steps', [1, 2, 3])
459         self.check_filter(exp, 'processes', 'sort_by', '-steps', [3, 2, 1])
460         self.check_filter(exp, 'processes', 'sort_by', 'owners', [3, 2, 1])
461         self.check_filter(exp, 'processes', 'sort_by', '-owners', [1, 2, 3])
462         # test pattern matching on title
463         exp.set('sort_by', 'title')
464         exp.lib_del('Process', '1')
465         self.check_filter(exp, 'processes', 'pattern', 'ba', [2, 3])
466         # test pattern matching on description
467         exp.lib_wipe('Process')
468         exp.lib_wipe('ProcessStep')
469         self.post_exp_process([exp], {'description': 'oof', 'effort': 1.0}, 1)
470         self.check_filter(exp, 'processes', 'pattern', 'of', [1])