1#
2# Copyright 2015 ClusterHQ
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Tests for _nvlist module.
19The tests convert from a `dict` to C ``nvlist_t`` and back to a `dict`
20and verify that no information is lost and value types are correct.
21The tests also check that various error conditions like unsupported
22value types or out of bounds values are detected.
23"""
24from __future__ import absolute_import, division, print_function
25
26import unittest
27
28from .._nvlist import nvlist_in, nvlist_out, _lib
29from ..ctypes import (
30    uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t,
31    uint64_t, int64_t, boolean_t, uchar_t
32)
33
34
35class TestNVList(unittest.TestCase):
36
37    def _dict_to_nvlist_to_dict(self, props):
38        res = {}
39        nv_in = nvlist_in(props)
40        with nvlist_out(res) as nv_out:
41            _lib.nvlist_dup(nv_in, nv_out, 0)
42        return res
43
44    def _assertIntDictsEqual(self, dict1, dict2):
45        self.assertEqual(
46            len(dict1), len(dict1),
47            b"resulting dictionary is of different size")
48        for key in dict1.keys():
49            self.assertEqual(int(dict1[key]), int(dict2[key]))
50
51    def _assertIntArrayDictsEqual(self, dict1, dict2):
52        self.assertEqual(
53            len(dict1), len(dict1),
54            b"resulting dictionary is of different size")
55        for key in dict1.keys():
56            val1 = dict1[key]
57            val2 = dict2[key]
58            self.assertEqual(
59                len(val1), len(val2), b"array values of different sizes")
60            for x, y in zip(val1, val2):
61                self.assertEqual(int(x), int(y))
62
63    def test_empty(self):
64        res = self._dict_to_nvlist_to_dict({})
65        self.assertEqual(len(res), 0, b"expected empty dict")
66
67    def test_invalid_key_type(self):
68        with self.assertRaises(TypeError):
69            self._dict_to_nvlist_to_dict({1: None})
70
71    def test_invalid_val_type__tuple(self):
72        with self.assertRaises(TypeError):
73            self._dict_to_nvlist_to_dict({b"key": (1, 2)})
74
75    def test_invalid_val_type__set(self):
76        with self.assertRaises(TypeError):
77            self._dict_to_nvlist_to_dict({b"key": set(1, 2)})
78
79    def test_invalid_array_val_type(self):
80        with self.assertRaises(TypeError):
81            self._dict_to_nvlist_to_dict({b"key": [(1, 2), (3, 4)]})
82
83    def test_invalid_array_of_arrays_val_type(self):
84        with self.assertRaises(TypeError):
85            self._dict_to_nvlist_to_dict({b"key": [[1, 2], [3, 4]]})
86
87    def test_string_value(self):
88        props = {b"key": b"value"}
89        res = self._dict_to_nvlist_to_dict(props)
90        self.assertEqual(props, res)
91
92    def test_implicit_boolean_value(self):
93        props = {b"key": None}
94        res = self._dict_to_nvlist_to_dict(props)
95        self.assertEqual(props, res)
96
97    def test_boolean_values(self):
98        props = {b"key1": True, b"key2": False}
99        res = self._dict_to_nvlist_to_dict(props)
100        self.assertEqual(props, res)
101
102    def test_explicit_boolean_true_value(self):
103        props = {b"key": boolean_t(1)}
104        res = self._dict_to_nvlist_to_dict(props)
105        self._assertIntDictsEqual(props, res)
106
107    def test_explicit_boolean_false_value(self):
108        props = {b"key": boolean_t(0)}
109        res = self._dict_to_nvlist_to_dict(props)
110        self._assertIntDictsEqual(props, res)
111
112    def test_explicit_boolean_invalid_value(self):
113        with self.assertRaises(OverflowError):
114            props = {b"key": boolean_t(2)}
115            self._dict_to_nvlist_to_dict(props)
116
117    def test_explicit_boolean_another_invalid_value(self):
118        with self.assertRaises(OverflowError):
119            props = {b"key": boolean_t(-1)}
120            self._dict_to_nvlist_to_dict(props)
121
122    def test_uint64_value(self):
123        props = {b"key": 1}
124        res = self._dict_to_nvlist_to_dict(props)
125        self.assertEqual(props, res)
126
127    def test_uint64_max_value(self):
128        props = {b"key": 2 ** 64 - 1}
129        res = self._dict_to_nvlist_to_dict(props)
130        self.assertEqual(props, res)
131
132    def test_uint64_too_large_value(self):
133        props = {b"key": 2 ** 64}
134        with self.assertRaises(OverflowError):
135            self._dict_to_nvlist_to_dict(props)
136
137    def test_uint64_negative_value(self):
138        props = {b"key": -1}
139        with self.assertRaises(OverflowError):
140            self._dict_to_nvlist_to_dict(props)
141
142    def test_explicit_uint64_value(self):
143        props = {b"key": uint64_t(1)}
144        res = self._dict_to_nvlist_to_dict(props)
145        self._assertIntDictsEqual(props, res)
146
147    def test_explicit_uint64_max_value(self):
148        props = {b"key": uint64_t(2 ** 64 - 1)}
149        res = self._dict_to_nvlist_to_dict(props)
150        self._assertIntDictsEqual(props, res)
151
152    def test_explicit_uint64_too_large_value(self):
153        with self.assertRaises(OverflowError):
154            props = {b"key": uint64_t(2 ** 64)}
155            self._dict_to_nvlist_to_dict(props)
156
157    def test_explicit_uint64_negative_value(self):
158        with self.assertRaises(OverflowError):
159            props = {b"key": uint64_t(-1)}
160            self._dict_to_nvlist_to_dict(props)
161
162    def test_explicit_uint32_value(self):
163        props = {b"key": uint32_t(1)}
164        res = self._dict_to_nvlist_to_dict(props)
165        self._assertIntDictsEqual(props, res)
166
167    def test_explicit_uint32_max_value(self):
168        props = {b"key": uint32_t(2 ** 32 - 1)}
169        res = self._dict_to_nvlist_to_dict(props)
170        self._assertIntDictsEqual(props, res)
171
172    def test_explicit_uint32_too_large_value(self):
173        with self.assertRaises(OverflowError):
174            props = {b"key": uint32_t(2 ** 32)}
175            self._dict_to_nvlist_to_dict(props)
176
177    def test_explicit_uint32_negative_value(self):
178        with self.assertRaises(OverflowError):
179            props = {b"key": uint32_t(-1)}
180            self._dict_to_nvlist_to_dict(props)
181
182    def test_explicit_uint16_value(self):
183        props = {b"key": uint16_t(1)}
184        res = self._dict_to_nvlist_to_dict(props)
185        self._assertIntDictsEqual(props, res)
186
187    def test_explicit_uint16_max_value(self):
188        props = {b"key": uint16_t(2 ** 16 - 1)}
189        res = self._dict_to_nvlist_to_dict(props)
190        self._assertIntDictsEqual(props, res)
191
192    def test_explicit_uint16_too_large_value(self):
193        with self.assertRaises(OverflowError):
194            props = {b"key": uint16_t(2 ** 16)}
195            self._dict_to_nvlist_to_dict(props)
196
197    def test_explicit_uint16_negative_value(self):
198        with self.assertRaises(OverflowError):
199            props = {b"key": uint16_t(-1)}
200            self._dict_to_nvlist_to_dict(props)
201
202    def test_explicit_uint8_value(self):
203        props = {b"key": uint8_t(1)}
204        res = self._dict_to_nvlist_to_dict(props)
205        self._assertIntDictsEqual(props, res)
206
207    def test_explicit_uint8_max_value(self):
208        props = {b"key": uint8_t(2 ** 8 - 1)}
209        res = self._dict_to_nvlist_to_dict(props)
210        self._assertIntDictsEqual(props, res)
211
212    def test_explicit_uint8_too_large_value(self):
213        with self.assertRaises(OverflowError):
214            props = {b"key": uint8_t(2 ** 8)}
215            self._dict_to_nvlist_to_dict(props)
216
217    def test_explicit_uint8_negative_value(self):
218        with self.assertRaises(OverflowError):
219            props = {b"key": uint8_t(-1)}
220            self._dict_to_nvlist_to_dict(props)
221
222    def test_explicit_byte_value(self):
223        props = {b"key": uchar_t(1)}
224        res = self._dict_to_nvlist_to_dict(props)
225        self._assertIntDictsEqual(props, res)
226
227    def test_explicit_byte_max_value(self):
228        props = {b"key": uchar_t(2 ** 8 - 1)}
229        res = self._dict_to_nvlist_to_dict(props)
230        self._assertIntDictsEqual(props, res)
231
232    def test_explicit_byte_too_large_value(self):
233        with self.assertRaises(OverflowError):
234            props = {b"key": uchar_t(2 ** 8)}
235            self._dict_to_nvlist_to_dict(props)
236
237    def test_explicit_byte_negative_value(self):
238        with self.assertRaises(OverflowError):
239            props = {b"key": uchar_t(-1)}
240            self._dict_to_nvlist_to_dict(props)
241
242    def test_explicit_int64_value(self):
243        props = {b"key": int64_t(1)}
244        res = self._dict_to_nvlist_to_dict(props)
245        self._assertIntDictsEqual(props, res)
246
247    def test_explicit_int64_max_value(self):
248        props = {b"key": int64_t(2 ** 63 - 1)}
249        res = self._dict_to_nvlist_to_dict(props)
250        self._assertIntDictsEqual(props, res)
251
252    def test_explicit_int64_min_value(self):
253        props = {b"key": int64_t(-(2 ** 63))}
254        res = self._dict_to_nvlist_to_dict(props)
255        self._assertIntDictsEqual(props, res)
256
257    def test_explicit_int64_too_large_value(self):
258        with self.assertRaises(OverflowError):
259            props = {b"key": int64_t(2 ** 63)}
260            self._dict_to_nvlist_to_dict(props)
261
262    def test_explicit_int64_too_small_value(self):
263        with self.assertRaises(OverflowError):
264            props = {b"key": int64_t(-(2 ** 63) - 1)}
265            self._dict_to_nvlist_to_dict(props)
266
267    def test_explicit_int32_value(self):
268        props = {b"key": int32_t(1)}
269        res = self._dict_to_nvlist_to_dict(props)
270        self._assertIntDictsEqual(props, res)
271
272    def test_explicit_int32_max_value(self):
273        props = {b"key": int32_t(2 ** 31 - 1)}
274        res = self._dict_to_nvlist_to_dict(props)
275        self._assertIntDictsEqual(props, res)
276
277    def test_explicit_int32_min_value(self):
278        props = {b"key": int32_t(-(2 ** 31))}
279        res = self._dict_to_nvlist_to_dict(props)
280        self._assertIntDictsEqual(props, res)
281
282    def test_explicit_int32_too_large_value(self):
283        with self.assertRaises(OverflowError):
284            props = {b"key": int32_t(2 ** 31)}
285            self._dict_to_nvlist_to_dict(props)
286
287    def test_explicit_int32_too_small_value(self):
288        with self.assertRaises(OverflowError):
289            props = {b"key": int32_t(-(2 ** 31) - 1)}
290            self._dict_to_nvlist_to_dict(props)
291
292    def test_explicit_int16_value(self):
293        props = {b"key": int16_t(1)}
294        res = self._dict_to_nvlist_to_dict(props)
295        self._assertIntDictsEqual(props, res)
296
297    def test_explicit_int16_max_value(self):
298        props = {b"key": int16_t(2 ** 15 - 1)}
299        res = self._dict_to_nvlist_to_dict(props)
300        self._assertIntDictsEqual(props, res)
301
302    def test_explicit_int16_min_value(self):
303        props = {b"key": int16_t(-(2 ** 15))}
304        res = self._dict_to_nvlist_to_dict(props)
305        self._assertIntDictsEqual(props, res)
306
307    def test_explicit_int16_too_large_value(self):
308        with self.assertRaises(OverflowError):
309            props = {b"key": int16_t(2 ** 15)}
310            self._dict_to_nvlist_to_dict(props)
311
312    def test_explicit_int16_too_small_value(self):
313        with self.assertRaises(OverflowError):
314            props = {b"key": int16_t(-(2 ** 15) - 1)}
315            self._dict_to_nvlist_to_dict(props)
316
317    def test_explicit_int8_value(self):
318        props = {b"key": int8_t(1)}
319        res = self._dict_to_nvlist_to_dict(props)
320        self._assertIntDictsEqual(props, res)
321
322    def test_explicit_int8_max_value(self):
323        props = {b"key": int8_t(2 ** 7 - 1)}
324        res = self._dict_to_nvlist_to_dict(props)
325        self._assertIntDictsEqual(props, res)
326
327    def test_explicit_int8_min_value(self):
328        props = {b"key": int8_t(-(2 ** 7))}
329        res = self._dict_to_nvlist_to_dict(props)
330        self._assertIntDictsEqual(props, res)
331
332    def test_explicit_int8_too_large_value(self):
333        with self.assertRaises(OverflowError):
334            props = {b"key": int8_t(2 ** 7)}
335            self._dict_to_nvlist_to_dict(props)
336
337    def test_explicit_int8_too_small_value(self):
338        with self.assertRaises(OverflowError):
339            props = {b"key": int8_t(-(2 ** 7) - 1)}
340            self._dict_to_nvlist_to_dict(props)
341
342    def test_nested_dict(self):
343        props = {b"key": {}}
344        res = self._dict_to_nvlist_to_dict(props)
345        self.assertEqual(props, res)
346
347    def test_nested_nested_dict(self):
348        props = {b"key": {b"key": {}}}
349        res = self._dict_to_nvlist_to_dict(props)
350        self.assertEqual(props, res)
351
352    def test_mismatching_values_array(self):
353        props = {b"key": [1, b"string"]}
354        with self.assertRaises(TypeError):
355            self._dict_to_nvlist_to_dict(props)
356
357    def test_mismatching_values_array2(self):
358        props = {b"key": [True, 10]}
359        with self.assertRaises(TypeError):
360            self._dict_to_nvlist_to_dict(props)
361
362    def test_mismatching_values_array3(self):
363        props = {b"key": [1, False]}
364        with self.assertRaises(TypeError):
365            self._dict_to_nvlist_to_dict(props)
366
367    def test_string_array(self):
368        props = {b"key": [b"value", b"value2"]}
369        res = self._dict_to_nvlist_to_dict(props)
370        self.assertEqual(props, res)
371
372    def test_boolean_array(self):
373        props = {b"key": [True, False]}
374        res = self._dict_to_nvlist_to_dict(props)
375        self.assertEqual(props, res)
376
377    def test_explicit_boolean_array(self):
378        props = {b"key": [boolean_t(False), boolean_t(True)]}
379        res = self._dict_to_nvlist_to_dict(props)
380        self._assertIntArrayDictsEqual(props, res)
381
382    def test_uint64_array(self):
383        props = {b"key": [0, 1, 2 ** 64 - 1]}
384        res = self._dict_to_nvlist_to_dict(props)
385        self.assertEqual(props, res)
386
387    def test_uint64_array_too_large_value(self):
388        props = {b"key": [0, 2 ** 64]}
389        with self.assertRaises(OverflowError):
390            self._dict_to_nvlist_to_dict(props)
391
392    def test_uint64_array_negative_value(self):
393        props = {b"key": [0, -1]}
394        with self.assertRaises(OverflowError):
395            self._dict_to_nvlist_to_dict(props)
396
397    def test_mixed_explict_int_array(self):
398        with self.assertRaises(TypeError):
399            props = {b"key": [uint64_t(0), uint32_t(0)]}
400            self._dict_to_nvlist_to_dict(props)
401
402    def test_explict_uint64_array(self):
403        props = {b"key": [uint64_t(0), uint64_t(1), uint64_t(2 ** 64 - 1)]}
404        res = self._dict_to_nvlist_to_dict(props)
405        self._assertIntArrayDictsEqual(props, res)
406
407    def test_explict_uint64_array_too_large_value(self):
408        with self.assertRaises(OverflowError):
409            props = {b"key": [uint64_t(0), uint64_t(2 ** 64)]}
410            self._dict_to_nvlist_to_dict(props)
411
412    def test_explict_uint64_array_negative_value(self):
413        with self.assertRaises(OverflowError):
414            props = {b"key": [uint64_t(0), uint64_t(-1)]}
415            self._dict_to_nvlist_to_dict(props)
416
417    def test_explict_uint32_array(self):
418        props = {b"key": [uint32_t(0), uint32_t(1), uint32_t(2 ** 32 - 1)]}
419        res = self._dict_to_nvlist_to_dict(props)
420        self._assertIntArrayDictsEqual(props, res)
421
422    def test_explict_uint32_array_too_large_value(self):
423        with self.assertRaises(OverflowError):
424            props = {b"key": [uint32_t(0), uint32_t(2 ** 32)]}
425            self._dict_to_nvlist_to_dict(props)
426
427    def test_explict_uint32_array_negative_value(self):
428        with self.assertRaises(OverflowError):
429            props = {b"key": [uint32_t(0), uint32_t(-1)]}
430            self._dict_to_nvlist_to_dict(props)
431
432    def test_explict_uint16_array(self):
433        props = {b"key": [uint16_t(0), uint16_t(1), uint16_t(2 ** 16 - 1)]}
434        res = self._dict_to_nvlist_to_dict(props)
435        self._assertIntArrayDictsEqual(props, res)
436
437    def test_explict_uint16_array_too_large_value(self):
438        with self.assertRaises(OverflowError):
439            props = {b"key": [uint16_t(0), uint16_t(2 ** 16)]}
440            self._dict_to_nvlist_to_dict(props)
441
442    def test_explict_uint16_array_negative_value(self):
443        with self.assertRaises(OverflowError):
444            props = {b"key": [uint16_t(0), uint16_t(-1)]}
445            self._dict_to_nvlist_to_dict(props)
446
447    def test_explict_uint8_array(self):
448        props = {b"key": [uint8_t(0), uint8_t(1), uint8_t(2 ** 8 - 1)]}
449        res = self._dict_to_nvlist_to_dict(props)
450        self._assertIntArrayDictsEqual(props, res)
451
452    def test_explict_uint8_array_too_large_value(self):
453        with self.assertRaises(OverflowError):
454            props = {b"key": [uint8_t(0), uint8_t(2 ** 8)]}
455            self._dict_to_nvlist_to_dict(props)
456
457    def test_explict_uint8_array_negative_value(self):
458        with self.assertRaises(OverflowError):
459            props = {b"key": [uint8_t(0), uint8_t(-1)]}
460            self._dict_to_nvlist_to_dict(props)
461
462    def test_explict_byte_array(self):
463        props = {b"key": [uchar_t(0), uchar_t(1), uchar_t(2 ** 8 - 1)]}
464        res = self._dict_to_nvlist_to_dict(props)
465        self._assertIntArrayDictsEqual(props, res)
466
467    def test_explict_byte_array_too_large_value(self):
468        with self.assertRaises(OverflowError):
469            props = {b"key": [uchar_t(0), uchar_t(2 ** 8)]}
470            self._dict_to_nvlist_to_dict(props)
471
472    def test_explict_byte_array_negative_value(self):
473        with self.assertRaises(OverflowError):
474            props = {b"key": [uchar_t(0), uchar_t(-1)]}
475            self._dict_to_nvlist_to_dict(props)
476
477    def test_explict_int64_array(self):
478        props = {b"key": [
479            int64_t(0), int64_t(1), int64_t(2 ** 63 - 1), int64_t(-(2 ** 63))]}
480        res = self._dict_to_nvlist_to_dict(props)
481        self._assertIntArrayDictsEqual(props, res)
482
483    def test_explict_int64_array_too_large_value(self):
484        with self.assertRaises(OverflowError):
485            props = {b"key": [int64_t(0), int64_t(2 ** 63)]}
486            self._dict_to_nvlist_to_dict(props)
487
488    def test_explict_int64_array_too_small_value(self):
489        with self.assertRaises(OverflowError):
490            props = {b"key": [int64_t(0), int64_t(-(2 ** 63) - 1)]}
491            self._dict_to_nvlist_to_dict(props)
492
493    def test_explict_int32_array(self):
494        props = {b"key": [
495            int32_t(0), int32_t(1), int32_t(2 ** 31 - 1), int32_t(-(2 ** 31))]}
496        res = self._dict_to_nvlist_to_dict(props)
497        self._assertIntArrayDictsEqual(props, res)
498
499    def test_explict_int32_array_too_large_value(self):
500        with self.assertRaises(OverflowError):
501            props = {b"key": [int32_t(0), int32_t(2 ** 31)]}
502            self._dict_to_nvlist_to_dict(props)
503
504    def test_explict_int32_array_too_small_value(self):
505        with self.assertRaises(OverflowError):
506            props = {b"key": [int32_t(0), int32_t(-(2 ** 31) - 1)]}
507            self._dict_to_nvlist_to_dict(props)
508
509    def test_explict_int16_array(self):
510        props = {b"key": [
511            int16_t(0), int16_t(1), int16_t(2 ** 15 - 1), int16_t(-(2 ** 15))]}
512        res = self._dict_to_nvlist_to_dict(props)
513        self._assertIntArrayDictsEqual(props, res)
514
515    def test_explict_int16_array_too_large_value(self):
516        with self.assertRaises(OverflowError):
517            props = {b"key": [int16_t(0), int16_t(2 ** 15)]}
518            self._dict_to_nvlist_to_dict(props)
519
520    def test_explict_int16_array_too_small_value(self):
521        with self.assertRaises(OverflowError):
522            props = {b"key": [int16_t(0), int16_t(-(2 ** 15) - 1)]}
523            self._dict_to_nvlist_to_dict(props)
524
525    def test_explict_int8_array(self):
526        props = {b"key": [
527            int8_t(0), int8_t(1), int8_t(2 ** 7 - 1), int8_t(-(2 ** 7))]}
528        res = self._dict_to_nvlist_to_dict(props)
529        self._assertIntArrayDictsEqual(props, res)
530
531    def test_explict_int8_array_too_large_value(self):
532        with self.assertRaises(OverflowError):
533            props = {b"key": [int8_t(0), int8_t(2 ** 7)]}
534            self._dict_to_nvlist_to_dict(props)
535
536    def test_explict_int8_array_too_small_value(self):
537        with self.assertRaises(OverflowError):
538            props = {b"key": [int8_t(0), int8_t(-(2 ** 7) - 1)]}
539            self._dict_to_nvlist_to_dict(props)
540
541    def test_dict_array(self):
542        props = {b"key": [{b"key": 1}, {b"key": None}, {b"key": {}}]}
543        res = self._dict_to_nvlist_to_dict(props)
544        self.assertEqual(props, res)
545
546    def test_implicit_uint32_value(self):
547        props = {b"rewind-request": 1}
548        res = self._dict_to_nvlist_to_dict(props)
549        self._assertIntDictsEqual(props, res)
550
551    def test_implicit_uint32_max_value(self):
552        props = {b"rewind-request": 2 ** 32 - 1}
553        res = self._dict_to_nvlist_to_dict(props)
554        self._assertIntDictsEqual(props, res)
555
556    def test_implicit_uint32_too_large_value(self):
557        with self.assertRaises(OverflowError):
558            props = {b"rewind-request": 2 ** 32}
559            self._dict_to_nvlist_to_dict(props)
560
561    def test_implicit_uint32_negative_value(self):
562        with self.assertRaises(OverflowError):
563            props = {b"rewind-request": -1}
564            self._dict_to_nvlist_to_dict(props)
565
566    def test_implicit_int32_value(self):
567        props = {b"pool_context": 1}
568        res = self._dict_to_nvlist_to_dict(props)
569        self._assertIntDictsEqual(props, res)
570
571    def test_implicit_int32_max_value(self):
572        props = {b"pool_context": 2 ** 31 - 1}
573        res = self._dict_to_nvlist_to_dict(props)
574        self._assertIntDictsEqual(props, res)
575
576    def test_implicit_int32_min_value(self):
577        props = {b"pool_context": -(2 ** 31)}
578        res = self._dict_to_nvlist_to_dict(props)
579        self._assertIntDictsEqual(props, res)
580
581    def test_implicit_int32_too_large_value(self):
582        with self.assertRaises(OverflowError):
583            props = {b"pool_context": 2 ** 31}
584            self._dict_to_nvlist_to_dict(props)
585
586    def test_implicit_int32_too_small_value(self):
587        with self.assertRaises(OverflowError):
588            props = {b"pool_context": -(2 ** 31) - 1}
589            self._dict_to_nvlist_to_dict(props)
590
591    def test_complex_dict(self):
592        props = {
593            b"key1": b"str",
594            b"key2": 10,
595            b"key3": {
596                b"skey1": True,
597                b"skey2": None,
598                b"skey3": [
599                    True,
600                    False,
601                    True
602                ]
603            },
604            b"key4": [
605                b"ab",
606                b"bc"
607            ],
608            b"key5": [
609                2 ** 64 - 1,
610                1,
611                2,
612                3
613            ],
614            b"key6": [
615                {
616                    b"skey71": b"a",
617                    b"skey72": b"b",
618                },
619                {
620                    b"skey71": b"c",
621                    b"skey72": b"d",
622                },
623                {
624                    b"skey71": b"e",
625                    b"skey72": b"f",
626                }
627
628            ],
629            b"type": 2 ** 32 - 1,
630            b"pool_context": -(2 ** 31)
631        }
632        res = self._dict_to_nvlist_to_dict(props)
633        self.assertEqual(props, res)
634
635
636# vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4
637