test_sqlite3.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.unit import TestCase
  6. # Import Salt Libs
  7. import salt.pillar.sqlite3 as sqlite3
  8. class SQLite3PillarTestCase(TestCase):
  9. maxDiff = None
  10. def test_001_extract_queries_list(self):
  11. return_data = sqlite3.SQLite3ExtPillar()
  12. args, kwargs = [
  13. 'SELECT blah',
  14. 'SELECT blah2',
  15. ('SELECT blah3',),
  16. ('SELECT blah4', 2),
  17. {'query': 'SELECT blah5'},
  18. {'query': 'SELECT blah6', 'depth': 2},
  19. {'query': 'SELECT blah7', 'as_list': True},
  20. {'query': 'SELECT blah8', 'with_lists': '1'},
  21. {'query': 'SELECT blah9', 'with_lists': '1,2'}
  22. ], {}
  23. qbuffer = return_data.extract_queries(args, kwargs)
  24. self.assertEqual([
  25. [None, {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  26. 'with_lists': None, 'ignore_null': False}],
  27. [None, {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  28. 'with_lists': None, 'ignore_null': False}],
  29. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  30. 'with_lists': None, 'ignore_null': False}],
  31. [None, {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  32. 'with_lists': None, 'ignore_null': False}],
  33. [None, {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  34. 'with_lists': None, 'ignore_null': False}],
  35. [None, {'query': 'SELECT blah6', 'depth': 2, 'as_list': False,
  36. 'with_lists': None, 'ignore_null': False}],
  37. [None, {'query': 'SELECT blah7', 'depth': 0, 'as_list': True,
  38. 'with_lists': None, 'ignore_null': False}],
  39. [None, {'query': 'SELECT blah8', 'depth': 0, 'as_list': False,
  40. 'with_lists': [1], 'ignore_null': False}],
  41. [None, {'query': 'SELECT blah9', 'depth': 0, 'as_list': False,
  42. 'with_lists': [1, 2], 'ignore_null': False}]
  43. ], qbuffer)
  44. def test_002_extract_queries_kwarg(self):
  45. return_data = sqlite3.SQLite3ExtPillar()
  46. args, kwargs = [], {
  47. '1': 'SELECT blah',
  48. '2': 'SELECT blah2',
  49. '3': ('SELECT blah3',),
  50. '4': ('SELECT blah4', 2),
  51. '5': {'query': 'SELECT blah5'},
  52. '6': {'query': 'SELECT blah6', 'depth': 2},
  53. '7': {'query': 'SELECT blah7', 'as_list': True},
  54. }
  55. qbuffer = return_data.extract_queries(args, kwargs)
  56. self.assertEqual([
  57. ['1', {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  58. 'with_lists': None, 'ignore_null': False}],
  59. ['2', {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  60. 'with_lists': None, 'ignore_null': False}],
  61. ['3', {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  62. 'with_lists': None, 'ignore_null': False}],
  63. ['4', {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  64. 'with_lists': None, 'ignore_null': False}],
  65. ['5', {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  66. 'with_lists': None, 'ignore_null': False}],
  67. ['6', {'query': 'SELECT blah6', 'depth': 2, 'as_list': False,
  68. 'with_lists': None, 'ignore_null': False}],
  69. ['7', {'query': 'SELECT blah7', 'depth': 0, 'as_list': True,
  70. 'with_lists': None, 'ignore_null': False}]
  71. ], qbuffer)
  72. def test_003_extract_queries_mixed(self):
  73. return_data = sqlite3.SQLite3ExtPillar()
  74. args, kwargs = [
  75. 'SELECT blah1',
  76. ('SELECT blah2', 2),
  77. {'query': 'SELECT blah3', 'as_list': True},
  78. ], {
  79. '1': 'SELECT blah1',
  80. '2': ('SELECT blah2', 2),
  81. '3': {'query': 'SELECT blah3', 'as_list': True},
  82. }
  83. qbuffer = return_data.extract_queries(args, kwargs)
  84. self.assertEqual([
  85. [None, {'query': 'SELECT blah1', 'depth': 0, 'as_list': False,
  86. 'with_lists': None, 'ignore_null': False}],
  87. [None, {'query': 'SELECT blah2', 'depth': 2, 'as_list': False,
  88. 'with_lists': None, 'ignore_null': False}],
  89. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': True,
  90. 'with_lists': None, 'ignore_null': False}],
  91. ['1', {'query': 'SELECT blah1', 'depth': 0, 'as_list': False,
  92. 'with_lists': None, 'ignore_null': False}],
  93. ['2', {'query': 'SELECT blah2', 'depth': 2, 'as_list': False,
  94. 'with_lists': None, 'ignore_null': False}],
  95. ['3', {'query': 'SELECT blah3', 'depth': 0, 'as_list': True,
  96. 'with_lists': None, 'ignore_null': False}]
  97. ], qbuffer)
  98. def test_004_extract_queries_bogus_list(self):
  99. # This test is specifically checking that empty queries are dropped
  100. return_data = sqlite3.SQLite3ExtPillar()
  101. args, kwargs = [
  102. 'SELECT blah',
  103. '',
  104. 'SELECT blah2',
  105. ('SELECT blah3',),
  106. ('',),
  107. ('SELECT blah4', 2),
  108. tuple(),
  109. ('SELECT blah5',),
  110. {'query': 'SELECT blah6'},
  111. {'query': ''},
  112. {'query': 'SELECT blah7', 'depth': 2},
  113. {'not_a_query': 'in sight!'},
  114. {'query': 'SELECT blah8', 'as_list': True},
  115. ], {}
  116. qbuffer = return_data.extract_queries(args, kwargs)
  117. self.assertEqual([
  118. [None, {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  119. 'with_lists': None, 'ignore_null': False}],
  120. [None, {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  121. 'with_lists': None, 'ignore_null': False}],
  122. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  123. 'with_lists': None, 'ignore_null': False}],
  124. [None, {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  125. 'with_lists': None, 'ignore_null': False}],
  126. [None, {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  127. 'with_lists': None, 'ignore_null': False}],
  128. [None, {'query': 'SELECT blah6', 'depth': 0, 'as_list': False,
  129. 'with_lists': None, 'ignore_null': False}],
  130. [None, {'query': 'SELECT blah7', 'depth': 2, 'as_list': False,
  131. 'with_lists': None, 'ignore_null': False}],
  132. [None, {'query': 'SELECT blah8', 'depth': 0, 'as_list': True,
  133. 'with_lists': None, 'ignore_null': False}]
  134. ], qbuffer)
  135. def test_005_extract_queries_bogus_kwargs(self):
  136. # this test is cut down as most of the path matches test_*_bogus_list
  137. return_data = sqlite3.SQLite3ExtPillar()
  138. args, kwargs = [], {
  139. '1': 'SELECT blah',
  140. '2': '',
  141. '3': 'SELECT blah2'
  142. }
  143. qbuffer = return_data.extract_queries(args, kwargs)
  144. self.assertEqual([
  145. ['1', {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  146. 'with_lists': None, 'ignore_null': False}],
  147. ['3', {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  148. 'with_lists': None, 'ignore_null': False}]
  149. ], qbuffer)
  150. def test_011_enter_root(self):
  151. return_data = sqlite3.SQLite3ExtPillar()
  152. return_data.enter_root("test")
  153. self.assertEqual(return_data.result["test"], return_data.focus)
  154. return_data.enter_root(None)
  155. self.assertEqual(return_data.result, return_data.focus)
  156. def test_021_process_fields(self):
  157. return_data = sqlite3.SQLite3ExtPillar()
  158. return_data.process_fields(['a', 'b'], 0)
  159. self.assertEqual(return_data.num_fields, 2)
  160. self.assertEqual(return_data.depth, 1)
  161. return_data.process_fields(['a', 'b'], 2)
  162. self.assertEqual(return_data.num_fields, 2)
  163. self.assertEqual(return_data.depth, 1)
  164. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  165. self.assertEqual(return_data.num_fields, 4)
  166. self.assertEqual(return_data.depth, 3)
  167. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  168. self.assertEqual(return_data.num_fields, 4)
  169. self.assertEqual(return_data.depth, 1)
  170. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  171. self.assertEqual(return_data.num_fields, 4)
  172. self.assertEqual(return_data.depth, 2)
  173. return_data.process_fields(['a', 'b', 'c', 'd'], 3)
  174. self.assertEqual(return_data.num_fields, 4)
  175. self.assertEqual(return_data.depth, 3)
  176. return_data.process_fields(['a', 'b', 'c', 'd'], 4)
  177. self.assertEqual(return_data.num_fields, 4)
  178. self.assertEqual(return_data.depth, 3)
  179. def test_111_process_results_legacy(self):
  180. return_data = sqlite3.SQLite3ExtPillar()
  181. return_data.process_fields(['a', 'b'], 0)
  182. return_data.with_lists = []
  183. return_data.process_results([[1, 2]])
  184. self.assertEqual(
  185. {1: 2},
  186. return_data.result
  187. )
  188. def test_112_process_results_legacy_multiple(self):
  189. return_data = sqlite3.SQLite3ExtPillar()
  190. return_data.process_fields(['a', 'b'], 0)
  191. return_data.with_lists = []
  192. return_data.process_results([[1, 2], [3, 4], [5, 6]])
  193. self.assertEqual(
  194. {1: 2, 3: 4, 5: 6},
  195. return_data.result
  196. )
  197. def test_121_process_results_depth_0(self):
  198. return_data = sqlite3.SQLite3ExtPillar()
  199. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  200. return_data.with_lists = []
  201. return_data.enter_root(None)
  202. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  203. self.assertEqual(
  204. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  205. return_data.result
  206. )
  207. def test_122_process_results_depth_1(self):
  208. return_data = sqlite3.SQLite3ExtPillar()
  209. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  210. return_data.with_lists = []
  211. return_data.enter_root(None)
  212. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  213. self.assertEqual(
  214. {1: {'b': 2, 'c': 3, 'd': 4}, 5: {'b': 6, 'c': 7, 'd': 8}},
  215. return_data.result
  216. )
  217. def test_123_process_results_depth_2(self):
  218. return_data = sqlite3.SQLite3ExtPillar()
  219. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  220. return_data.with_lists = []
  221. return_data.enter_root(None)
  222. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  223. self.assertEqual(
  224. {1: {2: {'c': 3, 'd': 4}}, 5: {6: {'c': 7, 'd': 8}}},
  225. return_data.result
  226. )
  227. def test_124_process_results_depth_3(self):
  228. return_data = sqlite3.SQLite3ExtPillar()
  229. return_data.process_fields(['a', 'b', 'c', 'd'], 3)
  230. return_data.with_lists = []
  231. return_data.enter_root(None)
  232. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  233. self.assertEqual(
  234. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  235. return_data.result
  236. )
  237. def test_125_process_results_depth_4(self):
  238. return_data = sqlite3.SQLite3ExtPillar()
  239. return_data.process_fields(['a', 'b', 'c', 'd'], 4)
  240. return_data.with_lists = []
  241. return_data.enter_root(None)
  242. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  243. self.assertEqual(
  244. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  245. return_data.result
  246. )
  247. def test_131_process_results_overwrite_legacy_multiple(self):
  248. return_data = sqlite3.SQLite3ExtPillar()
  249. return_data.process_fields(['a', 'b'], 0)
  250. return_data.with_lists = []
  251. return_data.process_results([[1, 2], [3, 4], [1, 6]])
  252. self.assertEqual(
  253. {1: 6, 3: 4},
  254. return_data.result
  255. )
  256. def test_132_process_results_merge_depth_0(self):
  257. return_data = sqlite3.SQLite3ExtPillar()
  258. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  259. return_data.with_lists = []
  260. return_data.enter_root(None)
  261. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  262. self.assertEqual(
  263. {1: {2: {3: 4}, 6: {7: 8}}},
  264. return_data.result
  265. )
  266. def test_133_process_results_overwrite_depth_0(self):
  267. return_data = sqlite3.SQLite3ExtPillar()
  268. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  269. return_data.with_lists = []
  270. return_data.enter_root(None)
  271. return_data.process_results([[1, 2, 3, 4], [1, 2, 3, 8]])
  272. self.assertEqual(
  273. {1: {2: {3: 8}}},
  274. return_data.result
  275. )
  276. def test_134_process_results_deepmerge_depth_0(self):
  277. return_data = sqlite3.SQLite3ExtPillar()
  278. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  279. return_data.with_lists = []
  280. return_data.enter_root(None)
  281. return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])
  282. self.assertEqual(
  283. {1: {2: {3: 4, 7: 8}}},
  284. return_data.result
  285. )
  286. def test_135_process_results_overwrite_depth_1(self):
  287. return_data = sqlite3.SQLite3ExtPillar()
  288. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  289. return_data.with_lists = []
  290. return_data.enter_root(None)
  291. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  292. self.assertEqual(
  293. {1: {'b': 6, 'c': 7, 'd': 8}},
  294. return_data.result
  295. )
  296. def test_136_process_results_merge_depth_2(self):
  297. return_data = sqlite3.SQLite3ExtPillar()
  298. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  299. return_data.with_lists = []
  300. return_data.enter_root(None)
  301. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  302. self.assertEqual(
  303. {1: {2: {'c': 3, 'd': 4}, 6: {'c': 7, 'd': 8}}},
  304. return_data.result
  305. )
  306. def test_137_process_results_overwrite_depth_2(self):
  307. return_data = sqlite3.SQLite3ExtPillar()
  308. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  309. return_data.with_lists = []
  310. return_data.enter_root(None)
  311. return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])
  312. self.assertEqual(
  313. {1: {2: {'c': 7, 'd': 8}}},
  314. return_data.result
  315. )
  316. def test_201_process_results_complexity_multiresults(self):
  317. return_data = sqlite3.SQLite3ExtPillar()
  318. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  319. return_data.with_lists = []
  320. return_data.enter_root(None)
  321. return_data.process_results([[1, 2, 3, 4]])
  322. return_data.process_results([[1, 2, 7, 8]])
  323. self.assertEqual(
  324. {1: {2: {'c': 7, 'd': 8}}},
  325. return_data.result
  326. )
  327. def test_202_process_results_complexity_as_list(self):
  328. return_data = sqlite3.SQLite3ExtPillar()
  329. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  330. return_data.with_lists = []
  331. return_data.enter_root(None)
  332. return_data.as_list = True
  333. return_data.process_results([[1, 2, 3, 4]])
  334. return_data.process_results([[1, 2, 7, 8]])
  335. self.assertEqual(
  336. {1: {2: {'c': [3, 7], 'd': [4, 8]}}},
  337. return_data.result
  338. )
  339. def test_203_process_results_complexity_as_list_deeper(self):
  340. return_data = sqlite3.SQLite3ExtPillar()
  341. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  342. return_data.with_lists = []
  343. return_data.enter_root(None)
  344. return_data.as_list = True
  345. return_data.process_results([[1, 2, 3, 4]])
  346. return_data.process_results([[1, 2, 3, 8]])
  347. self.assertEqual(
  348. {1: {2: {3: [4, 8]}}},
  349. return_data.result
  350. )
  351. def test_204_process_results_complexity_as_list_mismatch_depth(self):
  352. return_data = sqlite3.SQLite3ExtPillar()
  353. return_data.as_list = True
  354. return_data.with_lists = []
  355. return_data.enter_root(None)
  356. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  357. return_data.process_results([[1, 2, 3, 4]])
  358. return_data.process_results([[1, 2, 3, 5]])
  359. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  360. return_data.process_results([[1, 2, 3, 6, 7]])
  361. self.assertEqual(
  362. {1: {2: {3: [4, 5, {6: 7}]}}},
  363. return_data.result
  364. )
  365. def test_205_process_results_complexity_as_list_mismatch_depth_reversed(self):
  366. return_data = sqlite3.SQLite3ExtPillar()
  367. return_data.as_list = True
  368. return_data.with_lists = []
  369. return_data.enter_root(None)
  370. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  371. return_data.process_results([[1, 2, 3, 6, 7]])
  372. return_data.process_results([[1, 2, 3, 8, 9]])
  373. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  374. return_data.process_results([[1, 2, 3, 4]])
  375. return_data.process_results([[1, 2, 3, 5]])
  376. self.assertEqual(
  377. {1: {2: {3: [{6: 7, 8: 9}, 4, 5]}}},
  378. return_data.result
  379. )
  380. def test_206_process_results_complexity_as_list_mismatch_depth_weird_order(self):
  381. return_data = sqlite3.SQLite3ExtPillar()
  382. return_data.as_list = True
  383. return_data.with_lists = []
  384. return_data.enter_root(None)
  385. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  386. return_data.process_results([[1, 2, 3, 6, 7]])
  387. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  388. return_data.process_results([[1, 2, 3, 4]])
  389. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  390. return_data.process_results([[1, 2, 3, 8, 9]])
  391. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  392. return_data.process_results([[1, 2, 3, 5]])
  393. self.assertEqual(
  394. {1: {2: {3: [{6: 7, }, 4, {8: 9}, 5]}}},
  395. return_data.result
  396. )
  397. def test_207_process_results_complexity_collision_mismatch_depth(self):
  398. return_data = sqlite3.SQLite3ExtPillar()
  399. return_data.as_list = False
  400. return_data.with_lists = []
  401. return_data.enter_root(None)
  402. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  403. return_data.process_results([[1, 2, 3, 4]])
  404. return_data.process_results([[1, 2, 3, 5]])
  405. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  406. return_data.process_results([[1, 2, 3, 6, 7]])
  407. self.assertEqual(
  408. {1: {2: {3: {6: 7}}}},
  409. return_data.result
  410. )
  411. def test_208_process_results_complexity_collision_mismatch_depth_reversed(self):
  412. return_data = sqlite3.SQLite3ExtPillar()
  413. return_data.as_list = False
  414. return_data.with_lists = []
  415. return_data.enter_root(None)
  416. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  417. return_data.process_results([[1, 2, 3, 6, 7]])
  418. return_data.process_results([[1, 2, 3, 8, 9]])
  419. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  420. return_data.process_results([[1, 2, 3, 4]])
  421. return_data.process_results([[1, 2, 3, 5]])
  422. self.assertEqual(
  423. {1: {2: {3: 5}}},
  424. return_data.result
  425. )
  426. def test_209_process_results_complexity_collision_mismatch_depth_weird_order(self):
  427. return_data = sqlite3.SQLite3ExtPillar()
  428. return_data.as_list = False
  429. return_data.with_lists = []
  430. return_data.enter_root(None)
  431. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  432. return_data.process_results([[1, 2, 3, 6, 7]])
  433. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  434. return_data.process_results([[1, 2, 3, 4]])
  435. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  436. return_data.process_results([[1, 2, 3, 8, 9]])
  437. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  438. return_data.process_results([[1, 2, 3, 5]])
  439. self.assertEqual(
  440. {1: {2: {3: 5}}},
  441. return_data.result
  442. )
  443. def test_20A_process_results_complexity_as_list_vary(self):
  444. return_data = sqlite3.SQLite3ExtPillar()
  445. return_data.as_list = True
  446. return_data.with_lists = []
  447. return_data.enter_root(None)
  448. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  449. return_data.process_results([[1, 2, 3, 6, 7]])
  450. return_data.process_results([[1, 2, 3, 8, 9]])
  451. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  452. return_data.process_results([[1, 2, 3, 4]])
  453. return_data.as_list = False
  454. return_data.process_results([[1, 2, 3, 5]])
  455. self.assertEqual(
  456. {1: {2: {3: 5}}},
  457. return_data.result
  458. )
  459. def test_207_process_results_complexity_roots_collision(self):
  460. return_data = sqlite3.SQLite3ExtPillar()
  461. return_data.as_list = False
  462. return_data.with_lists = []
  463. return_data.enter_root(None)
  464. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  465. return_data.process_results([[1, 2, 3, 4]])
  466. return_data.enter_root(1)
  467. return_data.process_results([[5, 6, 7, 8]])
  468. self.assertEqual(
  469. {1: {5: {6: {7: 8}}}},
  470. return_data.result
  471. )
  472. def test_301_process_results_with_lists(self):
  473. return_data = sqlite3.SQLite3ExtPillar()
  474. return_data.as_list = False
  475. return_data.with_lists = [1, 3]
  476. return_data.enter_root(None)
  477. return_data.process_fields(['a', 'b', 'c', 'd', 'e', 'v'], 0)
  478. return_data.process_results([['a', 'b', 'c', 'd', 'e', 1],
  479. ['a', 'b', 'c', 'f', 'g', 2],
  480. ['a', 'z', 'h', 'y', 'j', 3],
  481. ['a', 'z', 'h', 'y', 'k', 4]])
  482. self.assertEqual(sorted(
  483. {'a': [
  484. {'c': [
  485. {'e': 1},
  486. {'g': 2}
  487. ]
  488. },
  489. {'h': [
  490. {'j': 3, 'k': 4}
  491. ]
  492. }
  493. ]}),
  494. sorted(return_data.result)
  495. )
  496. def test_302_process_results_with_lists_consecutive(self):
  497. return_data = sqlite3.SQLite3ExtPillar()
  498. return_data.as_list = False
  499. return_data.with_lists = [1, 2, 3]
  500. return_data.enter_root(None)
  501. return_data.process_fields(['a', 'b', 'c', 'd', 'e', 'v'], 0)
  502. return_data.process_results([['a', 'b', 'c', 'd', 'e', 1],
  503. ['a', 'b', 'c', 'f', 'g', 2],
  504. ['a', 'z', 'h', 'y', 'j', 3],
  505. ['a', 'z', 'h', 'y', 'k', 4]])
  506. self.assertEqual(sorted(
  507. {'a': [
  508. [[
  509. {'e': 1},
  510. {'g': 2}
  511. ]
  512. ],
  513. [[
  514. {'j': 3, 'k': 4}
  515. ]
  516. ]
  517. ]}),
  518. sorted(return_data.result)
  519. )