Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
test: fix test, drop objgraph memory test
Browse files Browse the repository at this point in the history
  • Loading branch information
Antares0982 committed Mar 28, 2024
1 parent 6fd05c8 commit 587e4f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
15 changes: 6 additions & 9 deletions test/decode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class TestDecode(unittest.TestCase):
def test_decode(self):
import json
import math
import gc
import objgraph

import cjson

Expand All @@ -25,7 +23,7 @@ def test_decode(self):
"abc",
math.inf,
-math.inf,
math.nan, # TODO
math.nan, # TODO
math.pi,
[], {}, tuple(),
[1, 2, 3, 4],
Expand All @@ -39,14 +37,13 @@ def test_decode(self):
test_cases = [json.dumps(case, ensure_ascii=False) for case in test_cases]

for case in test_cases:
re_json = json.loads(case)
with self.subTest(msg=f'decoding_test(case={case})'):
gc.collect()
objs = [id(a) for a in objgraph.get_leaking_objects()]
re_json = json.loads(case)
re_cjson = cjson.loads(case)
re = [a for a in list(objgraph.get_leaking_objects()) if id(a) not in objs]
self.assertEqual(len(re), 0, f"leak: {re}")
self.assertEqual(re_cjson, re_json)
if isinstance(re_json, float) and math.isnan(re_json):
self.assertTrue(math.isnan(re_cjson))
else:
self.assertEqual(re_cjson, re_json)


if __name__ == "__main__":
Expand Down
13 changes: 0 additions & 13 deletions test/encode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

class TestEncode(unittest.TestCase):
def test_fail(self):
import objgraph
import gc
import cjson

class A:
Expand All @@ -16,18 +14,12 @@ class A:

for case in test_cases:
with self.subTest(msg=f'encoding_fail_test(case={case})'):
gc.collect()
objs = [id(a) for a in objgraph.get_leaking_objects()]
with self.assertRaises(Exception):
cjson.dumps(case)
re = [a for a in list(objgraph.get_leaking_objects()) if id(a) not in objs]
self.assertEqual(len(re), 0, f"leak: {re}")

def test_encode(self):
import json
import math
import objgraph
import gc

import cjson

Expand Down Expand Up @@ -58,14 +50,9 @@ def test_encode(self):
for case in test_cases:
result_json = json.dumps(case, indent=None, separators=(",", ":"), ensure_ascii=False)
result_loadback_json = json.loads(result_json)
#

with self.subTest(msg=f'encoding_test(case={case})'):
gc.collect()
objs = [id(a) for a in objgraph.get_leaking_objects()]
result_cjson = cjson.dumps(case)
re = [a for a in list(objgraph.get_leaking_objects()) if id(a) not in objs]
self.assertEqual(len(re), 0, f"leak: {re}")
result_loadback_cjson = json.loads(result_cjson)
self._check(result_loadback_json, result_loadback_cjson)

Expand Down
1 change: 1 addition & 0 deletions test/memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def random_object(seed=None):

now = time.time()
seeds = [now * i for i in range(1, 31)]
seeds = [1711648723.164294]
for seed in seeds:
data = random_object(seed)
print(f"--seed {seed}")
Expand Down

0 comments on commit 587e4f2

Please sign in to comment.