summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
* fsobject.directory: use BAD_INFOhut2011-10-101-1/+2
* container.__init__: removed import shortcutshut2011-10-103-4/+2
* removed completely retarded colorscheme "texas"hut2011-10-102-73/+2
* core.fm: removed old codehut2011-10-101-6/+0
* core.actions: Fixed %t tag in --clean modehut2011-10-101-1/+1
* core.helper: Cleaned up load_settingshut2011-10-102-33/+16
* fixed some documentationhut2011-10-104-9/+12
* api.commands: finished merging ext.command_parser into apihut2011-10-104-175/+73
* core.actions: Don't shell-escape macros for non-shell commandshut2011-10-104-51/+52
* core.actions: shortened long linehut2011-10-101-1/+2
* core.actions: renamed Actions.source_cmdlist to Actions.sourcehut2011-10-102-4/+4
* README: "file" really is optionalhut2011-10-101-1/+1
* gui.curses_shortcuts: simplificationshut2011-10-102-35/+7
* fsobject.fsobject: Added fsobject._mark back inhut2011-10-102-5/+9
* widgets.browsercolumn: Removed redundant try/except blockhut2011-10-101-9/+4
* core.actions: Removed fm.search_forward attribute (not used)hut2011-10-101-6/+0
* fsobject.directory: revert change to accept_filehut2011-10-101-2/+2
* Eliminate orphaned functions and argumentsArisu2011-10-104-14/+10
* Repair some unintended variable referencesArisu2011-10-102-4/+1
* Eliminate orphaned and redundant definitions of variables and importsArisu2011-10-1016-42/+13
* fsobject.directory: Update dir size when content changeshut2011-10-091-1/+4
* widgets.console: Improved command historyhut2011-10-092-10/+19
* Removed example files for nowhut2011-10-094-383/+0
* Revert "core.main: Automatically copy config files"hut2011-10-093-27/+30
* Revert "ranger.1: added doc for --dont-copy-config"hut2011-10-092-7/+9
* defaults.apps: updatedhut2011-10-091-3/+4
* data/apps.py: updatedhut2011-10-091-4/+16
* api.apps: added test whether X runs or not.hut2011-10-092-13/+28
* data/apps.py: Added dochut2011-10-091-0/+3
* widgets.statusbar: Show mtime, like ls -l, not ctimehut2011-10-091-1/+1
* core.helper: fixed crashhut2011-10-081-3/+0
* core.helper: finally removed obsolete option --fail-if-runhut2011-10-081-2/+0
* mv ranger/data/config_examples/* ranger/data/hut2011-10-085-4/+4
* gui.ui: Fall back to "linux" terminal when $TERM failshut2011-10-081-1/+6
* ranger.__init__: changed ranger.LOGFILEhut2011-10-081-1/+1
* ranger.__init__, ranger.1: updated rangers descriptionhut2011-10-083-9/+9
* Updated man pagehut2011-10-082-24/+12
* ranger.1: added doc for --dont-copy-confighut2011-10-082-9/+7
* Write "ranger" with a lowercase "r"hut2011-10-087-10/+10
* defaults/options: disable use_preview_script, unicode_ellipsishut2011-10-081-2/+2
* data/config_examples/rc.conf: Fixed bad commandhut2011-10-081-2/+2
* data/config_examples/rc.conf: Added extra hashes in commentshut2011-10-081-9/+9
* data/config_examples/rc.conf: Typohut2011-10-081-1/+1
* data/config_examples/apps.py: Typohut2011-10-081-1/+1
* defaults/apps: fixed entry for fehhut2011-10-081-1/+1
* README: Updated dependencieshut2011-10-081-4/+4
* config_examples: updated dochut2011-10-082-13/+16
* data/config_examples: added documentationhut2011-10-082-7/+82
* defaults/apps: Removed example code, its now in config_examples/hut2011-10-081-28/+0
* defaults/apps: moved file chooser code to Actions.execute_filehut2011-10-082-5/+5
93'>93 94 95 96 97 98 99 100 101 102 103 104 105 106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159














                                                                       





                                                            
                                                                    

                                   
                                            




                                      





                                                                            





                                              
                                   




                                                                          

                                           




                                                                       


















































                                                                               



                                            



                                                                              
 



                                                              
















                                                                             


                                          
                                            
 





                                                              
 


                                                                       
 


                                                
 


                          
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

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

import unittest
import curses
from random import randint

from ranger.gui.displayable import Displayable, DisplayableContainer
from test import Fake, OK, raise_ok

class TestWithFakeCurses(unittest.TestCase):
	def setUp(self):
		self.win = Fake()
		self.fm = Fake()
		self.env = Fake()
		self.settings = Fake()
		self.initdict = {'win': self.win, 'settings': self.settings,
				'fm': self.fm, 'env': self.env}

		self.disp = Displayable(**self.initdict)
		self.disc = DisplayableContainer(**self.initdict)
		self.disc.add_child(self.disp)

		hei, wid = 100, 100
		self.env.termsize = (hei, wid)

	def tearDown(self):
		self.disp.destroy()
		self.disc.destroy()

	def test_colorscheme(self):
		# Using a color method implies change of window attributes
		disp = self.disp

		disp.win.chgat = raise_ok
		disp.win.attrset = raise_ok

		self.assertRaises(OK, disp.color, 'a', 'b')
		self.assertRaises(OK, disp.color_at, 0, 0, 0, 'a', 'b')
		self.assertRaises(OK, disp.color_reset)

	def test_focused_object(self):
		d1 = Displayable(**self.initdict)
		d2 = DisplayableContainer(**self.initdict)
		for obj in (Displayable(**self.initdict) for x in range(5)):
			d2.add_child(obj)
		d3 = DisplayableContainer(**self.initdict)
		for obj in (Displayable(**self.initdict) for x in range(5)):
			d3.add_child(obj)

		for obj in (d1, d2, d3):
			self.disc.add_child(obj)

		d3.container[3].focused = True

		self.assertEqual(self.disc._get_focused_obj(), d3.container[3])

		d3.container[3].focused = False
		d2.container[0].focused = True

		self.assertEqual(self.disc._get_focused_obj(), d2.container[0])

gWin = None

class TestDisplayableWithCurses(unittest.TestCase):
	def setUp(self):
		global gWin
		if not gWin:
			gWin = curses.initscr()
		self.win = gWin
		curses.cbreak()
		curses.noecho()
		curses.start_color()
		curses.use_default_colors()

		self.fm = Fake()
		self.env = Fake()
		self.settings = Fake()
		self.initdict = {'win': self.win, 'settings': self.settings,
				'fm': self.fm, 'env': self.env}
		self.disp = Displayable(**self.initdict)
		self.disc = DisplayableContainer(**self.initdict)
		self.disc.add_child(self.disp)

		self.env.termsize = self.win.getmaxyx()

	def tearDown(self):
		self.disp.destroy()
		curses.nocbreak()
		curses.echo()
		curses.endwin()

	def test_boundaries(self):
		disp = self.disp
		hei, wid = self.env.termsize

		self.assertRaises(ValueError, disp.resize, 0, 0, hei + 1, wid)
		self.assertRaises(ValueError, disp.resize, 0, 0, hei, wid + 1)
		self.assertRaises(ValueError, disp.resize, -1, 0, hei, wid)
		self.assertRaises(ValueError, disp.resize, 0, -1, hei, wid)

		box = [int(randint(0, hei) * 0.2), 0,
				int(randint(0, wid) * 0.2), 0]
		box[1] = randint(box[0], hei)
		box[1] = randint(box[0], hei)

		def in_box(y, x):
			return (x >= box[1] and x < box[1] + box[3]) and \
					(y >= box[0] and y < box[0] + box[2])

		disp.resize(*box)
		for y, x in zip(range(10), range(10)):
			is_in_box = in_box(y, x)

			point1 = (y, x)
			self.assertEqual(is_in_box, point1 in disp)

			point2 = Fake()
			point2.x = x
			point2.y = y
			self.assertEqual(is_in_box, point2 in disp)

	def test_click(self):
		self.disp.click = raise_ok

		hei, wid = self.env.termsize

		for i in range(50):
			winwid = randint(2, wid-1)
			winhei = randint(2, hei-1)
			self.disc.resize(0, 0, hei, wid)
			self.disp.resize(0, 0, winhei, winwid)
			fakepos = Fake()

			fakepos.x = winwid - 2
			fakepos.y = winhei - 2
			self.assertRaises(OK, self.disc.click, fakepos)

			fakepos.x = winwid
			fakepos.y = winhei
			self.disc.click(fakepos)


if __name__ == '__main__':
	unittest.main()