def test_jsonify_primitive_types(self): """Test jsonify_data with primitive data types only""" dct = {"a": 1, "b": "2", "1": True, "31": None, } res = jsonify_data(dct) self.assertEqual(res, json.dumps(dct)) back = dejsonify_data(res) self.assertDictEqual(dct, dict_unicode_to_str(back))
def test_jsonify_numpy_shaped(self): """Test jsonify_data with dict w/ 3d numpy array""" dct = {"array": np.arange(27).reshape((3, 3, 3)), } res = jsonify_data(dct) back = dejsonify_data(res) self.assertIsInstance(res, str) self.assertIsInstance(back, dict) self.assertIn("array", back) np.testing.assert_array_equal(dct["array"], back["array"]) self.assertEqual(dct["array"].dtype, back["array"].dtype) self.assertEqual(dct["array"].shape, back["array"].shape)