@@ -26,6 +26,42 @@ def api(runner):
2626 return Api ()
2727
2828
29+ def test_wb_value (live_mock_server , test_settings ):
30+ run = wandb .init (settings = test_settings )
31+ local_art = wandb .Artifact ("N" , "T" )
32+ public_art = run .use_artifact ("N:latest" )
33+
34+ wbvalue = data_types .WBValue ()
35+ with pytest .raises (NotImplementedError ):
36+ wbvalue .to_json (local_art )
37+
38+ with pytest .raises (NotImplementedError ):
39+ data_types .WBValue .from_json ({}, public_art )
40+
41+ assert data_types .WBValue .with_suffix ("item" ) == "item.json"
42+
43+ table = data_types .WBValue .init_from_json (
44+ {
45+ "_type" : "table" ,
46+ "data" : [[]],
47+ "columns" : [],
48+ "column_types" : wandb .data_types ._dtypes .DictType ({}).to_json (),
49+ },
50+ public_art ,
51+ )
52+ assert isinstance (table , data_types .WBValue ) and isinstance (
53+ table , wandb .data_types .Table
54+ )
55+
56+ type_mapping = data_types .WBValue .type_mapping ()
57+ assert all (
58+ [issubclass (type_mapping [key ], data_types .WBValue ) for key in type_mapping ]
59+ )
60+
61+ assert wbvalue == wbvalue
62+ assert wbvalue != data_types .WBValue ()
63+
64+
2965def test_raw_data ():
3066 wbhist = wandb .Histogram (data )
3167 assert len (wbhist .histogram ) == 64
@@ -161,7 +197,7 @@ def test_max_images(caplog, mocked_run):
161197 large_list = [wandb .Image (large_image )] * 200
162198 large_list [0 ].bind_to_run (mocked_run , "test2" , 0 , 0 )
163199 meta = wandb .Image .seq_to_json (
164- data_types .prune_max_seq (large_list ), mocked_run , "test2" , 0
200+ wandb . wandb_sdk . data_types ._prune_max_seq (large_list ), mocked_run , "test2" , 0
165201 )
166202 expected = {
167203 "_type" : "images/separated" ,
@@ -407,6 +443,17 @@ def test_molecule(runner, mocked_run):
407443 assert os .path .exists (mol ._path )
408444
409445
446+ def test_molecule_file (runner , mocked_run ):
447+ with runner .isolated_filesystem ():
448+ with open ("test.pdb" , "w" ) as f :
449+ f .write ("00000" )
450+ mol = wandb .Molecule (open ("test.pdb" , "r" ))
451+ mol .bind_to_run (mocked_run , "rad" , "summary" )
452+ wandb .Molecule .seq_to_json ([mol ], mocked_run , "rad" , "summary" )
453+
454+ assert os .path .exists (mol ._path )
455+
456+
410457def test_html_str (mocked_run ):
411458 html = wandb .Html ("<html><body><h1>Hello</h1></body></html>" )
412459 html .bind_to_run (mocked_run , "rad" , "summary" )
@@ -446,6 +493,16 @@ def test_html_file(mocked_run):
446493 assert os .path .exists (html ._path )
447494
448495
496+ def test_html_file_path (mocked_run ):
497+ with open ("test.html" , "w" ) as f :
498+ f .write ("<html><body><h1>Hello</h1></body></html>" )
499+ html = wandb .Html ("test.html" )
500+ html .bind_to_run (mocked_run , "rad" , "summary" )
501+ wandb .Html .seq_to_json ([html , html ], mocked_run , "rad" , "summary" )
502+
503+ assert os .path .exists (html ._path )
504+
505+
449506def test_table_default ():
450507 table = wandb .Table ()
451508 table .add_data ("Some awesome text" , "Positive" , "Negative" )
@@ -494,6 +551,22 @@ def test_object3d_numpy(mocked_run):
494551 assert obj3 .to_json (mocked_run )["_type" ] == "object3D-file"
495552
496553
554+ def test_object3d_dict (mocked_run ):
555+ obj = wandb .Object3D ({"type" : "lidar/beta" ,})
556+ obj .bind_to_run (mocked_run , "object3D" , 0 )
557+ assert obj .to_json (mocked_run )["_type" ] == "object3D-file"
558+
559+
560+ def test_object3d_dict_invalid (mocked_run ):
561+ with pytest .raises (ValueError ):
562+ obj = wandb .Object3D ({"type" : "INVALID" ,})
563+
564+
565+ def test_object3d_dict_invalid_string (mocked_run ):
566+ with pytest .raises (ValueError ):
567+ obj = wandb .Object3D ("INVALID" )
568+
569+
497570def test_object3d_obj (mocked_run ):
498571 obj = wandb .Object3D (utils .fixture_open ("cube.obj" ))
499572 obj .bind_to_run (mocked_run , "object3D" , 0 )
@@ -651,7 +724,7 @@ def test_graph():
651724
652725
653726def test_numpy_arrays_to_list ():
654- conv = data_types .numpy_arrays_to_lists
727+ conv = data_types ._numpy_arrays_to_lists
655728 assert conv (np .array ((1 , 2 ,))) == [1 , 2 ]
656729 assert conv ([np .array ((1 , 2 ,))]) == [[1 , 2 ]]
657730 assert conv (np .array (({"a" : [np .array ((1 , 2 ,))]}, 3 ))) == [{"a" : [[1 , 2 ]]}, 3 ]
0 commit comments