jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaseci might be problematic. Click here for more details.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
@@ -1,556 +0,0 @@
1
- from unittest import TestCase
2
- from jaseci.utils.utils import TestCaseHelper
3
- from jaseci.cli_tools import jsctl
4
- from click.testing import CliRunner
5
- import json
6
- import os
7
-
8
- from jaseci.jsorc.jsorc import JsOrc
9
- from jaseci.extens.svc.redis_svc import RedisService
10
-
11
-
12
- class JsctlTest(TestCaseHelper, TestCase):
13
- """Unit tests for Jac language"""
14
-
15
- infer_loc = (
16
- os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/tests/infer.py"
17
- )
18
-
19
- def setUp(self):
20
- super().setUp()
21
- JsOrc.svc("redis", RedisService).clear()
22
-
23
- def call(self, cmd: str):
24
- res = CliRunner(mix_stderr=False).invoke(jsctl.jsctl, ["-m"] + cmd.split())
25
- # self.log(res.stdout)
26
- # self.log(res.stderr)
27
- # self.log(res.exception)
28
- return res.stdout
29
-
30
- def jac_call(self, cmd: str):
31
- res = CliRunner(mix_stderr=False).invoke(jsctl.jac, cmd.split())
32
- return res.stdout
33
-
34
- def call_cast(self, cmd):
35
- ret = self.call(cmd)
36
- # self.log(ret)
37
- return json.loads(ret)
38
-
39
- def jac_call_cast(self, cmd):
40
- ret = self.jac_call(cmd)
41
- # self.log(ret)
42
- return json.loads(ret)
43
-
44
- def call_split(self, cmd):
45
- ret = self.call(cmd)
46
- # self.log(ret)
47
- return ret.split("\n")
48
-
49
- def jac_call_split(self, cmd):
50
- ret = self.jac_call(cmd)
51
- return ret.split("\n")
52
-
53
- def tearDown(self):
54
- jsctl.reset_state()
55
- super().tearDown()
56
-
57
- def test_jsctl_extract_tree(self):
58
- out = jsctl.extract_api_tree()
59
- self.assertIn("graph", out)
60
- self.assertIn("walker", out)
61
- self.assertIn("sentinel", out)
62
- self.assertIn("alias", out)
63
- self.assertIn("config", out)
64
- self.assertNotIn("jadc", out)
65
-
66
- def test_help_screen(self):
67
- r = self.call("--help")
68
- self.assertIn("Specify filename", r)
69
- self.assertIn("Group of `graph` commands", r)
70
- r = self.call("sentinel --help")
71
- self.assertIn("Group of `sentinel active` commands", r)
72
-
73
- def test_jsctl_create_graph_mem_only(self):
74
- ret = self.call(
75
- f"sentinel register {os.path.dirname(__file__)}/ll.jac -name ll -set_active true"
76
- )
77
- self.assertEqual(len(self.call_cast("graph list")), 1)
78
- self.call("graph create")
79
- self.call("graph create")
80
- self.call("graph create")
81
- self.assertEqual(len(self.call_cast("graph list")), 4)
82
-
83
- def test_jsctl_carry_forward(self):
84
- ret = self.call(f"actions load local {self.infer_loc}")
85
- ret = self.call(
86
- f"sentinel register {os.path.dirname(__file__)}/ll.jac -name ll -set_active true"
87
- )
88
- r = self.call("graph create -set_active true")
89
- r = self.call("walker run init")
90
- r = self.call("walker run gen_rand_life")
91
- r = self.call_cast("walker run get_gen_day")
92
- self.assertGreater(len(r["report"]), 3)
93
-
94
- def test_jsctl_dot(self):
95
- self.call(
96
- f"sentinel register {os.path.dirname(__file__)}/ll.jac -name ll -set_active true"
97
- )
98
- self.call("walker run init")
99
- self.call("walker run gen_rand_life")
100
- r = self.call("graph get -mode dot")
101
- self.assertIn('"n0" -> "n', r)
102
- self.assertNotIn('week="', r)
103
-
104
- r = self.call("graph get -mode dot -detailed true")
105
- self.assertIn('"n0" -> "n', r)
106
- self.assertIn('id="', r)
107
-
108
- def test_jsctl_aliases(self):
109
- """Tests that alias mapping api works"""
110
- self.call(
111
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
112
- )
113
- gph_id = self.call_cast("graph create")["jid"]
114
- snt_id = self.call_cast("sentinel list")[0]["jid"]
115
- self.call(f"alias register s -value {snt_id}")
116
- self.call(f"alias register g -value {gph_id}")
117
- self.assertEqual(len(self.call_cast("graph get -nd g")), 1)
118
- self.call("walker run init -snt s -nd g")
119
- self.assertEqual(len(self.call_cast("graph get -nd g")), 3)
120
- self.call("alias clear")
121
- self.assertEqual(len(self.call_cast("alias list").keys()), 0)
122
-
123
- def test_jsctl_auto_aliases(self):
124
- """Tests that auto alias mapping api works"""
125
- self.call(
126
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
127
- )
128
- aliases = self.call_cast("alias list")
129
- self.assertGreater(len(aliases), 20)
130
- self.assertIn("zsb:architype:bot", aliases.keys())
131
- self.assertIn("zsb:walker:similar_questions", aliases.keys())
132
- self.assertIn("sentinel:zsb", aliases.keys())
133
- self.assertIn("zsb:walker:create_nugget", aliases.keys())
134
-
135
- def test_jsctl_auto_aliases_delete(self):
136
- """Tests that auto removing alias mapping api works"""
137
- self.call(
138
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
139
- )
140
-
141
- num = len(self.call_cast("alias list"))
142
-
143
- self.call("architype delete zsb:architype:bot")
144
- self.call("architype delete zsb:walker:similar_questions")
145
- self.call("architype delete zsb:walker:create_nugget")
146
- self.assertEqual(num - 3, len(self.call_cast("alias list")))
147
-
148
- def test_jsctl_config_cmds(self):
149
- """Tests that config commands works"""
150
- self.call(
151
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
152
- )
153
- self.call('config set CONFIG_EXAMPLE -value "TEST" -do_check False')
154
- self.call("config set APPLE -value Grape2 -do_check False")
155
- self.call("config set APPLE_JSON -value '{\"test\":true}' -do_check False")
156
- self.call('config set "Banana" -value "Grape" -do_check False')
157
- self.call('config set "Pear" -value "Banana" -do_check False')
158
- r = self.call("config get APPLE -do_check False")
159
- self.assertEqual(r.strip(), "Grape2")
160
- r = self.call_cast("config list")
161
-
162
- self.assertEqual(len(r), 1)
163
-
164
- def test_jsctl_default_snt_setting(self):
165
- """Tests that alias mapping api works"""
166
- self.call(
167
- f"sentinel register {os.path.dirname(__file__)}/teststest.jac -name zsb "
168
- "-set_active true"
169
- )
170
- snt_id = self.call_cast("sentinel list")[0]["jid"]
171
- self.call(f"sentinel active set {snt_id}")
172
- self.call("sentinel active get")
173
- self.assertEqual(len(self.call_cast("walker list")), 2)
174
-
175
- def test_jsctl_init_auto_called(self):
176
- """Tests that alias mapping api works"""
177
- num = len(self.call_cast("graph get"))
178
- self.assertEqual(num, 3)
179
-
180
- def test_jsctl_master_defaults(self):
181
- """Tests that alias mapping api works"""
182
- self.call(
183
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
184
- )
185
- gph_id = self.call_cast("graph create")["jid"]
186
- snt_id = self.call_cast("sentinel list")[0]["jid"]
187
- self.call(f"sentinel active set -snt {snt_id}")
188
- self.call(f"graph active set -gph {gph_id}")
189
- self.assertEqual(len(self.call_cast("graph get")), 1)
190
- self.call("walker run init")
191
- self.assertEqual(len(self.call_cast("graph get")), 3)
192
-
193
- def test_public_apis_present(self):
194
- r = self.call("walker --help")
195
- self.assertIn("summon", r)
196
- self.assertIn("namespace key", r)
197
-
198
- def test_public_apis_walker_summon_auth(self):
199
- self.call(
200
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
201
- )
202
- wjid = self.call_cast("walker spawn create pubinit")["jid"]
203
- r = self.call_cast(f"walker get {wjid} -mode keys")
204
- key = r["anyone"]
205
- r = self.call_cast("alias list")
206
- nd = r["active:graph"]
207
- r = self.call_cast(f"walker summon {wjid} -key {key} -nd {nd}")
208
- self.assertEqual(len(r["report"]), 0)
209
- key = "aaaaaaaa"
210
- r = self.call_cast(f"walker summon {wjid} -key {key} -nd {nd}")
211
- self.assertFalse(r["success"])
212
-
213
- def test_jsctl_import(self):
214
- self.call(f"actions load local {self.infer_loc}")
215
- r = self.call_cast(
216
- f"sentinel register "
217
- f"{os.path.dirname(__file__)}/ll_base.jac -code_dir "
218
- f"{os.path.dirname(__file__)} -set_active true"
219
- )
220
- r = self.call_cast("walker run init")
221
- r = self.call_cast("walker run gen_rand_life")
222
- r = self.call_cast("walker run get_gen_day")
223
- self.assertGreater(len(r["report"]), 3)
224
-
225
- def test_jsctl_import_filters(self):
226
- self.call_cast(
227
- f"sentinel register {os.path.dirname(__file__)}/base.jac -set_active true"
228
- )
229
- r = self.call_cast("walker run init")
230
- self.assertEqual(len(r["report"]), 8)
231
-
232
- def test_jsctl_import_filters1(self):
233
- self.call(
234
- f"sentinel register {os.path.dirname(__file__)}/base1.jac -set_active true"
235
- )
236
- r = self.call_cast("walker run init")
237
- self.assertEqual(len(r["report"]), 8)
238
-
239
- def test_jsctl_import_filters2(self):
240
- self.call(
241
- f"sentinel register {os.path.dirname(__file__)}/base2.jac -set_active true"
242
- )
243
- r = self.call_cast("walker run init")
244
- self.assertEqual(len(r["report"]), 8)
245
-
246
- def test_jsctl_import_fails_when_incomplete(self):
247
- self.call(
248
- f"sentinel register {os.path.dirname(__file__)}/base3.jac -set_active true"
249
- )
250
- r = self.call_cast("walker run init")
251
- self.assertTrue("success" in r.keys())
252
- self.assertFalse(r["success"])
253
-
254
- def test_jsctl_import_globals(self):
255
- self.call(
256
- f"sentinel register "
257
- f"{os.path.dirname(__file__)}/base4.jac -code_dir {os.path.dirname(__file__)}/ "
258
- f"-set_active true"
259
- )
260
- r = self.call_cast("walker run init")
261
- self.assertEqual(len(r["report"]), 8)
262
-
263
- def test_jsctl_import_recursive(self):
264
- self.call(
265
- "sentinel register "
266
- f"{os.path.dirname(__file__)}/base5.jac -code_dir {os.path.dirname(__file__)}/ "
267
- "-set_active true"
268
- )
269
- r = self.call_cast("walker run init")
270
- self.assertEqual(r["report"][0], "plain")
271
-
272
- def test_jsctl_import_path(self):
273
- self.call(
274
- "sentinel register "
275
- f"{os.path.dirname(__file__)}/base6.jac -code_dir {os.path.dirname(__file__)}/ "
276
- "-set_active true"
277
- )
278
- r = self.call_cast("walker run init")
279
- self.assertEqual(r["report"][0], "plain")
280
-
281
- def test_jsctl_run_tests(self):
282
- self.call(f"sentinel register {os.path.dirname(__file__)}/teststest.jac")
283
- r = self.call_split("sentinel test")
284
- self.assertTrue(r[0].startswith("Testing assert should be"))
285
- self.assertTrue(r[4].startswith(' "tests": 3'))
286
- self.assertTrue(r[7].startswith(' "success": true'))
287
-
288
- def test_jsctl_run_tests_detailed(self):
289
- self.call(f"sentinel register {os.path.dirname(__file__)}/teststest.jac")
290
- r = self.call_split("sentinel test -detailed true")
291
- self.assertEqual(len(r), 33)
292
-
293
- def test_jsctl_multiple_registers_with_globals(self):
294
- r = self.call_cast(
295
- f"sentinel register {os.path.dirname(__file__)}/teststest.jir -mode ir"
296
- )
297
- r = self.call_cast(
298
- f"sentinel register {os.path.dirname(__file__)}/teststest.jir -mode ir"
299
- )
300
- self.assertEqual(len(r), 1)
301
-
302
- def test_jsctl_run_tests_with_stdout(self):
303
- self.call(f"sentinel register {os.path.dirname(__file__)}/teststest_stdout.jac")
304
- r = self.call("sentinel test -detailed true")
305
- self.assertIn('"stdout": "Some Output\\nSome Output\\n"', r)
306
- r = r.replace('"stdout": "Some Output\\nSome Output\\n"', "")
307
- self.assertNotIn("Some Output", r)
308
-
309
- def test_jsctl_jac_build(self):
310
- if os.path.exists(f"{os.path.dirname(__file__)}/teststest.jir"):
311
- os.remove(f"{os.path.dirname(__file__)}/teststest.jir")
312
- self.assertFalse(
313
- os.path.exists(f"{os.path.dirname(__file__)}/teststest.jir")
314
- )
315
- self.call(f"jac build {os.path.dirname(__file__)}/teststest.jac")
316
- self.assertGreater(
317
- os.path.getsize(f"{os.path.dirname(__file__)}/teststest.jir"), 20000
318
- )
319
-
320
- def test_jsctl_jac_build_with_action(self):
321
- if os.path.exists(f"{os.path.dirname(__file__)}/withaction.jir"):
322
- os.remove(f"{os.path.dirname(__file__)}/withaction.jir")
323
- self.assertFalse(
324
- os.path.exists(f"{os.path.dirname(__file__)}/withaction.jir")
325
- )
326
- self.call(f"jac build {os.path.dirname(__file__)}/withaction.jac")
327
- self.assertGreater(
328
- os.path.getsize(f"{os.path.dirname(__file__)}/withaction.jir"), 1000
329
- )
330
- os.remove(f"{os.path.dirname(__file__)}/withaction.jir")
331
-
332
- def test_jsctl_jac_test(self):
333
- r = self.call_split(f"jac test {os.path.dirname(__file__)}/teststest.jac")
334
- self.assertTrue(r[0].startswith("Testing assert should be"))
335
- self.assertTrue(r[4].startswith(' "tests": 3'))
336
- self.assertTrue(r[7].startswith(' "success": true'))
337
-
338
- def test_jsctl_jac_test_single(self):
339
- r = self.call_split(
340
- f"jac test {os.path.dirname(__file__)}/teststest.jac -single the_second"
341
- )
342
- self.log(r)
343
- self.assertTrue(r[0].startswith("Testing a second test"))
344
- self.assertTrue(r[2].startswith(' "tests": 1'))
345
- self.assertTrue(r[5].startswith(' "success": true'))
346
-
347
- def test_jsctl_jac_test_jir(self):
348
- r = self.call_split(f"jac test {os.path.dirname(__file__)}/teststest.jir")
349
- self.assertTrue(r[0].startswith("Testing assert should be"))
350
- self.assertTrue(r[4].startswith(' "tests": 3'))
351
- self.assertTrue(r[7].startswith(' "success": true'))
352
-
353
- def test_jac_long_str_build(self):
354
- r = self.jac_call_cast(f"run {os.path.dirname(__file__)}/longstring.jac")
355
- self.assertTrue(
356
- r["report"][0].startswith("Lorem Ipsum is simply dummy text of the")
357
- )
358
- self.assertTrue(
359
- r["report"][0].endswith(
360
- "Aldus PageMaker including versions of Lorem Ipsum."
361
- )
362
- )
363
-
364
- def test_jac_cli_test(self):
365
- r = self.jac_call_split(f"test {os.path.dirname(__file__)}/teststest.jir")
366
- self.assertTrue(r[0].startswith("Testing assert should be"))
367
- self.assertTrue(r[4].startswith(' "tests": 3'))
368
- self.assertTrue(r[7].startswith(' "success": true'))
369
-
370
- def test_jsctl_jac_disas_jir(self):
371
- r = self.call(f"jac disas {os.path.dirname(__file__)}/teststest.jir")
372
- self.assertIn("LOAD_CONST", r)
373
- self.assertIn("LOAD_VAR", r)
374
-
375
- def test_jsctl_jac_run(self):
376
- r = self.call_cast(f"jac run {os.path.dirname(__file__)}/teststest.jac")
377
- self.assertEqual(r["report"], [{}, 4])
378
-
379
- def test_jsctl_jac_run_jir(self):
380
- r = self.call_cast(f"jac run {os.path.dirname(__file__)}/teststest.jir")
381
- self.assertEqual(r["report"], [{}, 4])
382
-
383
- def test_jsctl_jac_dot_jir(self):
384
- r = self.call(f"jac dot {os.path.dirname(__file__)}/teststest.jir")
385
- self.assertEqual(r, 'strict digraph root {\n "n0" [ label="n0:root" ]\n}\n')
386
-
387
- def test_jsctl_jac_run_jir_walk(self):
388
- r = self.call_cast(
389
- f"jac run {os.path.dirname(__file__)}/teststest.jir -walk alt_init"
390
- )
391
- self.assertEqual(r["report"], [7])
392
-
393
- def test_jsctl_sentinel_set(self):
394
- self.call(
395
- f"sentinel register {os.path.dirname(__file__)}/teststest.jac -set_active true"
396
- )
397
- self.call(f"sentinel set {os.path.dirname(__file__)}/base.jac")
398
- r = self.call_cast("walker run init")
399
- r = self.call_cast("walker run init")
400
- self.assertEqual(len(r["report"]), 8)
401
-
402
- def test_jsctl_action_list(self):
403
- r = self.call_cast("actions list")
404
- self.assertIn("std.out", r)
405
-
406
- def test_jsctl_master_self(self):
407
- r = self.call_cast("master self")
408
- self.assertIn("j_type", r.keys())
409
- a = r["jid"]
410
- r = self.call_cast("master active get")
411
- self.assertIn("j_type", r.keys())
412
- b = r["jid"]
413
- self.assertEqual(a, b)
414
-
415
- def test_jsctl_graph_can(self):
416
- self.call(f"actions load local {self.infer_loc}")
417
- r = self.call(
418
- f"sentinel register "
419
- f"{os.path.dirname(__file__)}/graph_can.jac -name gc -set_active true"
420
- )
421
- r = self.call("walker run go1")
422
- self.assertEqual(r.split()[0], "2020-01-01T00:00:00")
423
- r = self.call("walker run go2")
424
- self.assertEqual(r.split()[0], "2020-07-01T00:00:00")
425
- r = self.call("walker run go3")
426
- self.assertEqual(r.split()[0], "2020-01-01T00:00:00")
427
- self.assertEqual(r.split()[1], "2020-07-01T00:00:00")
428
- self.assertEqual(r.split()[2], "2020-07-10T00:00:00")
429
-
430
- def test_jsctl_action_call(self):
431
- self.call(f"actions load local {self.infer_loc}")
432
- r = self.call(f"actions call infer.date_now")
433
- r = json.loads(r)
434
- import datetime
435
-
436
- date_now = datetime.datetime.utcnow().date().isoformat()
437
- self.assertEqual(r["result"], date_now)
438
-
439
- def test_jsctl_custom_report(self):
440
- self.call(
441
- f"sentinel register {os.path.dirname(__file__)}/glob_imp.jac -set_active true"
442
- )
443
- r = self.call_cast("walker run cust_report")
444
- self.assertEqual(r, {"a": "b"})
445
-
446
- def test_jsctl_custom_report_off(self):
447
- self.call(
448
- f"sentinel register {os.path.dirname(__file__)}/glob_imp.jac -set_active true"
449
- )
450
- r = self.call_cast("walker run cust_report_neutralize")
451
- self.assertIn("success", r.keys())
452
-
453
- def test_jsctl_disengage_report(self):
454
- self.call(
455
- f"sentinel register {os.path.dirname(__file__)}/glob_imp.jac -set_active true"
456
- )
457
- r = self.call_cast("walker run disengage_report")
458
- self.assertEqual(r, {"a": "b"})
459
-
460
- def test_jsctl_set_global_default_perms(self):
461
- self.call("object perms default public")
462
- self.call(
463
- f"sentinel register {os.path.dirname(__file__)}/zsb.jac -name zsb -set_active true"
464
- )
465
- gphs = self.call_cast("graph get -detailed true")
466
- for i in gphs:
467
- self.assertEqual(i["j_access"], "public")
468
-
469
- def test_jsctl_bookgen_api_cheatsheet(self):
470
- r = self.call("booktool cheatsheet")
471
- self.assertGreater(len(r), 2000)
472
-
473
- def test_jsctl_bookgen_std_library(self):
474
- r = self.call("booktool stdlib")
475
- self.assertGreater(len(r), 2000)
476
-
477
- def test_jsctl_bookgen_api_spec(self):
478
- r = self.call("booktool cheatsheet")
479
- self.assertGreater(len(r), 2000)
480
-
481
- def test_jsctl_print_detailed_sentinel(self):
482
- r = self.call_cast(
483
- f"sentinel register {os.path.dirname(__file__)}/teststest.jir -name test -mode ir"
484
- )
485
- r = self.call_cast("object get sentinel:test")
486
- before = len(r.keys())
487
- r = self.call_cast("object get sentinel:test -detailed true")
488
- after = len(r.keys())
489
- self.assertGreater(before, 4)
490
- self.assertGreater(after, before)
491
-
492
- def test_jsctl_script(self):
493
- r = self.call(f"script {os.path.dirname(__file__)}/jsctl_script")
494
- self.assertEqual(r, "[]\n\n[]\n\n{}\n\n")
495
-
496
- def test_jsctl_script_output(self):
497
- self.call(f"script {os.path.dirname(__file__)}/jsctl_script -o scr_out")
498
- with open("scr_out", "r") as f:
499
- s = [line.rstrip() for line in f]
500
- if os.path.exists("scr_out"):
501
- os.remove("scr_out")
502
- self.assertEqual(
503
- s,
504
- [
505
- "Multi Command Script Output:",
506
- "Output for sentinel list:",
507
- "[]",
508
- "Output for graph list:",
509
- "[]",
510
- "Output for alias list:",
511
- "{}",
512
- ],
513
- )
514
-
515
- def test_jsctl_pretty_profiles(self):
516
- self.call(f"actions load local {self.infer_loc}")
517
- r = self.call(
518
- f"sentinel register "
519
- f"{os.path.dirname(__file__)}/graph_can.jac -name gc -set_active true"
520
- )
521
- r = self.call("walker run go1 -profiling true")
522
- self.assertIn("walker::go1", r)
523
- self.assertIn("cumtime", r)
524
- self.assertIn("cum_time", r)
525
-
526
-
527
- class JsctlTestWithSession(TestCaseHelper, TestCase):
528
- """Unit tests for Jac language"""
529
-
530
- def setUp(self):
531
- super().setUp()
532
-
533
- def call(self, cmd):
534
- ses = " -f {os.path.dirname(__file__)}/js.session "
535
- res = CliRunner(mix_stderr=False).invoke(jsctl.jsctl, (ses + cmd).split())
536
- return res.stdout
537
-
538
- def call_cast(self, cmd):
539
- ret = self.call(cmd)
540
- return json.loads(ret)
541
-
542
- def call_split(self, cmd):
543
- ret = self.call(cmd)
544
- return ret.split("\n")
545
-
546
- def tearDown(self):
547
- if os.path.exists(f"{os.path.dirname(__file__)}/js.session"):
548
- os.remove(f"{os.path.dirname(__file__)}/js.session")
549
- jsctl.reset_state()
550
- super().tearDown()
551
-
552
- def test_jsctl_register_with_session(self):
553
- self.call(f"sentinel register {os.path.dirname(__file__)}/teststest.jac")
554
- self.call(f"sentinel register {os.path.dirname(__file__)}/teststest.jac")
555
- r = self.call_cast("object get active:sentinel -detailed true")
556
- self.assertGreater(len(r["arch_ids"]), 3)
jaseci/extens/__init__.py DELETED
File without changes
File without changes
@@ -1,118 +0,0 @@
1
- """Built in actions for Jaseci"""
2
-
3
- from datetime import datetime, timedelta
4
- from jaseci.jsorc.live_actions import jaseci_action
5
- from dateutil.relativedelta import relativedelta
6
-
7
-
8
- @jaseci_action()
9
- def quantize_to_year(date: str):
10
- date = datetime.fromisoformat(date)
11
- date = date.replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)
12
- return date.isoformat()
13
-
14
-
15
- @jaseci_action()
16
- def quantize_to_month(date: str):
17
- date = datetime.fromisoformat(date)
18
- date = date.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
19
- return date.isoformat()
20
-
21
-
22
- @jaseci_action()
23
- def quantize_to_week(date: str):
24
- date = datetime.fromisoformat(date)
25
- date = date.replace(hour=0, minute=0, second=0, microsecond=0)
26
- date = date - timedelta(days=date.weekday())
27
- return date.isoformat()
28
-
29
-
30
- @jaseci_action()
31
- def quantize_to_day(date: str):
32
- date = datetime.fromisoformat(date)
33
- date = date.replace(hour=0, minute=0, second=0, microsecond=0)
34
- return date.isoformat()
35
-
36
-
37
- @jaseci_action()
38
- def datetime_now():
39
- """Get utc date time now in iso format"""
40
- return datetime.utcnow().isoformat()
41
-
42
-
43
- @jaseci_action()
44
- def date_now():
45
- """Get utc date now in iso format"""
46
- return datetime.utcnow().date().isoformat()
47
-
48
-
49
- @jaseci_action()
50
- def timestamp_now():
51
- """Get utc date time for now in iso format"""
52
- return int(datetime.utcnow().timestamp())
53
-
54
-
55
- @jaseci_action()
56
- def datetime_obj(date: str = None):
57
- """Get utc date time now or parse one to dict format"""
58
- if date:
59
- date = datetime.fromisoformat(date)
60
- else:
61
- date = datetime.utcnow()
62
-
63
- return {
64
- "year": date.year,
65
- "month": date.month,
66
- "weekday": date.isoweekday(),
67
- "day": date.day,
68
- "hour": date.hour,
69
- "minute": date.minute,
70
- "second": date.second,
71
- "microsecond": date.microsecond,
72
- "iso": date.isoformat(),
73
- }
74
-
75
-
76
- @jaseci_action()
77
- def datetime_add(date: str = None, **kwargs):
78
- """
79
- Get utc date time now or parse one then add timedelta
80
- kwargs: this should be valid timedelta arguments
81
- """
82
- if date:
83
- date = datetime.fromisoformat(date)
84
- else:
85
- date = datetime.utcnow()
86
-
87
- return (date + relativedelta(**kwargs)).isoformat()
88
-
89
-
90
- @jaseci_action()
91
- def datetime_sub(date: str = None, **kwargs):
92
- """
93
- Get utc date time now or parse one then subtract timedelta
94
- kwargs: this should be valid timedelta arguments
95
- """
96
- if date:
97
- date = datetime.fromisoformat(date)
98
- else:
99
- date = datetime.utcnow()
100
-
101
- return (date - relativedelta(**kwargs)).isoformat()
102
-
103
-
104
- @jaseci_action()
105
- def date_day_diff(start_date: str, end_date: str = None):
106
- # Try to deal with some incompatible date in old nodes
107
- # Due date has not been saving in isoformat so this doesn't work
108
- # for example,'2021-03-31T04:00:00.000Z'
109
- start_date = datetime.fromisoformat(start_date.split("T")[0])
110
-
111
- if end_date is None:
112
- end_date = datetime.utcnow()
113
- else:
114
- end_date = datetime.fromisoformat(end_date.split("T")[0])
115
-
116
- delta = end_date - start_date
117
-
118
- return delta.days