hydrus/test.py

182 lines
6.4 KiB
Python
Raw Normal View History

2014-07-30 21:18:17 +00:00
import locale
try: locale.setlocale( locale.LC_ALL, '' )
except: pass
2013-07-10 20:25:57 +00:00
from include import HydrusConstants as HC
2014-04-23 20:56:12 +00:00
from include import ClientConstants as CC
2014-02-12 23:09:38 +00:00
from include import HydrusNetworking
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
2014-05-07 22:42:30 +00:00
from include import TestHydrusImageHandling
2014-04-16 20:31:59 +00:00
from include import TestHydrusNATPunch
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-11-27 18:27:11 +00:00
import threading
2014-04-16 20:31:59 +00:00
import time
2013-07-10 20:25:57 +00:00
import unittest
2013-07-24 20:26:00 +00:00
import wx
2013-11-27 18:27:11 +00:00
from twisted.internet import reactor
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
2014-02-12 23:09:38 +00:00
HC.http = HydrusNetworking.HTTPConnectionManager()
2014-03-26 21:23:10 +00:00
def show_text( text ): pass
HC.ShowText = show_text
2013-07-24 20:26:00 +00:00
self._reads = {}
2013-11-27 18:27:11 +00:00
self._reads[ 'hydrus_sessions' ] = []
2014-07-16 20:50:18 +00:00
self._reads[ 'local_booru_share_keys' ] = []
2013-11-27 18:27:11 +00:00
self._reads[ 'messaging_sessions' ] = []
2014-03-12 22:08:23 +00:00
self._reads[ 'tag_censorship' ] = []
2013-11-27 18:27:11 +00:00
self._reads[ 'options' ] = CC.CLIENT_DEFAULT_OPTIONS
self._reads[ 'sessions' ] = []
2013-07-24 20:26:00 +00:00
self._reads[ 'tag_parents' ] = {}
self._reads[ 'tag_service_precedence' ] = []
self._reads[ 'tag_siblings' ] = {}
2013-11-27 18:27:11 +00:00
self._reads[ 'web_sessions' ] = {}
2013-07-24 20:26:00 +00:00
2013-09-11 21:28:19 +00:00
HC.options = CC.CLIENT_DEFAULT_OPTIONS
2013-12-11 22:09:25 +00:00
HC.pubsub = TestConstants.FakePubSub()
2013-09-11 21:28:19 +00:00
2013-07-31 21:26:38 +00:00
self._writes = collections.defaultdict( list )
2013-11-27 18:27:11 +00:00
self._managers = {}
2013-07-24 20:26:00 +00:00
2013-11-27 18:27:11 +00:00
self._managers[ 'hydrus_sessions' ] = HydrusSessions.HydrusSessionManagerClient()
2014-03-12 22:08:23 +00:00
self._managers[ 'tag_censorship' ] = HydrusTags.TagCensorshipManager()
2013-11-27 18:27:11 +00:00
self._managers[ 'tag_siblings' ] = HydrusTags.TagSiblingsManager()
2013-12-11 22:09:25 +00:00
self._managers[ 'tag_parents' ] = HydrusTags.TagParentsManager()
2013-11-27 18:27:11 +00:00
self._managers[ 'undo' ] = CC.UndoManager()
2013-12-04 22:44:16 +00:00
self._managers[ 'web_sessions' ] = TestConstants.FakeWebSessionManager()
2013-11-27 18:27:11 +00:00
self._managers[ 'restricted_services_sessions' ] = HydrusSessions.HydrusSessionManagerServer()
self._managers[ 'messaging_sessions' ] = HydrusSessions.HydrusMessagingSessionManagerServer()
2013-10-23 21:36:47 +00:00
2014-07-16 20:50:18 +00:00
info = {}
info[ 'max_monthly_data' ] = None
info[ 'used_monthly_data' ] = 0
2014-08-06 20:29:17 +00:00
service_key = HC.LOCAL_BOORU_SERVICE_IDENTIFIER.GetServiceKey()
service_type = HC.LOCAL_BOORU_SERVICE_IDENTIFIER.GetType()
name = HC.LOCAL_BOORU_SERVICE_IDENTIFIER.GetName()
service = CC.Service( service_key, service_type, name, info )
2014-07-16 20:50:18 +00:00
HC.app.SetRead( 'service', service )
self._managers[ 'local_booru' ] = CC.LocalBooruCache()
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 ) )
2014-05-07 22:42:30 +00:00
if run_all or only_run == 'downloading': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusDownloading ) )
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 ) )
2014-05-07 22:42:30 +00:00
if run_all or only_run == 'image': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusImageHandling ) )
2014-04-16 20:31:59 +00:00
if run_all or only_run == 'nat': suites.append( unittest.TestLoader().loadTestsFromModule( TestHydrusNATPunch ) )
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 )
2014-04-16 20:31:59 +00:00
threading.Thread( target = reactor.run, kwargs = { 'installSignalHandlers' : 0 } ).start()
2013-11-27 18:27:11 +00:00
2013-07-24 20:26:00 +00:00
runner = unittest.TextTestRunner( verbosity = 1 )
runner.run( suite )
2014-04-16 20:31:59 +00:00
reactor.callFromThread( reactor.stop )
2013-11-27 18:27:11 +00:00
2013-07-24 20:26:00 +00:00
return True
2013-07-10 20:25:57 +00:00
2013-11-27 18:27:11 +00:00
def GetManager( self, type ): return self._managers[ type ]
2013-07-10 20:25:57 +00:00
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
2014-06-18 21:53:48 +00:00
old_pubsub = HC.pubsub
2013-07-24 20:26:00 +00:00
app = App()
2013-07-10 20:25:57 +00:00
2013-08-28 21:31:52 +00:00
HC.shutdown = True
2013-11-13 21:30:38 +00:00
HC.pubsub.WXpubimmediate( 'shutdown' )
2014-05-21 21:37:35 +00:00
2014-06-18 21:53:48 +00:00
old_pubsub.WXpubimmediate( 'shutdown' )
raw_input()