<s> from __future__ import absolute_import <EOL> from traits . testing . unittest_tools import unittest <EOL> from . . confirmation_dialog import ConfirmationDialog , confirm <EOL> from . . constant import YES , NO , OK , CANCEL <EOL> from . . gui import GUI <EOL> from . . image_resource import ImageResource <EOL> from . . toolkit import toolkit_object <EOL> from . . window import Window <EOL> ModalDialogTester = toolkit_object ( '<STR_LIT>' ) <EOL> no_modal_dialog_tester = ( ModalDialogTester . __name__ == '<STR_LIT>' ) <EOL> class TestConfirmationDialog ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . gui = GUI ( ) <EOL> self . dialog = ConfirmationDialog ( ) <EOL> def test_create ( self ) : <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_destroy ( self ) : <EOL> self . dialog . destroy ( ) <EOL> def test_create_parent ( self ) : <EOL> parent = Window ( ) <EOL> self . dialog . parent = parent . control <EOL> parent . _create ( ) <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> parent . destroy ( ) <EOL> def test_create_yes_renamed ( self ) : <EOL> self . dialog . yes_label = u"<STR_LIT>" <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_no_renamed ( self ) : <EOL> self . dialog . no_label = u"<STR_LIT>" <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_yes_default ( self ) : <EOL> self . dialog . default = YES <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_cancel ( self ) : <EOL> self . dialog . cancel = True <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_cancel_renamed ( self ) : <EOL> self . dialog . cancel = True <EOL> self . dialog . cancel_label = "<STR_LIT>" <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_cancel_default ( self ) : <EOL> self . dialog . cancel = True <EOL> self . dialog . default = CANCEL <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> def test_create_image ( self ) : <EOL> self . dialog . image = ImageResource ( '<STR_LIT>' ) <EOL> self . dialog . _create ( ) <EOL> self . gui . process_events ( ) <EOL> self . dialog . destroy ( ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_close ( self ) : <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_run ( when_opened = lambda x : self . dialog . close ( ) ) <EOL> self . assertEqual ( tester . result , NO ) <EOL> self . assertEqual ( self . dialog . return_code , NO ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_close_with_cancel ( self ) : <EOL> self . dialog . cancel = True <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_run ( when_opened = lambda x : self . dialog . close ( ) ) <EOL> self . assertEqual ( tester . result , CANCEL ) <EOL> self . assertEqual ( self . dialog . return_code , CANCEL ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_yes ( self ) : <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( YES ) ) <EOL> self . assertEqual ( tester . result , YES ) <EOL> self . assertEqual ( self . dialog . return_code , YES ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_renamed_yes ( self ) : <EOL> self . dialog . yes_label = u"<STR_LIT>" <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_widget ( u"<STR_LIT>" ) ) <EOL> self . assertEqual ( tester . result , YES ) <EOL> self . assertEqual ( self . dialog . return_code , YES ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_no ( self ) : <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( NO ) ) <EOL> self . assertEqual ( tester . result , NO ) <EOL> self . assertEqual ( self . dialog . return_code , NO ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_renamed_no ( self ) : <EOL> self . dialog . no_label = u"<STR_LIT>" <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_widget ( u"<STR_LIT>" ) ) <EOL> self . assertEqual ( tester . result , NO ) <EOL> self . assertEqual ( self . dialog . return_code , NO ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_cancel ( self ) : <EOL> self . dialog . cancel = True <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( CANCEL ) ) <EOL> self . assertEqual ( tester . result , CANCEL ) <EOL> self . assertEqual ( self . dialog . return_code , CANCEL ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_cancel_renamed ( self ) : <EOL> self . dialog . cancel = True <EOL> self . dialog . cancel_label = u"<STR_LIT>" <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_widget ( u"<STR_LIT>" ) ) <EOL> self . assertEqual ( tester . result , CANCEL ) <EOL> self . assertEqual ( self . dialog . return_code , CANCEL ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_parent ( self ) : <EOL> parent = Window ( ) <EOL> self . dialog . parent = parent . control <EOL> parent . open ( ) <EOL> tester = ModalDialogTester ( self . dialog . open ) <EOL> tester . open_and_run ( when_opened = lambda x : x . close ( accept = True ) ) <EOL> parent . close ( ) <EOL> self . assertEqual ( tester . result , OK ) <EOL> self . assertEqual ( self . dialog . return_code , OK ) <EOL> class TestConfirm ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . gui = GUI ( ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_reject ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" , cancel = True ) ) <EOL> tester . open_and_run ( when_opened = lambda x : x . close ( accept = False ) ) <EOL> self . assertEqual ( tester . result , CANCEL ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_yes ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" ) ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( YES ) ) <EOL> self . gui . process_events ( ) <EOL> self . assertEqual ( tester . result , YES ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_no ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" ) ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( NO ) ) <EOL> self . gui . process_events ( ) <EOL> self . assertEqual ( tester . result , NO ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_cancel ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" , cancel = True ) ) <EOL> tester . open_and_wait ( when_opened = lambda x : x . click_button ( CANCEL ) ) <EOL> self . gui . process_events ( ) <EOL> self . assertEqual ( tester . result , CANCEL ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_title ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" , <EOL> title = '<STR_LIT>' ) ) <EOL> tester . open_and_run ( when_opened = lambda x : x . click_button ( NO ) ) <EOL> self . assertEqual ( tester . result , NO ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_default_yes ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" , default = YES ) ) <EOL> tester . open_and_run ( when_opened = lambda x : x . click_button ( YES ) ) <EOL> self . assertEqual ( tester . result , YES ) <EOL> @ unittest . skipIf ( no_modal_dialog_tester , '<STR_LIT>' ) <EOL> def test_default_cancel ( self ) : <EOL> tester = ModalDialogTester ( lambda : confirm ( None , "<STR_LIT:message>" , <EOL> cancel = True , default = YES ) ) <EOL> tester . open_and_run ( when_opened = lambda x : x . click_button ( CANCEL ) ) <EOL> self . assertEqual ( tester . result , CANCEL ) </s>
