summary refs log tree commit diff stats
path: root/test/tc_directory.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-24 16:50:20 +0100
committerhut <hut@lavabit.com>2009-11-24 16:50:20 +0100
commitf6f26231a1a2c886f43d9ec965eb7903180067fb (patch)
tree2340d5a6b5dfb97e447b90ab9e1f45a8d4bdffba /test/tc_directory.py
parent798d06a2317a5bb4ee38cec4d1d4f5d428d75593 (diff)
downloadranger-f6f26231a1a2c886f43d9ec965eb7903180067fb.tar.gz
corrected test, added some stuff
Diffstat (limited to 'test/tc_directory.py')
-rw-r--r--test/tc_directory.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/test/tc_directory.py b/test/tc_directory.py
index f97f9913..ebbd6b5e 100644
--- a/test/tc_directory.py
+++ b/test/tc_directory.py
@@ -1,6 +1,7 @@
 import unittest
-import sys, os
+import sys, os, time
 sys.path.append('../code')
+os.stat_float_times(True)
 import directory, fsobject, file, debug
 
 TESTDIR = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), 'testdir'))
@@ -78,15 +79,33 @@ class Test1(unittest.TestCase):
 		self.assertRaises(fsobject.FrozenException, clone.load_content)
 
 	def test_load_if_outdated(self):
-		if os.path.exists(TESTFILE): os.unlink(TESTFILE)
+		# modify the directory. If the time between the last modification
+		# was within the filesystems resolution of mtime, we should have a re-load.
+
+		def modify_dir():
+			open(TESTFILE, 'w').close()
+			os.unlink(TESTFILE)
+
+		def mtime():
+			return os.stat(TESTDIR).st_mtime
+
 		dir = directory.Directory(TESTDIR)
 		dir.load()
 
-		open(TESTFILE, 'w').close()
+		# 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())
 
-		os.unlink(TESTFILE)
-
 unittest.main()
 
a> 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299