summary refs log tree commit diff stats
path: root/test/tc_directory.py
diff options
context:
space:
mode:
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()
 
03 +0000 committer James Booth <boothj5@gmail.com> 2015-11-19 00:45:03 +0000 Changed roster defaults, updated themes' href='/danisanti/profani-tty/commit/themes/complex?id=4eb0f14a3de378571b3fb644f230f60b892af29c'>4eb0f14a ^
30b5f112 ^
8413020a ^
216493ef ^









5bccee93 ^
abc2f0de ^
cf80fdc3 ^
97d96746 ^
e58be44f ^
519b10d1 ^
f91b21a1 ^
2bda22c3 ^
a00095c8 ^
2bda22c3 ^
a00095c8 ^
27adf031 ^

30b5f112 ^


446027b9 ^
93358d5e ^
fb7001cf ^
72c1c496 ^
bab75cae ^
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