@@ -235,6 +235,19 @@ def test_read_from_txt_data_tree(server_type):
235235 assert data_tree .has ("list_string" )
236236
237237
238+ @conftest .raises_for_servers_version_under ("4.0" )
239+ def test_print_data_tree (server_type ):
240+ data_tree = dpf .DataTree (server = server_type )
241+ with data_tree .to_fill () as to_fill :
242+ to_fill .int = 1
243+ to_fill .double = 1.0
244+ to_fill .string = "hello"
245+ to_fill .list_int = [1 , 2 ]
246+ to_fill .list_double = [1.5 , 2.5 ]
247+ to_fill .add (list_string = ["hello" , "bye" ])
248+ assert str (data_tree ) != ""
249+
250+
238251@conftest .raises_for_servers_version_under ("4.0" )
239252def test_sub_data_tree ():
240253 data_tree = dpf .DataTree ()
@@ -316,3 +329,48 @@ def test_unsupported_types_data_tree(server_type):
316329 data_tree .add (data1 = [[1 ]])
317330 with pytest .raises (TypeError ):
318331 data_tree .add (data1 = (1 , 2 ))
332+
333+
334+ @pytest .mark .skipif (
335+ not conftest .SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0 , reason = "Available for servers >=7.0"
336+ )
337+ def test_list_attributes_data_tree (server_type ):
338+ data_tree = dpf .DataTree (server = server_type )
339+ with data_tree .to_fill () as to_fill :
340+ to_fill .int = 1
341+ to_fill .double = 1.0
342+ to_fill .string = "hello"
343+ to_fill .list_int = [1 , 2 ]
344+ to_fill .list_double = [1.5 , 2.5 ]
345+ to_fill .add (list_string = ["hello" , "bye" ])
346+
347+ attributes = data_tree .get_attribute_names ()
348+
349+ assert ["double" , "int" , "list_double" , "list_int" , "list_string" , "string" ] == attributes
350+
351+
352+ @pytest .mark .skipif (
353+ not conftest .SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0 , reason = "Available for servers >=7.0"
354+ )
355+ def test_list_attributes_recursive_data_tree (server_type ):
356+ data_tree = dpf .DataTree (server = server_type )
357+ with data_tree .to_fill () as to_fill :
358+ to_fill .attribute01 = 1
359+ sub_tree01 = dpf .DataTree (server = server_type )
360+ with sub_tree01 .to_fill () as to_fill01 :
361+ to_fill01 .attribute02 = 2
362+ to_fill .sub_tree01 = sub_tree01
363+ sub_tree02 = dpf .DataTree (server = server_type )
364+ to_fill .sub_tree02 = sub_tree02
365+
366+ attributes = data_tree .get_attribute_names ()
367+ sub_trees = data_tree .get_sub_tree_names ()
368+
369+ assert attributes == ["attribute01" ]
370+ assert sub_trees == ["sub_tree01" , "sub_tree02" ]
371+
372+ dic = data_tree .to_dict ()
373+
374+ assert ["attribute01" , "sub_tree01" , "sub_tree02" ] == list (dic .keys ())
375+ assert {"attribute02" : "2" } == dic ["sub_tree01" ]
376+ assert {} == dic ["sub_tree02" ]
0 commit comments