1515
1616from plotpy .builder import make
1717from plotpy .tests import get_path
18+ from plotpy .tests .data import gen_image1
1819
1920
20- def test_contrast ():
21- """Test"""
22- # -- Create QApplication
21+ def __create_dialog_with_contrast (item ):
22+ """Create plot dialog with contrast panel
23+
24+ Args:
25+ Item: item to be added to the plot
26+ """
27+ win = make .dialog (
28+ edit = False ,
29+ toolbar = True ,
30+ wintitle = "Contrast test" ,
31+ show_contrast = True ,
32+ type = "image" ,
33+ )
34+ plot = win .get_plot ()
35+ plot .add_item (item )
36+ plot .set_active_item (item )
37+ item .unselect ()
38+ win .resize (600 , 600 )
39+ win .show ()
40+ return win
41+
42+
43+ def test_contrast1 ():
44+ """Contrast test 1"""
2345 with qt_app_context (exec_loop = True ):
24- filename = get_path ("brain.png" )
25- image = make .image (filename = filename , title = "Original" , colormap = "gray" )
26- win = make .dialog (
27- edit = False ,
28- toolbar = True ,
29- wintitle = "Contrast test" ,
30- show_contrast = True ,
31- type = "image" ,
32- )
33- plot = win .manager .get_plot ()
34- plot .add_item (image )
35- win .resize (600 , 600 )
36- win .show ()
46+ item = make .image (filename = get_path ("brain.png" ), colormap = "gray" )
47+ win = __create_dialog_with_contrast (item )
3748 fname = "contrast.png"
3849 try :
39- plot .save_widget (fname )
50+ win . get_plot () .save_widget (fname )
4051 except IOError :
4152 # Skipping this part of the test
4253 # because user has no write permission on current directory
@@ -45,5 +56,22 @@ def test_contrast():
4556 os .unlink (fname )
4657
4758
59+ def test_contrast2 ():
60+ """Contrast test 2
61+
62+ Test if level histogram is really removed when the associated image is removed from
63+ the plot (the validation is not automatic)
64+ """
65+ with qt_app_context (exec_loop = True ):
66+ item1 = make .image (filename = get_path ("brain.png" ), colormap = "gray" )
67+ win = __create_dialog_with_contrast (item1 )
68+ plot = win .get_plot ()
69+ plot .del_item (item1 )
70+ item2 = make .image (gen_image1 ())
71+ plot .add_item (item2 )
72+ plot .set_active_item (item2 )
73+
74+
4875if __name__ == "__main__" :
49- test_contrast ()
76+ # test_contrast1()
77+ test_contrast2 ()
0 commit comments