mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
pyzfs: python3 support (unit tests)
* Updated unit tests to be compatbile with python 2 or 3. In most cases all that was required was to add the 'b' prefix to existing strings to convert them to type bytes for python 3 compatibility. * There were several places where the python version need to be checked to remain compatible with pythong 2 and 3. Some one more seasoned with Python may be able to find a way to rewrite these statements in a compatible fashion. Reviewed-by: John Ramsden <johnramsden@riseup.net> Reviewed-by: Neal Gompa <ngompa@datto.com> Reviewed-by: loli10K <ezomori.nozomu@gmail.com> Signed-off-by: John Wren Kennedy <john.kennedy@delphix.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #8096
This commit is contained in:
parent
e5fb1dc586
commit
4b1c4062d0
File diff suppressed because it is too large
Load Diff
@ -44,25 +44,25 @@ class TestNVList(unittest.TestCase):
|
||||
def _assertIntDictsEqual(self, dict1, dict2):
|
||||
self.assertEqual(
|
||||
len(dict1), len(dict1),
|
||||
"resulting dictionary is of different size")
|
||||
b"resulting dictionary is of different size")
|
||||
for key in dict1.keys():
|
||||
self.assertEqual(int(dict1[key]), int(dict2[key]))
|
||||
|
||||
def _assertIntArrayDictsEqual(self, dict1, dict2):
|
||||
self.assertEqual(
|
||||
len(dict1), len(dict1),
|
||||
"resulting dictionary is of different size")
|
||||
b"resulting dictionary is of different size")
|
||||
for key in dict1.keys():
|
||||
val1 = dict1[key]
|
||||
val2 = dict2[key]
|
||||
self.assertEqual(
|
||||
len(val1), len(val2), "array values of different sizes")
|
||||
len(val1), len(val2), b"array values of different sizes")
|
||||
for x, y in zip(val1, val2):
|
||||
self.assertEqual(int(x), int(y))
|
||||
|
||||
def test_empty(self):
|
||||
res = self._dict_to_nvlist_to_dict({})
|
||||
self.assertEqual(len(res), 0, "expected empty dict")
|
||||
self.assertEqual(len(res), 0, b"expected empty dict")
|
||||
|
||||
def test_invalid_key_type(self):
|
||||
with self.assertRaises(TypeError):
|
||||
@ -70,564 +70,564 @@ class TestNVList(unittest.TestCase):
|
||||
|
||||
def test_invalid_val_type__tuple(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict({"key": (1, 2)})
|
||||
self._dict_to_nvlist_to_dict({b"key": (1, 2)})
|
||||
|
||||
def test_invalid_val_type__set(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict({"key": set(1, 2)})
|
||||
self._dict_to_nvlist_to_dict({b"key": set(1, 2)})
|
||||
|
||||
def test_invalid_array_val_type(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict({"key": [(1, 2), (3, 4)]})
|
||||
self._dict_to_nvlist_to_dict({b"key": [(1, 2), (3, 4)]})
|
||||
|
||||
def test_invalid_array_of_arrays_val_type(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict({"key": [[1, 2], [3, 4]]})
|
||||
self._dict_to_nvlist_to_dict({b"key": [[1, 2], [3, 4]]})
|
||||
|
||||
def test_string_value(self):
|
||||
props = {"key": "value"}
|
||||
props = {b"key": b"value"}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_implicit_boolean_value(self):
|
||||
props = {"key": None}
|
||||
props = {b"key": None}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_boolean_values(self):
|
||||
props = {"key1": True, "key2": False}
|
||||
props = {b"key1": True, b"key2": False}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_explicit_boolean_true_value(self):
|
||||
props = {"key": boolean_t(1)}
|
||||
props = {b"key": boolean_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_boolean_false_value(self):
|
||||
props = {"key": boolean_t(0)}
|
||||
props = {b"key": boolean_t(0)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_boolean_invalid_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": boolean_t(2)}
|
||||
props = {b"key": boolean_t(2)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_boolean_another_invalid_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": boolean_t(-1)}
|
||||
props = {b"key": boolean_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_uint64_value(self):
|
||||
props = {"key": 1}
|
||||
props = {b"key": 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_uint64_max_value(self):
|
||||
props = {"key": 2 ** 64 - 1}
|
||||
props = {b"key": 2 ** 64 - 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_uint64_too_large_value(self):
|
||||
props = {"key": 2 ** 64}
|
||||
props = {b"key": 2 ** 64}
|
||||
with self.assertRaises(OverflowError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_uint64_negative_value(self):
|
||||
props = {"key": -1}
|
||||
props = {b"key": -1}
|
||||
with self.assertRaises(OverflowError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint64_value(self):
|
||||
props = {"key": uint64_t(1)}
|
||||
props = {b"key": uint64_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint64_max_value(self):
|
||||
props = {"key": uint64_t(2 ** 64 - 1)}
|
||||
props = {b"key": uint64_t(2 ** 64 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint64_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint64_t(2 ** 64)}
|
||||
props = {b"key": uint64_t(2 ** 64)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint64_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint64_t(-1)}
|
||||
props = {b"key": uint64_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint32_value(self):
|
||||
props = {"key": uint32_t(1)}
|
||||
props = {b"key": uint32_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint32_max_value(self):
|
||||
props = {"key": uint32_t(2 ** 32 - 1)}
|
||||
props = {b"key": uint32_t(2 ** 32 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint32_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint32_t(2 ** 32)}
|
||||
props = {b"key": uint32_t(2 ** 32)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint32_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint32_t(-1)}
|
||||
props = {b"key": uint32_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint16_value(self):
|
||||
props = {"key": uint16_t(1)}
|
||||
props = {b"key": uint16_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint16_max_value(self):
|
||||
props = {"key": uint16_t(2 ** 16 - 1)}
|
||||
props = {b"key": uint16_t(2 ** 16 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint16_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint16_t(2 ** 16)}
|
||||
props = {b"key": uint16_t(2 ** 16)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint16_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint16_t(-1)}
|
||||
props = {b"key": uint16_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint8_value(self):
|
||||
props = {"key": uint8_t(1)}
|
||||
props = {b"key": uint8_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint8_max_value(self):
|
||||
props = {"key": uint8_t(2 ** 8 - 1)}
|
||||
props = {b"key": uint8_t(2 ** 8 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_uint8_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint8_t(2 ** 8)}
|
||||
props = {b"key": uint8_t(2 ** 8)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_uint8_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uint8_t(-1)}
|
||||
props = {b"key": uint8_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_byte_value(self):
|
||||
props = {"key": uchar_t(1)}
|
||||
props = {b"key": uchar_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_byte_max_value(self):
|
||||
props = {"key": uchar_t(2 ** 8 - 1)}
|
||||
props = {b"key": uchar_t(2 ** 8 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_byte_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uchar_t(2 ** 8)}
|
||||
props = {b"key": uchar_t(2 ** 8)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_byte_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": uchar_t(-1)}
|
||||
props = {b"key": uchar_t(-1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int64_value(self):
|
||||
props = {"key": int64_t(1)}
|
||||
props = {b"key": int64_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int64_max_value(self):
|
||||
props = {"key": int64_t(2 ** 63 - 1)}
|
||||
props = {b"key": int64_t(2 ** 63 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int64_min_value(self):
|
||||
props = {"key": int64_t(-(2 ** 63))}
|
||||
props = {b"key": int64_t(-(2 ** 63))}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int64_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int64_t(2 ** 63)}
|
||||
props = {b"key": int64_t(2 ** 63)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int64_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int64_t(-(2 ** 63) - 1)}
|
||||
props = {b"key": int64_t(-(2 ** 63) - 1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int32_value(self):
|
||||
props = {"key": int32_t(1)}
|
||||
props = {b"key": int32_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int32_max_value(self):
|
||||
props = {"key": int32_t(2 ** 31 - 1)}
|
||||
props = {b"key": int32_t(2 ** 31 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int32_min_value(self):
|
||||
props = {"key": int32_t(-(2 ** 31))}
|
||||
props = {b"key": int32_t(-(2 ** 31))}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int32_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int32_t(2 ** 31)}
|
||||
props = {b"key": int32_t(2 ** 31)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int32_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int32_t(-(2 ** 31) - 1)}
|
||||
props = {b"key": int32_t(-(2 ** 31) - 1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int16_value(self):
|
||||
props = {"key": int16_t(1)}
|
||||
props = {b"key": int16_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int16_max_value(self):
|
||||
props = {"key": int16_t(2 ** 15 - 1)}
|
||||
props = {b"key": int16_t(2 ** 15 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int16_min_value(self):
|
||||
props = {"key": int16_t(-(2 ** 15))}
|
||||
props = {b"key": int16_t(-(2 ** 15))}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int16_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int16_t(2 ** 15)}
|
||||
props = {b"key": int16_t(2 ** 15)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int16_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int16_t(-(2 ** 15) - 1)}
|
||||
props = {b"key": int16_t(-(2 ** 15) - 1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int8_value(self):
|
||||
props = {"key": int8_t(1)}
|
||||
props = {b"key": int8_t(1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int8_max_value(self):
|
||||
props = {"key": int8_t(2 ** 7 - 1)}
|
||||
props = {b"key": int8_t(2 ** 7 - 1)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int8_min_value(self):
|
||||
props = {"key": int8_t(-(2 ** 7))}
|
||||
props = {b"key": int8_t(-(2 ** 7))}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_explicit_int8_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int8_t(2 ** 7)}
|
||||
props = {b"key": int8_t(2 ** 7)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explicit_int8_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": int8_t(-(2 ** 7) - 1)}
|
||||
props = {b"key": int8_t(-(2 ** 7) - 1)}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_nested_dict(self):
|
||||
props = {"key": {}}
|
||||
props = {b"key": {}}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_nested_nested_dict(self):
|
||||
props = {"key": {"key": {}}}
|
||||
props = {b"key": {b"key": {}}}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_mismatching_values_array(self):
|
||||
props = {"key": [1, "string"]}
|
||||
props = {b"key": [1, b"string"]}
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_mismatching_values_array2(self):
|
||||
props = {"key": [True, 10]}
|
||||
props = {b"key": [True, 10]}
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_mismatching_values_array3(self):
|
||||
props = {"key": [1, False]}
|
||||
props = {b"key": [1, False]}
|
||||
with self.assertRaises(TypeError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_string_array(self):
|
||||
props = {"key": ["value", "value2"]}
|
||||
props = {b"key": [b"value", b"value2"]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_boolean_array(self):
|
||||
props = {"key": [True, False]}
|
||||
props = {b"key": [True, False]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_explicit_boolean_array(self):
|
||||
props = {"key": [boolean_t(False), boolean_t(True)]}
|
||||
props = {b"key": [boolean_t(False), boolean_t(True)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_uint64_array(self):
|
||||
props = {"key": [0, 1, 2 ** 64 - 1]}
|
||||
props = {b"key": [0, 1, 2 ** 64 - 1]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_uint64_array_too_large_value(self):
|
||||
props = {"key": [0, 2 ** 64]}
|
||||
props = {b"key": [0, 2 ** 64]}
|
||||
with self.assertRaises(OverflowError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_uint64_array_negative_value(self):
|
||||
props = {"key": [0, -1]}
|
||||
props = {b"key": [0, -1]}
|
||||
with self.assertRaises(OverflowError):
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_mixed_explict_int_array(self):
|
||||
with self.assertRaises(TypeError):
|
||||
props = {"key": [uint64_t(0), uint32_t(0)]}
|
||||
props = {b"key": [uint64_t(0), uint32_t(0)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint64_array(self):
|
||||
props = {"key": [uint64_t(0), uint64_t(1), uint64_t(2 ** 64 - 1)]}
|
||||
props = {b"key": [uint64_t(0), uint64_t(1), uint64_t(2 ** 64 - 1)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_uint64_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint64_t(0), uint64_t(2 ** 64)]}
|
||||
props = {b"key": [uint64_t(0), uint64_t(2 ** 64)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint64_array_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint64_t(0), uint64_t(-1)]}
|
||||
props = {b"key": [uint64_t(0), uint64_t(-1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint32_array(self):
|
||||
props = {"key": [uint32_t(0), uint32_t(1), uint32_t(2 ** 32 - 1)]}
|
||||
props = {b"key": [uint32_t(0), uint32_t(1), uint32_t(2 ** 32 - 1)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_uint32_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint32_t(0), uint32_t(2 ** 32)]}
|
||||
props = {b"key": [uint32_t(0), uint32_t(2 ** 32)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint32_array_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint32_t(0), uint32_t(-1)]}
|
||||
props = {b"key": [uint32_t(0), uint32_t(-1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint16_array(self):
|
||||
props = {"key": [uint16_t(0), uint16_t(1), uint16_t(2 ** 16 - 1)]}
|
||||
props = {b"key": [uint16_t(0), uint16_t(1), uint16_t(2 ** 16 - 1)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_uint16_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint16_t(0), uint16_t(2 ** 16)]}
|
||||
props = {b"key": [uint16_t(0), uint16_t(2 ** 16)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint16_array_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint16_t(0), uint16_t(-1)]}
|
||||
props = {b"key": [uint16_t(0), uint16_t(-1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint8_array(self):
|
||||
props = {"key": [uint8_t(0), uint8_t(1), uint8_t(2 ** 8 - 1)]}
|
||||
props = {b"key": [uint8_t(0), uint8_t(1), uint8_t(2 ** 8 - 1)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_uint8_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint8_t(0), uint8_t(2 ** 8)]}
|
||||
props = {b"key": [uint8_t(0), uint8_t(2 ** 8)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_uint8_array_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uint8_t(0), uint8_t(-1)]}
|
||||
props = {b"key": [uint8_t(0), uint8_t(-1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_byte_array(self):
|
||||
props = {"key": [uchar_t(0), uchar_t(1), uchar_t(2 ** 8 - 1)]}
|
||||
props = {b"key": [uchar_t(0), uchar_t(1), uchar_t(2 ** 8 - 1)]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_byte_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uchar_t(0), uchar_t(2 ** 8)]}
|
||||
props = {b"key": [uchar_t(0), uchar_t(2 ** 8)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_byte_array_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [uchar_t(0), uchar_t(-1)]}
|
||||
props = {b"key": [uchar_t(0), uchar_t(-1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int64_array(self):
|
||||
props = {"key": [
|
||||
props = {b"key": [
|
||||
int64_t(0), int64_t(1), int64_t(2 ** 63 - 1), int64_t(-(2 ** 63))]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_int64_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int64_t(0), int64_t(2 ** 63)]}
|
||||
props = {b"key": [int64_t(0), int64_t(2 ** 63)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int64_array_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int64_t(0), int64_t(-(2 ** 63) - 1)]}
|
||||
props = {b"key": [int64_t(0), int64_t(-(2 ** 63) - 1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int32_array(self):
|
||||
props = {"key": [
|
||||
props = {b"key": [
|
||||
int32_t(0), int32_t(1), int32_t(2 ** 31 - 1), int32_t(-(2 ** 31))]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_int32_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int32_t(0), int32_t(2 ** 31)]}
|
||||
props = {b"key": [int32_t(0), int32_t(2 ** 31)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int32_array_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int32_t(0), int32_t(-(2 ** 31) - 1)]}
|
||||
props = {b"key": [int32_t(0), int32_t(-(2 ** 31) - 1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int16_array(self):
|
||||
props = {"key": [
|
||||
props = {b"key": [
|
||||
int16_t(0), int16_t(1), int16_t(2 ** 15 - 1), int16_t(-(2 ** 15))]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_int16_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int16_t(0), int16_t(2 ** 15)]}
|
||||
props = {b"key": [int16_t(0), int16_t(2 ** 15)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int16_array_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int16_t(0), int16_t(-(2 ** 15) - 1)]}
|
||||
props = {b"key": [int16_t(0), int16_t(-(2 ** 15) - 1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int8_array(self):
|
||||
props = {"key": [
|
||||
props = {b"key": [
|
||||
int8_t(0), int8_t(1), int8_t(2 ** 7 - 1), int8_t(-(2 ** 7))]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntArrayDictsEqual(props, res)
|
||||
|
||||
def test_explict_int8_array_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int8_t(0), int8_t(2 ** 7)]}
|
||||
props = {b"key": [int8_t(0), int8_t(2 ** 7)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_explict_int8_array_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"key": [int8_t(0), int8_t(-(2 ** 7) - 1)]}
|
||||
props = {b"key": [int8_t(0), int8_t(-(2 ** 7) - 1)]}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_dict_array(self):
|
||||
props = {"key": [{"key": 1}, {"key": None}, {"key": {}}]}
|
||||
props = {b"key": [{b"key": 1}, {b"key": None}, {b"key": {}}]}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
||||
def test_implicit_uint32_value(self):
|
||||
props = {"rewind-request": 1}
|
||||
props = {b"rewind-request": 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_implicit_uint32_max_value(self):
|
||||
props = {"rewind-request": 2 ** 32 - 1}
|
||||
props = {b"rewind-request": 2 ** 32 - 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_implicit_uint32_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"rewind-request": 2 ** 32}
|
||||
props = {b"rewind-request": 2 ** 32}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_implicit_uint32_negative_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"rewind-request": -1}
|
||||
props = {b"rewind-request": -1}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_implicit_int32_value(self):
|
||||
props = {"pool_context": 1}
|
||||
props = {b"pool_context": 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_implicit_int32_max_value(self):
|
||||
props = {"pool_context": 2 ** 31 - 1}
|
||||
props = {b"pool_context": 2 ** 31 - 1}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_implicit_int32_min_value(self):
|
||||
props = {"pool_context": -(2 ** 31)}
|
||||
props = {b"pool_context": -(2 ** 31)}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self._assertIntDictsEqual(props, res)
|
||||
|
||||
def test_implicit_int32_too_large_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"pool_context": 2 ** 31}
|
||||
props = {b"pool_context": 2 ** 31}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_implicit_int32_too_small_value(self):
|
||||
with self.assertRaises(OverflowError):
|
||||
props = {"pool_context": -(2 ** 31) - 1}
|
||||
props = {b"pool_context": -(2 ** 31) - 1}
|
||||
self._dict_to_nvlist_to_dict(props)
|
||||
|
||||
def test_complex_dict(self):
|
||||
props = {
|
||||
"key1": "str",
|
||||
"key2": 10,
|
||||
"key3": {
|
||||
"skey1": True,
|
||||
"skey2": None,
|
||||
"skey3": [
|
||||
b"key1": b"str",
|
||||
b"key2": 10,
|
||||
b"key3": {
|
||||
b"skey1": True,
|
||||
b"skey2": None,
|
||||
b"skey3": [
|
||||
True,
|
||||
False,
|
||||
True
|
||||
]
|
||||
},
|
||||
"key4": [
|
||||
"ab",
|
||||
"bc"
|
||||
b"key4": [
|
||||
b"ab",
|
||||
b"bc"
|
||||
],
|
||||
"key5": [
|
||||
b"key5": [
|
||||
2 ** 64 - 1,
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
"key6": [
|
||||
b"key6": [
|
||||
{
|
||||
"skey71": "a",
|
||||
"skey72": "b",
|
||||
b"skey71": b"a",
|
||||
b"skey72": b"b",
|
||||
},
|
||||
{
|
||||
"skey71": "c",
|
||||
"skey72": "d",
|
||||
b"skey71": b"c",
|
||||
b"skey72": b"d",
|
||||
},
|
||||
{
|
||||
"skey71": "e",
|
||||
"skey72": "f",
|
||||
b"skey71": b"e",
|
||||
b"skey72": b"f",
|
||||
}
|
||||
|
||||
],
|
||||
"type": 2 ** 32 - 1,
|
||||
"pool_context": -(2 ** 31)
|
||||
b"type": 2 ** 32 - 1,
|
||||
b"pool_context": -(2 ** 31)
|
||||
}
|
||||
res = self._dict_to_nvlist_to_dict(props)
|
||||
self.assertEqual(props, res)
|
||||
|
Loading…
Reference in New Issue
Block a user