1111
1212import pytest
1313
14+ from jupyter_client ._version import version_info as jupyter_client_version
15+
1416from .. import jsonutil
1517from ..jsonutil import json_clean , encode_images
1618
19+
20+ JUPYTER_CLIENT_MAJOR_VERSION = jupyter_client_version [0 ]
21+
22+
1723class MyInt (object ):
1824 def __int__ (self ):
1925 return 389
2026numbers .Integral .register (MyInt )
2127
28+
2229class MyFloat (object ):
2330 def __float__ (self ):
2431 return 3.14
2532numbers .Real .register (MyFloat )
2633
2734
35+ @pytest .mark .skipif (JUPYTER_CLIENT_MAJOR_VERSION >= 7 , reason = "json_clean is a no-op" )
2836def test ():
2937 # list of input/expected output. Use None for the expected output if it
3038 # can be the same as the input.
@@ -47,7 +55,7 @@ def test():
4755 (MyFloat (), 3.14 ),
4856 (MyInt (), 389 )
4957 ]
50-
58+
5159 for val , jval in pairs :
5260 if jval is None :
5361 jval = val
@@ -58,13 +66,14 @@ def test():
5866 json .loads (json .dumps (out ))
5967
6068
69+ @pytest .mark .skipif (JUPYTER_CLIENT_MAJOR_VERSION >= 7 , reason = "json_clean is a no-op" )
6170def test_encode_images ():
6271 # invalid data, but the header and footer are from real files
6372 pngdata = b'\x89 PNG\r \n \x1a \n blahblahnotactuallyvalidIEND\xae B`\x82 '
6473 jpegdata = b'\xff \xd8 \xff \xe0 \x00 \x10 JFIFblahblahjpeg(\xa0 \x0f \xff \xd9 '
6574 pdfdata = b'%PDF-1.\n trailer<</Root<</Pages<</Kids[<</MediaBox[0 0 3 3]>>]>>>>>>'
6675 bindata = b'\xff \xff \xff \xff '
67-
76+
6877 fmt = {
6978 'image/png' : pngdata ,
7079 'image/jpeg' : jpegdata ,
@@ -78,16 +87,18 @@ def test_encode_images():
7887 assert decoded == value
7988 encoded2 = json_clean (encode_images (encoded ))
8089 assert encoded == encoded2
81-
90+
8291 for key , value in fmt .items ():
8392 decoded = a2b_base64 (encoded [key ])
8493 assert decoded == value
8594
95+ @pytest .mark .skipif (JUPYTER_CLIENT_MAJOR_VERSION >= 7 , reason = "json_clean is a no-op" )
8696def test_lambda ():
8797 with pytest .raises (ValueError ):
8898 json_clean (lambda : 1 )
8999
90100
101+ @pytest .mark .skipif (JUPYTER_CLIENT_MAJOR_VERSION >= 7 , reason = "json_clean is a no-op" )
91102def test_exception ():
92103 bad_dicts = [{1 :'number' , '1' :'string' },
93104 {True :'bool' , 'True' :'string' },
@@ -97,6 +108,7 @@ def test_exception():
97108 json_clean (d )
98109
99110
111+ @pytest .mark .skipif (JUPYTER_CLIENT_MAJOR_VERSION >= 7 , reason = "json_clean is a no-op" )
100112def test_unicode_dict ():
101113 data = {'üniço∂e' : 'üniço∂e' }
102114 clean = jsonutil .json_clean (data )
0 commit comments