<s> """<STR_LIT>""" <EOL> try : <EOL> from twisted . internet import gireactor , gtk3reactor <EOL> from gi . repository import Gtk , Gio <EOL> except ImportError : <EOL> gireactor = None <EOL> from twisted . internet . error import ReactorAlreadyRunning <EOL> from twisted . trial . unittest import TestCase , SkipTest <EOL> from twisted . internet . test . reactormixins import ReactorBuilder <EOL> class GtkApplicationRegistration ( ReactorBuilder , TestCase ) : <EOL> """<STR_LIT>""" <EOL> if gireactor is None : <EOL> skip = "<STR_LIT>" <EOL> def runReactor ( self , app , reactor ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( app , "<STR_LIT>" ) : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> result = [ ] <EOL> def stop ( ) : <EOL> result . append ( "<STR_LIT>" ) <EOL> reactor . stop ( ) <EOL> def activate ( widget ) : <EOL> result . append ( "<STR_LIT>" ) <EOL> reactor . callLater ( <NUM_LIT:0> , stop ) <EOL> app . connect ( '<STR_LIT>' , activate ) <EOL> app . hold ( ) <EOL> reactor . registerGApplication ( app ) <EOL> ReactorBuilder . runReactor ( self , reactor ) <EOL> self . assertEqual ( result , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_gApplicationActivate ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gireactor . GIReactor ( useGtk = False ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = Gio . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> self . runReactor ( app , reactor ) <EOL> def test_gtkApplicationActivate ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gtk3reactor . Gtk3Reactor ( ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = Gtk . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> self . runReactor ( app , reactor ) <EOL> def test_portable ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gireactor . PortableGIReactor ( ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = Gio . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> self . assertRaises ( NotImplementedError , <EOL> reactor . registerGApplication , app ) <EOL> def test_noQuit ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gireactor . GIReactor ( useGtk = False ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = object ( ) <EOL> exc = self . assertRaises ( RuntimeError , reactor . registerGApplication , app ) <EOL> self . assertTrue ( exc . args [ <NUM_LIT:0> ] . startswith ( <EOL> "<STR_LIT>" ) ) <EOL> def test_cantRegisterAfterRun ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gireactor . GIReactor ( useGtk = False ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = Gio . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> def tryRegister ( ) : <EOL> exc = self . assertRaises ( ReactorAlreadyRunning , <EOL> reactor . registerGApplication , app ) <EOL> self . assertEqual ( exc . args [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) <EOL> reactor . stop ( ) <EOL> reactor . callLater ( <NUM_LIT:0> , tryRegister ) <EOL> ReactorBuilder . runReactor ( self , reactor ) <EOL> def test_cantRegisterTwice ( self ) : <EOL> """<STR_LIT>""" <EOL> reactor = gireactor . GIReactor ( useGtk = False ) <EOL> self . addCleanup ( self . unbuildReactor , reactor ) <EOL> app = Gio . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> reactor . registerGApplication ( app ) <EOL> app2 = Gio . Application ( <EOL> application_id = '<STR_LIT>' , <EOL> flags = Gio . ApplicationFlags . FLAGS_NONE ) <EOL> exc = self . assertRaises ( RuntimeError , <EOL> reactor . registerGApplication , app2 ) <EOL> self . assertEqual ( exc . args [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) </s>
