44from aiida .orm import ArrayData
55from ipywidgets import HTML , Dropdown
66
7- from alc_aiidalab_widgets .widgets .tables import XYZArrayDataTableWidget
7+ from alc_aiidalab_widgets .widgets .tables import (
8+ GenericArrayDataTableWidget ,
9+ XYZArrayDataTableWidget ,
10+ )
811
912
1013def test_xyz_arraydata_table ():
@@ -26,3 +29,37 @@ def test_xyz_arraydata_table():
2629 assert "4263.123456" in widget .children [1 ].value
2730 assert widget .children [0 ].value == "Array_2"
2831 assert "1.000000" in widget .children [1 ].value
32+
33+
34+ def test_generic_arraydata_table ():
35+ """Test the basic arraydata table viewer."""
36+ array = ArrayData ()
37+ array1 = numpy .array ([0 , 1 , 2 , 32 , 4 , 5 ], dtype = float )
38+ array2 = numpy .array ([0 , 1 , 2 , 32 , 4 , 5 ], dtype = int )
39+ array3 = numpy .array ([[0 , 1 , 2 ], [32 , 4 , 5 ]], dtype = int )
40+ array4 = numpy .zeros ((2 , 2 , 2 ), dtype = float )
41+ array .set_array ("Array_1" , array1 )
42+ array .set_array ("Array_2" , array2 )
43+ array .set_array ("Array_3" , array3 )
44+ array .set_array ("Array_4" , array4 )
45+ widget = GenericArrayDataTableWidget (array )
46+ assert isinstance (widget .children [0 ], Dropdown )
47+ assert isinstance (widget .children [1 ], HTML )
48+ assert "32.00000" in widget .children [1 ].value
49+ assert "0.000000" in widget .children [1 ].value
50+ assert widget .children [0 ].value == "Array_1"
51+
52+ widget .array_selector .index = 1
53+ assert "32" in widget .children [1 ].value
54+ assert widget .children [0 ].value == "Array_2"
55+ assert "1" in widget .children [1 ].value
56+ assert "Array 2" in widget .children [1 ].value
57+
58+ widget .array_selector .index = 2
59+ assert widget .children [0 ].value == "Array_3"
60+ assert "32" in widget .children [1 ].value
61+ assert "1" in widget .children [1 ].value
62+ assert "Array_3" not in widget .children [1 ].value
63+
64+ widget .array_selector .index = 3
65+ assert "To many dimensions" in widget .children [1 ].value
0 commit comments