def test_loader_uses_decimal_to_parse_numbers(self): text = """ { "number": 1.5 } """ doc = JSON.loads(text) number = doc["number"] self.assertEqual(number, Decimal("1.5")) self.assertTrue(isinstance(number, Decimal))
def test_dumper_can_dump_decimals(self): doc = { "format": "Dashboard Bundle Format 1.0", "test_runs": [ { "test_id": "NOT RELEVANT", "analyzer_assigned_date": "2010-11-14T01:03:06Z", "analyzer_assigned_uuid": "NOT RELEVANT", "time_check_performed": False, "test_results": [ { "test_case_id": "NOT RELEVANT", "result": "unknown", "measurement": Decimal("1.5")}]}]} text = JSON.dumps(doc) self.assertIn("1.5", text)
def test_dumper_can_dump_decimals(self): doc = { "format": "Dashboard Bundle Format 1.0", "test_runs": [{ "test_id": "NOT RELEVANT", "analyzer_assigned_date": "2010-11-14T01:03:06Z", "analyzer_assigned_uuid": "NOT RELEVANT", "time_check_performed": False, "test_results": [{ "test_case_id": "NOT RELEVANT", "result": "unknown", "measurement": Decimal("1.5") }] }] } text = JSON.dumps(doc) self.assertIn("1.5", text)
def test_dump_produces_readable_output(self): stream = StringIO() JSON.dump(stream, self.doc, human_readable=True) observed_text = stream.getvalue() self.assertEqual(observed_text, self.expected_readable_text)
def test_dumps_produces_compact_sorted_ouptut(self): observed_text = JSON.dumps( self.doc, human_readable=False, sort_keys=True) self.assertEqual(observed_text, self.expected_compact_sorted_text)
def test_dumps_produces_readable_ouptut(self): observed_text = JSON.dumps(self.doc, human_readable=True) self.assertEqual(observed_text, self.expected_readable_text)
def test_dumps_produces_compact_sorted_ouptut(self): observed_text = JSON.dumps(self.doc, human_readable=False, sort_keys=True) self.assertEqual(observed_text, self.expected_compact_sorted_text)
def test_load__with_enabled_retain_order__dict_class(self): doc = JSON.load(self.stream, retain_order=True) observed_impl = type(doc) # Note: VVV self.assertNotEqual(observed_impl, dict)
def test_load__return_value(self): doc = JSON.load(self.stream) self.assertEqual(doc, self.expected_doc)
def test_loads__return_value(self): doc = JSON.loads(self.text) self.assertEqual(doc, self.expected_doc)
def test_dump_produces_compact_sorted_output(self): stream = StringIO() JSON.dump(stream, self.doc, human_readable=False, sort_keys=True) observed_text = stream.getvalue() self.assertEqual(observed_text, self.expected_compact_sorted_text)
def test_load__with_enabled_retain_order__key_order(self): doc = JSON.load(self.stream, retain_order=True) observed_keys = list(doc.keys()) self.assertEqual(observed_keys, self.expected_keys)
def test_load__with_disabled_retain_order__dict_class(self): doc = JSON.load(self.stream, retain_order=False) expected_impl = dict observed_impl = type(doc) self.assertEqual(observed_impl, expected_impl)
def test_loads__with_enabled_retain_order__key_order(self): doc = JSON.loads(self.text, retain_order=True) observed_keys = doc.keys() self.assertEqual(observed_keys, self.expected_keys)
def test_loads__with_disabled_retain_order__dict_class(self): doc = JSON.loads(self.text, retain_order=False) expected_impl = dict observed_impl = type(doc) self.assertEqual(observed_impl, expected_impl)