hydrus/test.py

142 lines
4.9 KiB
Python
Raw Normal View History

2013-09-11 21:28:19 +00:00
from include import ClientConstants as CC
2013-07-10 20:25:57 +00:00
from include import HydrusConstants as HC
2013-10-23 21:36:47 +00:00
from include import HydrusSessions
2013-07-24 20:26:00 +00:00
from include import HydrusTags
2013-08-07 22:25:18 +00:00
from include import TestClientConstants
2013-07-31 21:26:38 +00:00
from include import TestClientDaemons
2013-07-10 20:25:57 +00:00
from include import TestConstants
2013-07-24 20:26:00 +00:00
from include import TestDialogs
2013-07-10 20:25:57 +00:00
from include import TestDB
from include import TestFunctions
2013-07-31 21:26:38 +00:00
from include import TestHydrusDownloading
2013-11-13 21:30:38 +00:00
from include import TestHydrusEncryption
2013-11-20 21:12:21 +00:00
from include import TestHydrusServer
2013-11-06 18:22:07 +00:00
from include import TestHydrusSessions
2013-07-17 20:56:13 +00:00
from include import TestHydrusTags
2013-07-31 21:26:38 +00:00
import collections
2013-07-24 20:26:00 +00:00
import os
2013-11-06 18:22:07 +00:00
import sys
2013-07-10 20:25:57 +00:00
import unittest
2013-07-24 20:26:00 +00:00
import wx
2013-07-10 20:25:57 +00:00
2013-11-06 18:22:07 +00:00
only_run = None
2013-07-24 20:26:00 +00:00
class App( wx.App ):
def OnInit( self ):
HC.app = self
self._reads = {}
2013-09-11 21:28:19 +00:00
self._reads[ 'options' ] = CC.CLIENT_DEFAULT_OPTIONS
2013-10-09 18:13:42 +00:00
self._reads[ 'namespace_blacklists' ] = []
2013-07-24 20:26:00 +00:00
self._reads[ 'tag_parents' ] = {}
self._reads[ 'tag_service_precedence' ] = []
self._reads[ 'tag_siblings' ] = {}
2013-10-23 21:36:47 +00:00
self._reads[ 'hydrus_sessions' ] = []
self._reads[ 'sessions' ] = []
2013-07-24 20:26:00 +00:00
2013-09-11 21:28:19 +00:00
HC.options = CC.CLIENT_DEFAULT_OPTIONS
2013-07-31 21:26:38 +00:00
self._writes = collections.defaultdict( list )
2013-10-09 18:13:42 +00:00
self._namespace_blacklists_manager = HydrusTags.NamespaceBlacklistsManager()
2013-07-24 20:26:00 +00:00
self._tag_parents_manager = HydrusTags.TagParentsManager()
self._tag_siblings_manager = HydrusTags.TagSiblingsManager()
2013-10-23 21:36:47 +00:00
self._client_session_manager = HydrusSessions.HydrusSessionManagerClient()
self._server_session_manager = HydrusSessions.HydrusSessionManagerServer()
2013-09-04 16:48:44 +00:00
self._cookies = {}
2013-07-24 20:26:00 +00:00
suites = []
2013-11-06 18:22:07 +00:00
if only_run is None: run_all = True
else: run_all = False
if run_all or only_run == 'cc': suites.append( unittest.TestLoader().loadTestsFromModule( TestClientConstants ) )
if run_all or only_run == 'daemons': suites.append( unittest.TestLoader().loadTestsFromModule( TestClientDaemons ) )
if run_all or only_run == 'dialogs': suites.append( unittest.TestLoader().loadTestsFromModule( TestDialogs ) )
if run_all or only_run == 'db': suites.append( unittest.TestLoader().loadTestsFromModule( TestDB ) )
2013-11-13 21:30:38 +00:00
if run_all or only_run == 'encryption': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusEncryption ) )
2013-11-06 18:22:07 +00:00
if run_all or only_run == 'functions': suites.append( unittest.TestLoader().loadTestsFromModule( TestFunctions ) )
if run_all or only_run == 'downloading': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusDownloading ) )
2013-11-20 21:12:21 +00:00
if run_all or only_run == 'server': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusServer ) )
2013-11-06 18:22:07 +00:00
if run_all or only_run == 'sessions': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusSessions ) )
if run_all or only_run == 'tags': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusTags ) )
2013-07-24 20:26:00 +00:00
suite = unittest.TestSuite( suites )
runner = unittest.TextTestRunner( verbosity = 1 )
runner.run( suite )
return True
2013-07-10 20:25:57 +00:00
2013-10-09 18:13:42 +00:00
def GetNamespaceBlacklistsManager( self ): return self._namespace_blacklists_manager
2013-10-23 21:36:47 +00:00
def GetSessionKey( self, service_identifier ): return self._client_session_manager.GetSessionKey( service_identifier )
2013-11-06 18:22:07 +00:00
def GetSessionManager( self ): return self._server_session_manager
2013-07-24 20:26:00 +00:00
def GetTagParentsManager( self ): return self._tag_parents_manager
def GetTagSiblingsManager( self ): return self._tag_siblings_manager
2013-07-10 20:25:57 +00:00
2013-09-04 16:48:44 +00:00
def GetWebCookies( self, name ): return self._cookies[ name ]
2013-07-31 21:26:38 +00:00
def GetWrite( self, name ):
write = self._writes[ name ]
del self._writes[ name ]
return write
2013-10-23 21:36:47 +00:00
def Read( self, name, *args, **kwargs ): return self._reads[ name ]
2013-07-10 20:25:57 +00:00
2013-10-23 21:36:47 +00:00
def ReadDaemon( self, name, *args, **kwargs ): return self.Read( name )
2013-07-31 21:26:38 +00:00
2013-07-24 20:26:00 +00:00
def SetRead( self, name, value ): self._reads[ name ] = value
2013-07-10 20:25:57 +00:00
2013-09-04 16:48:44 +00:00
def SetWebCookies( self, name, value ): self._cookies[ name ] = value
2013-07-31 21:26:38 +00:00
def Write( self, name, *args, **kwargs ):
self._writes[ name ].append( ( args, kwargs ) )
2013-08-14 20:21:49 +00:00
def WriteSynchronous( self, name, *args, **kwargs ):
2013-07-31 21:26:38 +00:00
self._writes[ name ].append( ( args, kwargs ) )
if name == 'import_file':
2013-08-07 22:25:18 +00:00
( path, ) = args
with open( path, 'rb' ) as f: file = f.read()
if file == 'blarg': raise Exception( 'File failed to import for some reason!' )
2013-07-31 21:26:38 +00:00
else: return ( 'successful', 'hash' )
2013-07-24 20:26:00 +00:00
if __name__ == '__main__':
2013-07-10 20:25:57 +00:00
2013-11-06 18:22:07 +00:00
args = sys.argv[1:]
if len( args ) > 0:
only_run = args[0]
else: only_run = None
2013-07-24 20:26:00 +00:00
app = App()
2013-07-10 20:25:57 +00:00
raw_input()
2013-08-28 21:31:52 +00:00
HC.shutdown = True
2013-11-13 21:30:38 +00:00
HC.pubsub.WXpubimmediate( 'shutdown' )