summary refs log blame commit diff stats
path: root/test/tc_ui.py
blob: eb503c5da982c5b32ab56c963c7096698c1ddd65 (plain) (tree)


















                                                            
                                                         






                                         






















                                                                         
if __name__ == '__main__': from __init__ import init; init()

import unittest
import curses

from ranger.gui import ui

from test import Fake, OK, raise_ok

ui.curses = Fake()

class Test(unittest.TestCase):
	def setUp(self):

		self.fm = Fake()
		self.ui = ui.UI(env=Fake(), fm=self.fm)

		def fakesetup():
			self.ui.widget = Fake()
			self.ui.add_child(self.ui.widget)
		self.ui.setup = fakesetup

		self.ui.initialize()

	def tearDown(self):
		self.ui.destroy()
	
	def test_passing(self):
		# Test whether certain method calls are passed to widgets
		widget = self.ui.widget

		widget.draw = raise_ok
		self.assertRaises(OK, self.ui.draw)
		widget.__clear__()

		widget.finalize = raise_ok
		self.assertRaises(OK, self.ui.finalize)
		widget.__clear__()

		widget.press = raise_ok
		random_key = 123
		self.assertRaises(OK, self.ui.handle_key, random_key)
		widget.__clear__()

		widget.destroy = raise_ok
		self.assertRaises(OK, self.ui.destroy)
		widget.__clear__()

if __name__ == '__main__':
	unittest.main()
) // Used to transmit database pointer var dbChan = make(chan dbase, 1) // Used to transmit the wrapped tickers // corresponding to the in-memory cache // or the on-disk database. var dbTickC = make(chan *tick, 1) var cTickC = make(chan *tick, 1) // Used to manage the landing page template var tmpls *template.Template // Holds the registry data in-memory var twtxtCache = registry.NewIndex() // List of other registries submitted to this registry var remoteRegistries = &RemoteRegistries{ Mu: sync.RWMutex{}, List: make([]string, 0), } // In-memory cache of static assets, specifically // the parsed landing page and the stylesheet. var staticCache = &staticAssets{} func errFatal(context string, err error) { if err != nil { log.Fatalf(context+"%v\n", err.Error()) } } func errLog(context string, err error) { if err != nil { log.Printf(context+"%v\n", err.Error()) } } // I'm not using init() because it runs // even during testing and was causing // problems. func initSvc() { checkFlags() titleScreen() initConfig() initLogging() initDatabase() tmpls = initTemplates() initPersistence() pingAssets() watchForInterrupt() } func checkFlags() { pflag.Parse() if *flagVersion { titleScreen() os.Exit(0) } if *flagHelp { titleScreen() helpScreen() os.Exit(0) } if *flagMan { titleScreen() helpScreen() manualScreen() os.Exit(0) } } // Watch for SIGINT aka ^C // Close the log file then exit func watchForInterrupt() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { for sigint := range c { log.Printf("Caught %v. Cleaning up ...\n", sigint) confObj.Mu.RLock() log.Printf("Closing database connection to %v...\n", confObj.DBPath) killTickers() killDB() if !confObj.StdoutLogging { closeLog <- true } confObj.Mu.RUnlock() close(dbChan) close(closeLog) // Let everything catch up time.Sleep(100 * time.Millisecond) os.Exit(0) } }() }