Coverage for jsonurl_benchmark_test.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-20 21:12 +0000

1import pytest 

2 

3pytest.importorskip("pytest_benchmark") 

4import jsonurl_py as jsonurl 

5from conftest import assert_roundtrip_data 

6 

7BENCHMARK_DATA = { 

8 "a": 1, 

9 "digits": [1, 2, 3, 4, 5, 6], 

10 "aaa": "aaa", 

11 "odd strings": [ 

12 " spa ce ", 

13 "'quo'te'", 

14 "&amper&sand&", 

15 "^car^et^", 

16 "+pl+us+", 

17 "#ha#sh#", 

18 "=eq=ual=", 

19 "/sl/ash/", 

20 "\\back\\slash\\", 

21 "$dol$lar$", 

22 ":co:lon:", 

23 ",com,ma,", 

24 "(par)(en)", 

25 ")par)en(", 

26 ], 

27 "": "empty-key", 

28 "empty-val": "", 

29 "exc": ["!", "e!", "!e", "!(", "!)", "a!b"], 

30 "structural": [",", "(", ")", ":"], 

31 "t": True, 

32 "f": False, 

33 "n": None, 

34 "tstr": "true", 

35 "fstr": "false", 

36 "nstr": "null", 

37 "float": -1.2445, 

38 "nest": [ 

39 None, 

40 False, 

41 True, 

42 "text", 

43 12, 

44 3.4, 

45 [ 

46 None, 

47 False, 

48 True, 

49 "text", 

50 12, 

51 3.4, 

52 ["a", "b"], 

53 {"a": "b"}, 

54 ], 

55 { 

56 "null": None, 

57 "false": False, 

58 "true": True, 

59 "text": "with space", 

60 "one two": 12, 

61 "three,four": 3.4, 

62 "list": ["a", 1], 

63 "dict": {"a": 1}, 

64 }, 

65 ], 

66} 

67 

68 

69def test_roundtrip_aqf(): 

70 assert_roundtrip_data(BENCHMARK_DATA, aqf=True) 

71 assert_roundtrip_data(BENCHMARK_DATA, aqf=True, implied_dict=True) 

72 

73 

74@pytest.mark.parametrize("aqf", [True, False]) 

75def test_loads(benchmark, aqf: bool): 

76 text = jsonurl.dumps(BENCHMARK_DATA, aqf=aqf) 

77 data = benchmark(lambda: jsonurl.loads(text, aqf=aqf)) 

78 assert data == BENCHMARK_DATA 

79 

80 

81@pytest.mark.parametrize("aqf", [True, False]) 

82def test_dumps(benchmark, aqf: bool): 

83 text = benchmark(lambda: jsonurl.dumps(BENCHMARK_DATA, aqf=aqf)) 

84 data = jsonurl.loads(text, aqf=aqf) 

85 assert data == BENCHMARK_DATA