def testPrettyParamsExtraParamsInside(self): s = json_utils.Dumps({ 'v': 1.012345, 'n': float('nan') }, **json_utils.PrettyParams(allow_nan=True)) self.assertEqual(s, '{\n "n": NaN,\n "v": 1.0123\n}') with self.assertRaises(ValueError): s = json_utils.Dumps({ 'v': 1.012345, 'n': float('nan') }, **json_utils.PrettyParams(allow_nan=False))
def testPrettyParams(self): s = json_utils.Dumps({ 'v': 1.012345, 'n': 2 }, **json_utils.PrettyParams()) self.assertEqual(s, '{\n "n": 2,\n "v": 1.0123\n}')
def testDumpsUnspecifiedPrecision(self): s = json_utils.Dumps(1.012345) self.assertEqual(s, '1.012345')
def testDumpsZeroPrecision(self): s = json_utils.Dumps(1.0, float_digits=0) self.assertEqual(s, '1')
def testDumpsPassExtraParams(self): s = json_utils.Dumps([1.0], float_digits=2, indent=3) self.assertEqual(s, '[\n 1.00\n]')
def testDumpsReasonablePrecision(self): s = json_utils.Dumps(1.0, float_digits=2) self.assertEqual(s, '1.00')