@voxgig/sdkgen 0.36.0 → 0.37.0

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.
Files changed (135) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Main.js +0 -12
  3. package/dist/cmp/Main.js.map +1 -1
  4. package/package.json +1 -1
  5. package/project/.sdk/src/cmp/go/Config_go.ts +6 -2
  6. package/project/.sdk/src/cmp/js/EntityBase_js.ts +34 -0
  7. package/project/.sdk/src/cmp/js/Main_js.ts +10 -0
  8. package/project/.sdk/src/cmp/js/ReadmeExplanation_js.ts +33 -0
  9. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +123 -0
  10. package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +152 -0
  11. package/project/.sdk/src/cmp/js/ReadmeTopHowto_js.ts +25 -0
  12. package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +65 -0
  13. package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +36 -0
  14. package/project/.sdk/src/cmp/js/TestDirect_js.ts +53 -5
  15. package/project/.sdk/src/cmp/js/TestEntity_js.ts +114 -20
  16. package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +7 -139
  17. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +149 -0
  18. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -10
  19. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -10
  20. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +7 -11
  21. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +7 -11
  22. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +7 -11
  23. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +2 -0
  24. package/project/.sdk/src/cmp/js/fragment/SdkError.fragment.js +0 -2
  25. package/project/.sdk/src/cmp/lua/Config_lua.ts +6 -2
  26. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +3 -1
  27. package/project/.sdk/src/cmp/php/Config_php.ts +6 -2
  28. package/project/.sdk/src/cmp/php/TestDirect_php.ts +2 -2
  29. package/project/.sdk/src/cmp/php/TestEntity_php.ts +10 -15
  30. package/project/.sdk/src/cmp/py/Config_py.ts +6 -2
  31. package/project/.sdk/src/cmp/py/TestEntity_py.ts +3 -1
  32. package/project/.sdk/src/cmp/rb/Config_rb.ts +6 -2
  33. package/project/.sdk/src/cmp/ts/Main_ts.ts +7 -0
  34. package/project/.sdk/tm/go/feature/log_feature.go +1 -1
  35. package/project/.sdk/tm/go/test/runner_test.go +16 -2
  36. package/project/.sdk/tm/js/src/Context.js +142 -0
  37. package/project/.sdk/tm/js/src/Control.js +16 -0
  38. package/project/.sdk/tm/js/src/Operation.js +19 -0
  39. package/project/.sdk/tm/js/src/Point.js +24 -0
  40. package/project/.sdk/tm/js/src/README.md +1 -0
  41. package/project/.sdk/tm/js/src/Response.js +19 -0
  42. package/project/.sdk/tm/js/src/Result.js +21 -0
  43. package/project/.sdk/tm/js/src/Spec.js +26 -0
  44. package/project/.sdk/tm/js/src/feature/README.md +1 -0
  45. package/project/.sdk/tm/js/src/feature/base/BaseFeature.js +45 -0
  46. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +46 -47
  47. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +207 -0
  48. package/project/.sdk/tm/js/src/types.js +22 -0
  49. package/project/.sdk/tm/js/src/utility/CleanUtility.js +31 -0
  50. package/project/.sdk/tm/js/src/utility/DoneUtility.js +11 -4
  51. package/project/.sdk/tm/js/src/utility/FeatureAddUtility.js +42 -0
  52. package/project/.sdk/tm/js/src/utility/FeatureHookUtility.js +25 -0
  53. package/project/.sdk/tm/js/src/utility/FeatureInitUtility.js +11 -0
  54. package/project/.sdk/tm/js/src/utility/FetcherUtility.js +28 -0
  55. package/project/.sdk/tm/js/src/utility/MakeContextUtility.js +11 -0
  56. package/project/.sdk/tm/js/src/utility/MakeErrorUtility.js +55 -0
  57. package/project/.sdk/tm/js/src/utility/MakeFetchDefUtility.js +44 -0
  58. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +93 -0
  59. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +77 -0
  60. package/project/.sdk/tm/js/src/utility/MakeRequestUtility.js +63 -0
  61. package/project/.sdk/tm/js/src/utility/MakeResponseUtility.js +55 -0
  62. package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +54 -0
  63. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +58 -0
  64. package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +40 -0
  65. package/project/.sdk/tm/js/src/utility/ParamUtility.js +61 -0
  66. package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +41 -0
  67. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +25 -0
  68. package/project/.sdk/tm/js/src/utility/PrepareHeadersUtility.js +18 -0
  69. package/project/.sdk/tm/js/src/utility/{MethodUtility.js → PrepareMethodUtility.js} +7 -7
  70. package/project/.sdk/tm/js/src/utility/PrepareParamsUtility.js +25 -0
  71. package/project/.sdk/tm/js/src/utility/PreparePathUtility.js +13 -0
  72. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +26 -0
  73. package/project/.sdk/tm/js/src/utility/README.md +1 -0
  74. package/project/.sdk/tm/js/src/utility/ResultBasicUtility.js +34 -0
  75. package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +18 -0
  76. package/project/.sdk/tm/js/src/utility/ResultHeadersUtility.js +22 -0
  77. package/project/.sdk/tm/js/src/utility/StructUtility.js +2219 -1078
  78. package/project/.sdk/tm/js/src/utility/TransformRequestUtility.js +28 -0
  79. package/project/.sdk/tm/js/src/utility/TransformResponseUtility.js +31 -0
  80. package/project/.sdk/tm/js/src/utility/Utility.js +61 -61
  81. package/project/.sdk/tm/js/test/README.md +1 -0
  82. package/project/.sdk/tm/js/test/exists.test.js +16 -0
  83. package/project/.sdk/tm/js/test/runner.js +323 -107
  84. package/project/.sdk/tm/js/test/utility/Custom.test.js +41 -63
  85. package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +390 -116
  86. package/project/.sdk/tm/js/test/utility/StructUtility.test.js +728 -175
  87. package/project/.sdk/tm/js/test/utility/index.js +9 -0
  88. package/project/.sdk/tm/js/test/utility.js +72 -0
  89. package/project/.sdk/tm/lua/test/primary_utility_test.lua +1213 -0
  90. package/project/.sdk/tm/lua/test/runner.lua +2 -2
  91. package/project/.sdk/tm/lua/test/struct_runner.lua +602 -0
  92. package/project/.sdk/tm/lua/test/struct_utility_test.lua +959 -0
  93. package/project/.sdk/tm/lua/utility/struct/struct.lua +10 -0
  94. package/project/.sdk/tm/php/feature/TestFeature.php +59 -96
  95. package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +1309 -0
  96. package/project/.sdk/tm/php/test/Runner.php +24 -1
  97. package/project/.sdk/tm/php/test/StructRunner.php +275 -0
  98. package/project/.sdk/tm/php/test/StructUtilityTest.php +1336 -0
  99. package/project/.sdk/tm/php/utility/Fetcher.php +6 -2
  100. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -1
  101. package/project/.sdk/tm/php/utility/MakeResult.php +3 -0
  102. package/project/.sdk/tm/php/utility/Param.php +9 -7
  103. package/project/.sdk/tm/php/utility/struct/Struct.php +312 -208
  104. package/project/.sdk/tm/py/test/runner.py +13 -0
  105. package/project/.sdk/tm/py/test/struct_runner.py +411 -0
  106. package/project/.sdk/tm/py/test/test_primary_utility.py +1101 -0
  107. package/project/.sdk/tm/py/test/test_struct_utility.py +751 -0
  108. package/project/.sdk/tm/rb/test/primary_utility_test.rb +1083 -0
  109. package/project/.sdk/tm/rb/test/runner.rb +5 -0
  110. package/project/.sdk/tm/rb/test/struct_runner.rb +309 -0
  111. package/project/.sdk/tm/rb/test/struct_utility_test.rb +670 -0
  112. package/src/cmp/Main.ts +1 -16
  113. package/project/.sdk/src/cmp/js/Quick_js.ts +0 -78
  114. package/project/.sdk/src/cmp/js/TestAcceptEntity_js.ts +0 -13
  115. package/project/.sdk/src/cmp/js/TestAccept_js.ts +0 -18
  116. package/project/.sdk/tm/js/src/utility/AuthUtility.js +0 -21
  117. package/project/.sdk/tm/js/src/utility/BodyUtility.js +0 -29
  118. package/project/.sdk/tm/js/src/utility/ErrorUtility.js +0 -33
  119. package/project/.sdk/tm/js/src/utility/FindparamUtility.js +0 -31
  120. package/project/.sdk/tm/js/src/utility/FullurlUtility.js +0 -39
  121. package/project/.sdk/tm/js/src/utility/HeadersUtility.js +0 -13
  122. package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +0 -14
  123. package/project/.sdk/tm/js/src/utility/OperatorUtility.js +0 -44
  124. package/project/.sdk/tm/js/src/utility/OptionsUtility.js +0 -54
  125. package/project/.sdk/tm/js/src/utility/ParamsUtility.js +0 -21
  126. package/project/.sdk/tm/js/src/utility/QueryUtility.js +0 -21
  127. package/project/.sdk/tm/js/src/utility/ReqformUtility.js +0 -32
  128. package/project/.sdk/tm/js/src/utility/RequestUtility.js +0 -48
  129. package/project/.sdk/tm/js/src/utility/ResbasicUtility.js +0 -27
  130. package/project/.sdk/tm/js/src/utility/ResbodyUtility.js +0 -15
  131. package/project/.sdk/tm/js/src/utility/ResformUtility.js +0 -34
  132. package/project/.sdk/tm/js/src/utility/ResheadersUtility.js +0 -19
  133. package/project/.sdk/tm/js/src/utility/ResponseUtility.js +0 -37
  134. package/project/.sdk/tm/js/src/utility/ResultUtility.js +0 -28
  135. package/project/.sdk/tm/js/src/utility/SpecUtility.js +0 -35
@@ -0,0 +1,751 @@
1
+ # Vendored from voxgig/struct/py
2
+ # RUN: python -m unittest discover -s tests
3
+ # RUN-SOME: python -m unittest discover -s tests -k getpath
4
+
5
+ import os
6
+ import unittest
7
+
8
+ from test.struct_runner import (
9
+ makeRunner,
10
+ nullModifier,
11
+ NULLMARK,
12
+ UNDEFMARK,
13
+ StructTestClient,
14
+ )
15
+
16
+ from utility.voxgig_struct import voxgig_struct as vs
17
+ from utility.voxgig_struct.voxgig_struct import (
18
+ T_noval, T_scalar, T_function, T_symbol, T_any, T_node, T_instance, T_null,
19
+ )
20
+
21
+
22
+ STRUCT_TEST_JSON = os.path.join(
23
+ os.path.dirname(os.path.abspath(__file__)), '../../.sdk/test/test.json')
24
+
25
+ sdk_client = StructTestClient.test()
26
+ runner = makeRunner(STRUCT_TEST_JSON, sdk_client)
27
+ runparts = runner('struct')
28
+
29
+ spec = runparts["spec"]
30
+ runset = runparts["runset"]
31
+ runsetflags = runparts["runsetflags"]
32
+ client = runparts["client"]
33
+
34
+ # Get all the struct utilities from the client
35
+ struct_utils = client.utility().struct
36
+ clone = struct_utils.clone
37
+ delprop = struct_utils.delprop
38
+ escre = struct_utils.escre
39
+ escurl = struct_utils.escurl
40
+ filter_fn = struct_utils.filter
41
+ flatten = struct_utils.flatten
42
+ getelem = struct_utils.getelem
43
+ getpath = struct_utils.getpath
44
+ getprop = struct_utils.getprop
45
+ haskey = struct_utils.haskey
46
+ inject = struct_utils.inject
47
+ isempty = struct_utils.isempty
48
+ isfunc = struct_utils.isfunc
49
+ iskey = struct_utils.iskey
50
+ islist = struct_utils.islist
51
+ ismap = struct_utils.ismap
52
+ isnode = struct_utils.isnode
53
+ items = struct_utils.items
54
+ ja = struct_utils.ja
55
+ jo = struct_utils.jo
56
+ joinurl = struct_utils.joinurl
57
+ jsonify = struct_utils.jsonify
58
+ keysof = struct_utils.keysof
59
+ merge = struct_utils.merge
60
+ pad = struct_utils.pad
61
+ pathify = struct_utils.pathify
62
+ select = struct_utils.select
63
+ setpath = struct_utils.setpath
64
+ setprop = struct_utils.setprop
65
+ DELETE = struct_utils.DELETE
66
+ size = struct_utils.size
67
+ slice = struct_utils.slice
68
+ stringify = struct_utils.stringify
69
+ strkey = struct_utils.strkey
70
+ transform = struct_utils.transform
71
+ typename = struct_utils.typename
72
+ typify = struct_utils.typify
73
+ validate = struct_utils.validate
74
+ walk = struct_utils.walk
75
+
76
+ minorSpec = spec["minor"]
77
+ walkSpec = spec["walk"]
78
+ mergeSpec = spec["merge"]
79
+ getpathSpec = spec["getpath"]
80
+ injectSpec = spec["inject"]
81
+ transformSpec = spec["transform"]
82
+ validateSpec = spec["validate"]
83
+ selectSpec = spec["select"]
84
+
85
+
86
+ class TestStructUtility(unittest.TestCase):
87
+
88
+ # minor tests
89
+ # ===========
90
+
91
+ def test_exists(self):
92
+ self.assertTrue(callable(clone))
93
+ self.assertTrue(callable(escre))
94
+ self.assertTrue(callable(escurl))
95
+ self.assertTrue(callable(getprop))
96
+ self.assertTrue(callable(getpath))
97
+
98
+ self.assertTrue(callable(haskey))
99
+ self.assertTrue(callable(inject))
100
+ self.assertTrue(callable(isempty))
101
+ self.assertTrue(callable(isfunc))
102
+ self.assertTrue(callable(iskey))
103
+
104
+ self.assertTrue(callable(islist))
105
+ self.assertTrue(callable(ismap))
106
+ self.assertTrue(callable(isnode))
107
+ self.assertTrue(callable(items))
108
+ self.assertTrue(callable(joinurl))
109
+
110
+ self.assertTrue(callable(keysof))
111
+ self.assertTrue(callable(merge))
112
+ self.assertTrue(callable(pathify))
113
+ self.assertTrue(callable(setprop))
114
+ self.assertTrue(callable(strkey))
115
+
116
+ self.assertTrue(callable(stringify))
117
+ self.assertTrue(callable(transform))
118
+ self.assertTrue(callable(typify))
119
+ self.assertTrue(callable(validate))
120
+ self.assertTrue(callable(walk))
121
+
122
+
123
+ def test_minor_isnode(self):
124
+ runset(minorSpec["isnode"], isnode)
125
+
126
+
127
+ def test_minor_ismap(self):
128
+ runset(minorSpec["ismap"], ismap)
129
+
130
+
131
+ def test_minor_islist(self):
132
+ runset(minorSpec["islist"], islist)
133
+
134
+
135
+ def test_minor_iskey(self):
136
+ runsetflags(minorSpec["iskey"], {"null": False}, iskey)
137
+
138
+
139
+ def test_minor_strkey(self):
140
+ runsetflags(minorSpec["strkey"], {"null": False}, strkey)
141
+
142
+
143
+ def test_minor_isempty(self):
144
+ runsetflags(minorSpec["isempty"], {"null": False}, isempty)
145
+
146
+
147
+ def test_minor_isfunc(self):
148
+ runset(minorSpec["isfunc"], isfunc)
149
+ def f0():
150
+ return None
151
+ self.assertTrue(isfunc(f0))
152
+ self.assertTrue(isfunc(lambda: None))
153
+
154
+
155
+ def test_minor_clone(self):
156
+ runsetflags(minorSpec["clone"], {"null": False}, clone)
157
+ def f0():
158
+ return None
159
+ self.assertEqual({"a":f0}, clone({"a":f0}))
160
+
161
+
162
+ def test_minor_escre(self):
163
+ runset(minorSpec["escre"], escre)
164
+
165
+
166
+ def test_minor_escurl(self):
167
+ runset(minorSpec["escurl"], escurl)
168
+
169
+
170
+ def test_minor_stringify(self):
171
+ runset(minorSpec["stringify"],
172
+ lambda vin: stringify("null" if NULLMARK == vin.get('val') else
173
+ vin.get('val'), vin.get('max')))
174
+
175
+ def test_minor_jsonify(self):
176
+ runsetflags(minorSpec["jsonify"], {"null": False},
177
+ lambda vin: jsonify(vin.get("val"), vin.get("flags")))
178
+
179
+ def test_minor_getelem(self):
180
+ def getelem_wrapper(vin):
181
+ if vin.get("alt") is None:
182
+ return getelem(vin.get("val"), vin.get("key"))
183
+ else:
184
+ return getelem(vin.get("val"), vin.get("key"), vin.get("alt"))
185
+ runsetflags(minorSpec["getelem"], {"null": False}, getelem_wrapper)
186
+
187
+ def test_minor_delprop(self):
188
+ def delprop_wrapper(vin):
189
+ return delprop(vin.get("parent"), vin.get("key"))
190
+ runset(minorSpec["delprop"], delprop_wrapper)
191
+
192
+ def test_minor_edge_clone(self):
193
+ x = {"y": 1}
194
+ xc = clone(x)
195
+ self.assertEqual(x, xc)
196
+ self.assertIsNot(x, xc)
197
+
198
+ def test_minor_edge_items(self):
199
+ a0 = [11, 22, 33]
200
+ self.assertEqual(items(a0), [['0', 11], ['1', 22], ['2', 33]])
201
+
202
+ def test_minor_edge_getelem(self):
203
+ self.assertEqual(getelem([], 1, lambda: 2), 2)
204
+
205
+ def test_minor_edge_jsonify(self):
206
+ self.assertEqual(jsonify(lambda: 1), 'null')
207
+
208
+ def test_minor_edge_keysof(self):
209
+ a0 = [11, 22, 33]
210
+ self.assertEqual(keysof(a0), ['0', '1', '2'])
211
+
212
+ def test_minor_edge_stringify(self):
213
+ a = {}
214
+ a["a"] = a
215
+ self.assertEqual(stringify(a), '__STRINGIFY_FAILED__')
216
+
217
+ self.assertEqual(stringify({"a": [9]}, -1, True),
218
+ '\x1b[38;5;81m\x1b[38;5;118m{\x1b[38;5;118ma\x1b[38;5;118m:'
219
+ '\x1b[38;5;213m[\x1b[38;5;213m9\x1b[38;5;213m]\x1b[38;5;118m}\x1b[0m')
220
+
221
+ def test_minor_edge_delprop(self):
222
+ # String array tests
223
+ strarr0 = ['a', 'b', 'c', 'd', 'e']
224
+ strarr1 = ['a', 'b', 'c', 'd', 'e']
225
+ self.assertEqual(delprop(strarr0, 2), ['a', 'b', 'd', 'e'])
226
+ self.assertEqual(delprop(strarr1, '2'), ['a', 'b', 'd', 'e'])
227
+
228
+ # Integer array tests
229
+ intarr0 = [2, 3, 5, 7, 11]
230
+ intarr1 = [2, 3, 5, 7, 11]
231
+ self.assertEqual(delprop(intarr0, 2), [2, 3, 7, 11])
232
+ self.assertEqual(delprop(intarr1, '2'), [2, 3, 7, 11])
233
+
234
+ def test_minor_size(self):
235
+ runsetflags(minorSpec["size"], {"null": False}, size)
236
+
237
+ def test_minor_slice(self):
238
+ def slice_wrapper(vin):
239
+ return slice(vin.get("val"), vin.get("start"), vin.get("end"))
240
+ runsetflags(minorSpec["slice"], {"null": False}, slice_wrapper)
241
+
242
+ def test_minor_pad(self):
243
+ def pad_wrapper(vin):
244
+ return pad(vin.get("val"), vin.get("pad"), vin.get("char"))
245
+ runsetflags(minorSpec["pad"], {"null": False}, pad_wrapper)
246
+
247
+
248
+ def test_minor_pathify(self):
249
+ def pathify_wrapper(vin=None):
250
+ path = vin.get("path")
251
+ path = None if NULLMARK == path else path
252
+ pathstr = pathify(path, vin.get("from")).replace("__NULL__.","")
253
+ pathstr = pathstr.replace(">", ":null>") if NULLMARK == vin.get('path') else pathstr
254
+ return pathstr
255
+ runsetflags(minorSpec["pathify"], {"null": True}, pathify_wrapper)
256
+
257
+
258
+ def test_minor_items(self):
259
+ runset(minorSpec["items"], items)
260
+
261
+
262
+ def test_minor_getprop(self):
263
+ def getprop_wrapper(vin):
264
+ if vin.get("alt") is None:
265
+ return getprop(vin.get("val"), vin.get("key"))
266
+ else:
267
+ return getprop(vin.get("val"), vin.get("key"), vin.get("alt"))
268
+ runsetflags(minorSpec["getprop"], {"null": False}, getprop_wrapper)
269
+
270
+ def test_minor_edge_getprop(self):
271
+ # String array tests
272
+ strarr = ['a', 'b', 'c', 'd', 'e']
273
+ self.assertEqual(getprop(strarr, 2), 'c')
274
+ self.assertEqual(getprop(strarr, '2'), 'c')
275
+
276
+ # Integer array tests
277
+ intarr = [2, 3, 5, 7, 11]
278
+ self.assertEqual(getprop(intarr, 2), 5)
279
+ self.assertEqual(getprop(intarr, '2'), 5)
280
+
281
+
282
+ def test_minor_setprop(self):
283
+ runset(minorSpec["setprop"],
284
+ lambda vin: setprop(vin.get("parent"), vin.get("key"), vin.get("val")))
285
+
286
+
287
+ def test_minor_edge_setprop(self):
288
+ # String array tests
289
+ strarr0 = ['a', 'b', 'c', 'd', 'e']
290
+ strarr1 = ['a', 'b', 'c', 'd', 'e']
291
+ self.assertEqual(setprop(strarr0, 2, 'C'), ['a', 'b', 'C', 'd', 'e'])
292
+ self.assertEqual(setprop(strarr1, '2', 'CC'), ['a', 'b', 'CC', 'd', 'e'])
293
+
294
+ # Integer array tests
295
+ intarr0 = [2, 3, 5, 7, 11]
296
+ intarr1 = [2, 3, 5, 7, 11]
297
+ self.assertEqual(setprop(intarr0, 2, 55), [2, 3, 55, 7, 11])
298
+ self.assertEqual(setprop(intarr1, '2', 555), [2, 3, 555, 7, 11])
299
+
300
+
301
+ def test_minor_haskey(self):
302
+ runsetflags(minorSpec["haskey"], {"null": False},
303
+ lambda vin: haskey(vin.get("src"), vin.get("key")))
304
+
305
+
306
+ def test_minor_keysof(self):
307
+ runset(minorSpec["keysof"], keysof)
308
+
309
+
310
+ def test_minor_joinurl(self):
311
+ from utility.voxgig_struct.voxgig_struct import join as struct_join
312
+ runsetflags(minorSpec["join"], {"null": False},
313
+ lambda vin: struct_join(vin.get("val"), vin.get("sep"), vin.get("url")))
314
+
315
+
316
+ def test_minor_typify(self):
317
+ runsetflags(minorSpec["typify"], {"null": False}, typify)
318
+
319
+ def test_minor_edge_typify(self):
320
+ self.assertEqual(typify(), T_noval)
321
+ self.assertEqual(typify(None), T_scalar | T_null)
322
+ self.assertEqual(typify(float('nan')), T_noval)
323
+ self.assertEqual(typify(lambda: None), T_scalar | T_function)
324
+
325
+ def test_minor_setpath(self):
326
+ runsetflags(minorSpec["setpath"], {"null": False},
327
+ lambda vin: setpath(vin.get("store"), vin.get("path"), vin.get("val")))
328
+
329
+ def test_minor_edge_setpath(self):
330
+ x = {"y": {"z": 1, "q": 2}}
331
+ self.assertEqual(setpath(x, 'y.q', DELETE), {"z": 1})
332
+ self.assertEqual(x, {"y": {"z": 1}})
333
+
334
+ def test_minor_filter(self):
335
+ checkmap = {
336
+ 'gt3': lambda n: n[1] > 3,
337
+ 'lt3': lambda n: n[1] < 3,
338
+ }
339
+ runset(minorSpec["filter"],
340
+ lambda vin: filter_fn(vin.get("val"), checkmap[vin.get("check")]))
341
+
342
+ def test_minor_typename(self):
343
+ runset(minorSpec["typename"], typename)
344
+
345
+ def test_minor_flatten(self):
346
+ runset(minorSpec["flatten"],
347
+ lambda vin: flatten(vin.get("val"), vin.get("depth")))
348
+
349
+ # walk tests
350
+ # ==========
351
+
352
+ def test_walk_log(self):
353
+ test_data = clone(walkSpec["log"])
354
+
355
+ log = []
356
+
357
+ def walklog(key, val, parent, path):
358
+ log.append('k=' + stringify(key) +
359
+ ', v=' + stringify(val) +
360
+ ', p=' + stringify(parent) +
361
+ ', t=' + pathify(path))
362
+ return val
363
+
364
+ # Test after callback (Python walk only supports after, not before)
365
+ # TODO: Python walk() needs to be updated to support before/after callbacks like TypeScript
366
+ walk(test_data["in"], walklog)
367
+ self.assertEqual(log, test_data["out"]["after"])
368
+
369
+ def test_walk_basic(self):
370
+ def walkpath(_key, val, _parent, path):
371
+ if isinstance(val, str):
372
+ return val + '~' + '.'.join(str(p) for p in path)
373
+ return val
374
+
375
+ def walk_wrapper(vin=None):
376
+ return walk(vin, walkpath)
377
+
378
+ runset(walkSpec["basic"], walk_wrapper)
379
+
380
+ def test_walk_copy(self):
381
+ cur = [None]
382
+
383
+ def walkcopy(key, val, _parent, path):
384
+ if key is None:
385
+ cur[0] = [None]
386
+ cur[0][0] = {} if ismap(val) else [] if islist(val) else val
387
+ return val
388
+
389
+ v = val
390
+ i = size(path)
391
+
392
+ if isnode(v):
393
+ while len(cur[0]) <= i:
394
+ cur[0].append(None)
395
+ v = cur[0][i] = {} if ismap(v) else []
396
+
397
+ setprop(cur[0][i - 1], key, v)
398
+
399
+ return val
400
+
401
+ def walk_copy_wrapper(vin=None):
402
+ walk(vin, before=walkcopy)
403
+ return cur[0][0]
404
+
405
+ runset(walkSpec["copy"], walk_copy_wrapper)
406
+
407
+ def test_walk_depth(self):
408
+ def walk_depth_wrapper(vin):
409
+ state = {'top': None, 'cur': None}
410
+
411
+ def copy(key, val, _parent, _path):
412
+ if key is None or isnode(val):
413
+ child = [] if islist(val) else {}
414
+ if key is None:
415
+ state['top'] = state['cur'] = child
416
+ else:
417
+ state['cur'][key] = child
418
+ state['cur'] = child
419
+ else:
420
+ state['cur'][key] = val
421
+ return val
422
+
423
+ walk(vin.get("src"), before=copy, maxdepth=vin.get("maxdepth"))
424
+ return state['top']
425
+
426
+ runsetflags(walkSpec["depth"], {"null": False}, walk_depth_wrapper)
427
+
428
+ # merge tests
429
+ # ===========
430
+
431
+
432
+
433
+ def test_merge_basic(self):
434
+ test_data = clone(spec["merge"]["basic"])
435
+ self.assertEqual(merge(test_data["in"]), test_data["out"])
436
+
437
+ def test_merge_cases(self):
438
+ runset(spec["merge"]["cases"], merge)
439
+
440
+ def test_merge_array(self):
441
+ runset(spec["merge"]["array"], merge)
442
+
443
+ def test_merge_integrity(self):
444
+ runset(spec["merge"]["integrity"], merge)
445
+
446
+ def test_merge_depth(self):
447
+ runset(spec["merge"]["depth"],
448
+ lambda vin: merge(vin.get("val"), vin.get("depth")))
449
+
450
+ def test_merge_special(self):
451
+ def f0():
452
+ return None
453
+ self.assertEqual(merge([f0]), f0)
454
+ self.assertEqual(merge([None, f0]), f0)
455
+ self.assertEqual(merge([{"a": f0}]), {"a": f0})
456
+ self.assertEqual(merge([[f0]]), [f0])
457
+ self.assertEqual(merge([{"a": {"b": f0}}]), {"a": {"b": f0}})
458
+
459
+
460
+ # -------------------------------------------------
461
+ # getpath tests
462
+ # -------------------------------------------------
463
+
464
+
465
+
466
+ def test_getpath_basic(self):
467
+ def getpath_wrapper(vin):
468
+ return getpath(vin.get("store"), vin.get("path"))
469
+ runset(spec["getpath"]["basic"], getpath_wrapper)
470
+
471
+ def test_getpath_relative(self):
472
+ def getpath_wrapper(vin):
473
+ dpath = vin.get("dpath")
474
+ if dpath:
475
+ dpath = dpath.split('.')
476
+ injdef = {"dparent": vin.get("dparent"), "dpath": dpath}
477
+ return getpath(vin.get("store"), vin.get("path"), injdef)
478
+ runset(spec["getpath"]["relative"], getpath_wrapper)
479
+
480
+ def test_getpath_special(self):
481
+ def getpath_wrapper(vin):
482
+ return getpath(vin.get("store"), vin.get("path"), vin.get("inj"))
483
+ runset(spec["getpath"]["special"], getpath_wrapper)
484
+
485
+ def test_getpath_handler(self):
486
+ def getpath_wrapper(vin):
487
+ def handler(inj, val, ref, store):
488
+ return val() if callable(val) else val
489
+
490
+ return getpath({
491
+ "$TOP": vin.get("store"),
492
+ "$FOO": lambda: "foo"
493
+ }, vin.get("path"), {"handler": handler})
494
+ runset(spec["getpath"]["handler"], getpath_wrapper)
495
+
496
+ # -------------------------------------------------
497
+ # inject tests
498
+ # -------------------------------------------------
499
+
500
+
501
+
502
+ def test_inject_basic(self):
503
+ test_data = clone(spec["inject"]["basic"])
504
+ self.assertEqual(
505
+ inject(test_data["in"]["val"], test_data["in"]["store"]),
506
+ test_data["out"]
507
+ )
508
+
509
+ def test_inject_string(self):
510
+ def inject_wrapper(vin):
511
+ return inject(vin.get("val"), vin.get("store"), {"modify": nullModifier, "extra": vin.get("current")})
512
+ runset(spec["inject"]["string"], inject_wrapper)
513
+
514
+ def test_inject_deep(self):
515
+ runset(spec["inject"]["deep"], lambda vin: inject(vin.get("val"), vin.get("store")))
516
+
517
+ # -------------------------------------------------
518
+ # transform tests
519
+ # Inputs and expected outputs: build/test/transform.jsonic
520
+ # -------------------------------------------------
521
+
522
+ def test_transform_basic(self):
523
+ test_data = clone(spec["transform"]["basic"])
524
+ test_data_in = test_data.get("in")
525
+ self.assertEqual(
526
+ transform(
527
+ test_data_in.get("data"),
528
+ test_data_in.get("spec"),
529
+ test_data_in.get("store")
530
+ ),
531
+ test_data["out"]
532
+ )
533
+
534
+ def test_transform_paths(self):
535
+ def transform_wrapper(vin):
536
+ return transform(vin.get("data"), vin.get("spec"), vin.get("store"))
537
+ runset(spec["transform"]["paths"], transform_wrapper)
538
+
539
+ def test_transform_cmds(self):
540
+ def transform_wrapper(vin):
541
+ return transform(vin.get("data"), vin.get("spec"), vin.get("store"))
542
+ runset(spec["transform"]["cmds"], transform_wrapper)
543
+
544
+ def test_transform_each(self):
545
+ def transform_wrapper(vin):
546
+ return transform(vin.get("data"), vin.get("spec"), vin.get("store"))
547
+ runset(spec["transform"]["each"], transform_wrapper)
548
+
549
+ def test_transform_pack(self):
550
+ def transform_wrapper(vin):
551
+ return transform(vin.get("data"), vin.get("spec"), vin.get("store"))
552
+ runset(spec["transform"]["pack"], transform_wrapper)
553
+
554
+ def test_transform_ref(self):
555
+ def transform_wrapper(vin):
556
+ return transform(vin.get("data"), vin.get("spec"), vin.get("store"))
557
+ runset(spec["transform"]["ref"], transform_wrapper)
558
+
559
+ def test_transform_modify(self):
560
+ def modifier(val, key, parent, inj):
561
+ if key is not None and parent is not None and isinstance(val, str):
562
+ parent[key] = '@' + val
563
+
564
+ runset(spec["transform"]["modify"],
565
+ lambda vin: transform(vin.get("data"), vin.get("spec"), {"modify": modifier, "extra": vin.get("store")}))
566
+
567
+ def test_transform_extra(self):
568
+ def upper_func(state, val, current, ref, store):
569
+ path = state.path
570
+ this_key = path[-1] if path else None
571
+ return str(this_key).upper()
572
+
573
+ self.assertEqual(
574
+ transform(
575
+ {"a": 1},
576
+ {"x": "`a`", "b": "`$COPY`", "c": "`$UPPER`"},
577
+ {
578
+ "extra": {
579
+ "b": 2,
580
+ "$UPPER": upper_func
581
+ }
582
+ }
583
+ ),
584
+ {"x": 1, "b": 2, "c": "C"}
585
+ )
586
+
587
+ def test_transform_format(self):
588
+ def transform_wrapper(vin):
589
+ return transform(vin.get("data"), vin.get("spec"))
590
+ runsetflags(spec["transform"]["format"], {"null": False}, transform_wrapper)
591
+
592
+ def test_transform_apply(self):
593
+ def transform_wrapper(vin):
594
+ return transform(vin.get("data"), vin.get("spec"))
595
+ runset(spec["transform"]["apply"], transform_wrapper)
596
+
597
+ def test_transform_edge_apply(self):
598
+ self.assertEqual(2, transform({}, ['`$APPLY`', lambda v: 1 + v, 1]))
599
+
600
+ def test_transform_funcval(self):
601
+ def f0():
602
+ return 99
603
+
604
+ self.assertEqual(transform({}, {"x": 1}), {"x": 1})
605
+ self.assertEqual(transform({}, {"x": f0}), {"x": f0})
606
+ self.assertEqual(transform({"a": 1}, {"x": "`a`"}), {"x": 1})
607
+ self.assertEqual(transform({"f0": f0}, {"x": "`f0`"}), {"x": f0})
608
+
609
+ # -------------------------------------------------
610
+ # validate tests
611
+ # -------------------------------------------------
612
+
613
+
614
+
615
+ def test_validate_basic(self):
616
+ def validate_wrapper(vin):
617
+ return validate(vin.get("data"), vin.get("spec"))
618
+ runsetflags(spec["validate"]["basic"], {"null": False}, validate_wrapper)
619
+
620
+
621
+ def test_validate_child(self):
622
+ def validate_wrapper(vin):
623
+ return validate(vin.get("data"), vin.get("spec"))
624
+ runset(spec["validate"]["child"], validate_wrapper)
625
+
626
+ def test_validate_one(self):
627
+ def validate_wrapper(vin):
628
+ return validate(vin.get("data"), vin.get("spec"))
629
+ runset(spec["validate"]["one"], validate_wrapper)
630
+
631
+ def test_validate_exact(self):
632
+ def validate_wrapper(vin):
633
+ return validate(vin.get("data"), vin.get("spec"))
634
+ runset(spec["validate"]["exact"], validate_wrapper)
635
+
636
+
637
+ def test_validate_invalid(self):
638
+ runsetflags(spec["validate"]["invalid"], {"null": False},
639
+ lambda vin: validate(vin.get("data"), vin.get("spec")))
640
+
641
+ def test_validate_special(self):
642
+ def validate_wrapper(vin):
643
+ return validate(vin.get("data"), vin.get("spec"), vin.get("inj"))
644
+ runset(spec["validate"]["special"], validate_wrapper)
645
+
646
+
647
+ def test_validate_custom(self):
648
+ errs = []
649
+
650
+ def integer_check(state, _val, current, _ref, _store):
651
+ key = state.key
652
+ out = getprop(current, key)
653
+
654
+ if not isinstance(out, int) and not (isinstance(out, float) and out.is_integer()):
655
+ state.errs.append(
656
+ f"Not an integer at {'.'.join(state.path[1:])}: {out}"
657
+ )
658
+ return None
659
+
660
+ return out
661
+
662
+ extra = {
663
+ "$INTEGER": integer_check
664
+ }
665
+
666
+ shape = {"a": "`$INTEGER`"}
667
+
668
+ # Test with valid integer
669
+ out = validate({"a": 1}, shape, {"extra": extra, "errs": errs})
670
+ self.assertEqual(out, {"a": 1})
671
+ self.assertEqual(len(errs), 0)
672
+
673
+ # Test with invalid value
674
+ out = validate({"a": "A"}, shape, {"extra": extra, "errs": errs})
675
+ self.assertEqual(out, {"a": "A"})
676
+ self.assertEqual(errs, ["Not an integer at a: A"])
677
+
678
+ def test_validate_edge(self):
679
+ errs = []
680
+ validate({"x": 1}, {"x": '`$INSTANCE`'}, {"errs": errs})
681
+ self.assertEqual(errs[0], 'Expected field x to be instance, but found integer: 1.')
682
+
683
+ errs = []
684
+ validate({"x": {}}, {"x": '`$INSTANCE`'}, {"errs": errs})
685
+ self.assertEqual(errs[0], 'Expected field x to be instance, but found map: {}.')
686
+
687
+ errs = []
688
+ validate({"x": []}, {"x": '`$INSTANCE`'}, {"errs": errs})
689
+ self.assertEqual(errs[0], 'Expected field x to be instance, but found list: [].')
690
+
691
+ # -------------------------------------------------
692
+ # select tests
693
+ # -------------------------------------------------
694
+
695
+ def test_select_basic(self):
696
+ def select_wrapper(vin):
697
+ return select(vin.get("obj"), vin.get("query"))
698
+ runset(selectSpec["basic"], select_wrapper)
699
+
700
+ def test_select_operators(self):
701
+ def select_wrapper(vin):
702
+ return select(vin.get("obj"), vin.get("query"))
703
+ runset(selectSpec["operators"], select_wrapper)
704
+
705
+ def test_select_edge(self):
706
+ def select_wrapper(vin):
707
+ return select(vin.get("obj"), vin.get("query"))
708
+ runset(selectSpec["edge"], select_wrapper)
709
+
710
+ def test_select_alts(self):
711
+ def select_wrapper(vin):
712
+ return select(vin.get("obj"), vin.get("query"))
713
+ runset(selectSpec["alts"], select_wrapper)
714
+
715
+ # -------------------------------------------------
716
+ # JSON Builder tests
717
+ # -------------------------------------------------
718
+
719
+ def test_json_builder(self):
720
+ self.assertEqual(jsonify(jo('a', 1)), '{\n "a": 1\n}')
721
+
722
+ self.assertEqual(jsonify(ja('b', 2)), '[\n "b",\n 2\n]')
723
+
724
+ self.assertEqual(jsonify(jo(
725
+ 'c', 'C',
726
+ 'd', jo('x', True),
727
+ 'e', ja(None, False)
728
+ )), '{\n "c": "C",\n "d": {\n "x": true\n },\n "e": [\n null,\n false\n ]\n}')
729
+
730
+ self.assertEqual(jsonify(ja(
731
+ 3.3, jo(
732
+ 'f', True,
733
+ 'g', False,
734
+ 'h', None,
735
+ 'i', ja('y', 0),
736
+ 'j', jo('z', -1),
737
+ 'k')
738
+ )), '[\n 3.3,\n {\n "f": true,\n "g": false,\n "h": null,\n "i": [\n "y",\n 0\n ],\n "j": {\n "z": -1\n },\n "k": null\n }\n]')
739
+
740
+ self.assertEqual(jsonify(jo(
741
+ True, 1,
742
+ False, 2,
743
+ None, 3,
744
+ ['a'], 4,
745
+ {'b': 0}, 5
746
+ )), '{\n "true": 1,\n "false": 2,\n "null": 3,\n "[a]": 4,\n "{b:0}": 5\n}')
747
+
748
+
749
+ # If you want to run this file directly, add:
750
+ if __name__ == "__main__":
751
+ unittest.main()