summary refs log tree commit diff stats
path: root/test/tc_newkeys.py
Commit message (Expand)AuthorAgeFilesLines
* cleanupshut2010-05-051-1/+1
* test: added TODO, skip broken testshut2010-05-031-2/+13
* Fixed unittestshut2010-04-181-1/+2
* moved container.keymap.KeyBuffer into seperate modulehut2010-04-161-0/+1
* keymap: moved simulate_press to where it belongs: tc_newkeyshut2010-04-161-5/+14
* keymap: move translate_keys to ranger.ext.keybinding_parserhut2010-04-161-2/+3
* tc_newkeys: fixed all but one testhut2010-04-091-6/+24
* partially fix tc_newkeyshut2010-04-091-26/+28
* tc_newkey: added 2 failing test cases. Fix it!hut2010-04-081-13/+53
* clean uphut2010-04-081-1/+2
* added KeyManagerhut2010-04-071-1/+38
* tc_newkey: added commenthut2010-04-071-0/+1
* container.keymap: support for Alt keyhut2010-04-071-0/+2
* updated container.keymap + testcase to work with new ext.directionhut2010-04-071-7/+9
* keyparser: test for collisions with directories of a lenght > 1hut2010-03-091-8/+27
* keyparser: added copying info to testcasehut2010-03-091-0/+15
* keyparser: lots of stuffhut2010-03-091-5/+9
* keyparser: renamed KeyMap.add to KeyMap.maphut2010-03-091-45/+45
* keyparser: swapped argument order in KeyMap.add()hut2010-03-091-21/+21
* keyparser: allow passive actions (for hints, show bookmarks)hut2010-03-091-0/+30
* integrating keyparser...hut2010-03-091-0/+12
* keyparser: moved classes from test/ to ranger/hut2010-03-091-415/+17
* keyparser: implemented aliaseshut2010-03-091-11/+87
* keyparser: minor updateshut2010-03-091-2/+8
* keyparse: implemented Tree.mergehut2010-03-091-31/+92
* keyparser: Remove the restriction that a root can't be a leafhut2010-03-091-1/+0
* keyparser: updated test_tree_deep_copyhut2010-03-091-5/+4
* keyparser: added test case for tree emrgehut2010-03-091-0/+36
* keyparser: added tree.copy() for deep copieshut2010-03-091-0/+25
* keyparser: minor changeshut2010-03-091-3/+5
* keyparser: turned KeyMap into a treehut2010-03-091-76/+59
* keyparser: added seperate Tree classhut2010-03-091-0/+53
* keyparser: proper parsing of <xyz> in keybindingshut2010-03-091-51/+118
* keyparser: added test for directions as functions, cleanupshut2010-03-091-27/+66
* keyparser: cleanupshut2010-03-091-7/+4
* keyparser: some additionshut2010-03-091-16/+60
* keyparser: allow arbitrary number/order of directionshut2010-03-091-34/+66
* keyparser: reworkedhut2010-03-091-51/+61
* keyparser: "." matches any characterhut2010-03-091-23/+71
* keyparser: some improvementshut2010-03-091-51/+52
* started new key parserhut2010-03-091-0/+331
y?h=v1.9.3&id=fae694a03ebb52888a747010fcb92fa43b33b4a8'>fae694a0 ^
fe179145 ^

fae694a0 ^




9506fb8e ^
fae694a0 ^
fae694a0 ^
1159f9ec ^



fe179145 ^
5822dff7 ^
9506fb8e ^
fae694a0 ^
fe179145 ^
fae694a0 ^
fe179145 ^

fae694a0 ^

fe179145 ^
fae694a0 ^
9506fb8e ^

f6f26231 ^
4c05e43d ^
f6f26231 ^







9506fb8e ^
fae694a0 ^

f6f26231 ^










4c05e43d ^

fae694a0 ^

fe179145 ^
5822dff7 ^

fe179145 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
                                                            
 

                                           
                           

                                               


                                                
 

                                                      
                                              
 
               
                               
                                         
                                                          
                                        

                                                   

                                                     
                                                 
                                                                  
 
                                            
                         
                                                                                
                                        
                                  

                                           
                                                           
 


                                                                                       

                                                                                    

                                        

                                             




                                                                                 
                                      
                                
                                                 



                                                                                       
 
                                       
                                                
                                  
                
                                                   

                                                

                                                                  
 
                                        

                           
                                                                                 
                                                                                         







                                                        
                                        

                          










                                                                             

                                                                                                      

                                                       
 

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

from os.path import realpath, join, dirname

from ranger import fsobject
from ranger.fsobject.file import File
from ranger.fsobject.directory import Directory
from ranger.shared.settings import SettingsAware

SettingsAware._setup()

TESTDIR = realpath(join(dirname(__file__), 'testdir'))
TESTFILE = join(TESTDIR, 'testfile5234148')
NONEXISTANT_DIR = join(TESTDIR, 'nonexistant')

import unittest
class Test1(unittest.TestCase):
	def test_initial_condition(self):
		# Check for the expected initial condition
		dir = Directory(TESTDIR)

		self.assertEqual(dir.path, TESTDIR)
		self.assertFalse(dir.content_loaded)
		self.assertEqual(dir.filenames, None)
		self.assertEqual(dir.files, None)
		self.assertRaises(fsobject.NotLoadedYet, len, dir)

	def test_after_content_loaded(self):
		import os
		# Check whether the directory has the correct list of filenames.
		dir = Directory(TESTDIR)
		dir.load_content()

		self.assertTrue(dir.exists)
		self.assertEqual(type(dir.filenames), list)

		# Get the filenames you expect it to have and sort both before
		# comparing. I don't expect any order after only loading the filenames.
		assumed_filenames = os.listdir(TESTDIR)
		assumed_filenames = list(map(lambda str: os.path.join(TESTDIR, str),
			assumed_filenames))
		assumed_filenames.sort()
		dir.filenames.sort()

		self.assertTrue(len(dir) > 0)
		self.assertEqual(dir.filenames, assumed_filenames)

		# build a file object for each file in the list assumed_filenames
		# and find exactly one equivalent in dir.files
		for name in assumed_filenames:
			f = File(name)
			f.load()
			for dirfile in dir.files:
				if (f.path == dirfile.path and f.stat == dirfile.stat):
					break
			else:
				self.fail("couldn't find file {0}".format(name))

	def test_nonexistant_dir(self):
		dir = Directory(NONEXISTANT_DIR)
		dir.load_content()
		
		self.assertTrue(dir.content_loaded)
		self.assertFalse(dir.exists)
		self.assertFalse(dir.accessible)
		self.assertEqual(dir.filenames, None)
		self.assertRaises(fsobject.NotLoadedYet, len, dir)

	def test_load_if_outdated(self):
		import os
		import time
		# modify the directory. If the time between the last modification
		# was within the filesystems resolution of mtime, we should have a reload

		def modify_dir():
			open(TESTFILE, 'w').close()
			os.unlink(TESTFILE)

		def mtime():
			return os.stat(TESTDIR).st_mtime

		dir = Directory(TESTDIR)
		dir.load()

		# If the modification happens to be in the same second as the
		# last modification, it will result in mtime having the same
		# integer value. So we wait until the resolution is exceeded
		# and mtime differs.
		old_mtime = mtime()
		for i in range(50):
			modify_dir()
			if old_mtime != mtime(): break
			time.sleep(0.1)
		else:
			# fail after 5 seconds of trying
			self.fail(
					"Cannot perform test: mtime of TESTDIR is not being updated.")

		self.assertTrue(dir.load_if_outdated())

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